wiki.techinc.nl/maintenance/sqlite/archives/patch-recentchanges-rc_title-varbinary.sql
Amir Sarabadani 4a6d4baaed Migrate recentchanges table to abstract schema
This table is massive but thankfully we fixed most of its complexities
in previous patches.

For MySQL/Sqlite:
 - Change type of rc_title and rc_source from "varchar binary" to
   "varbinary"
 - Drop default of rc_timestamp
 - Change rc_timestamp from varbinary(14) to binary(14) to standardize
   timestamp datatypes

One index doesn't follow the uniform prefix rule but since it's in a
maintenance script, will fix that in a follow up.

Bug: T230428
Bug: T42626
Change-Id: I13994e02ad3a2293148346ef7be96746578ad854
2021-02-26 13:56:56 +01:00

48 lines
2.4 KiB
SQL

CREATE TABLE recentchanges_tmp (
rc_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
rc_timestamp BLOB NOT NULL, rc_actor BIGINT UNSIGNED NOT NULL,
rc_namespace INTEGER DEFAULT 0 NOT NULL,
rc_title BLOB DEFAULT '' NOT NULL, rc_comment_id BIGINT UNSIGNED NOT NULL,
rc_minor SMALLINT UNSIGNED DEFAULT 0 NOT NULL,
rc_bot SMALLINT UNSIGNED DEFAULT 0 NOT NULL,
rc_new SMALLINT UNSIGNED DEFAULT 0 NOT NULL,
rc_cur_id INTEGER UNSIGNED DEFAULT 0 NOT NULL,
rc_this_oldid INTEGER UNSIGNED DEFAULT 0 NOT NULL,
rc_last_oldid INTEGER UNSIGNED DEFAULT 0 NOT NULL,
rc_type SMALLINT UNSIGNED DEFAULT 0 NOT NULL,
rc_source BLOB DEFAULT '' NOT NULL,
rc_patrolled SMALLINT UNSIGNED DEFAULT 0 NOT NULL,
rc_ip BLOB DEFAULT '' NOT NULL, rc_old_len INTEGER DEFAULT NULL,
rc_new_len INTEGER DEFAULT NULL, rc_deleted SMALLINT UNSIGNED DEFAULT 0 NOT NULL,
rc_logid INTEGER UNSIGNED DEFAULT 0 NOT NULL,
rc_log_type BLOB DEFAULT NULL, rc_log_action BLOB DEFAULT NULL,
rc_params BLOB DEFAULT NULL
);
INSERT INTO /*_*/recentchanges_tmp (
rc_id, rc_timestamp, rc_actor, rc_namespace, rc_title, rc_comment_id, rc_minor, rc_bot, rc_new, rc_cur_id,
rc_this_oldid, rc_last_oldid, rc_type, rc_source, rc_patrolled, rc_ip, rc_old_len, rc_new_len, rc_deleted,
rc_logid, rc_log_type, rc_log_action, rc_params)
SELECT rc_id, rc_timestamp, rc_actor, rc_namespace, rc_title, rc_comment_id, rc_minor, rc_bot, rc_new, rc_cur_id,
rc_this_oldid, rc_last_oldid, rc_type, rc_source, rc_patrolled, rc_ip, rc_old_len, rc_new_len, rc_deleted,
rc_logid, rc_log_type, rc_log_action, rc_params
FROM /*_*/recentchanges;
DROP TABLE /*_*/recentchanges;
ALTER TABLE /*_*/recentchanges_tmp RENAME TO /*_*/recentchanges;
CREATE INDEX rc_timestamp ON /*_*/recentchanges (rc_timestamp);
CREATE INDEX rc_namespace_title_timestamp ON /*_*/recentchanges (
rc_namespace, rc_title, rc_timestamp
);
CREATE INDEX rc_cur_id ON /*_*/recentchanges (rc_cur_id);
CREATE INDEX new_name_timestamp ON /*_*/recentchanges (
rc_new, rc_namespace, rc_timestamp
);
CREATE INDEX rc_ip ON /*_*/recentchanges (rc_ip);
CREATE INDEX rc_ns_actor ON /*_*/recentchanges (rc_namespace, rc_actor);
CREATE INDEX rc_actor ON /*_*/recentchanges (rc_actor, rc_timestamp);
CREATE INDEX rc_name_type_patrolled_timestamp ON /*_*/recentchanges (
rc_namespace, rc_type, rc_patrolled,
rc_timestamp
);
CREATE INDEX rc_this_oldid ON /*_*/recentchanges (rc_this_oldid);