Migrate iwlinks to abstract schema

In order to migrate MySQL and Sqlite to abstract schema changed the
iwl_title data type from varchar binary to varbinary. This wouldn't
affect production.

For migrating Postgres:
 - Turning the unique index to PK to make it in sync with MySQL

Bug: T164898
Bug: T230428
Change-Id: Iaa625b66c874023b8cf2403917fa2fa120279208
This commit is contained in:
Amir Sarabadani 2020-08-29 19:25:15 +02:00
parent 1770341562
commit cd7a28d30f
12 changed files with 101 additions and 29 deletions

View file

@ -448,6 +448,7 @@ class MysqlUpdater extends DatabaseUpdater {
[ 'modifyField', 'templatelinks', 'tl_title', 'patch-templatelinks-tl_title-varbinary.sql' ],
[ 'modifyField', 'imagelinks', 'il_to', 'patch-imagelinks-il_to-varbinary.sql' ],
[ 'modifyField', 'langlinks', 'll_title', 'patch-langlinks-ll_title-varbinary.sql' ],
[ 'modifyField', 'iwlinks', 'iwl_title', 'patch-iwlinks-iwl_title-varbinary.sql' ],
];
}

View file

@ -740,6 +740,7 @@ class PostgresUpdater extends DatabaseUpdater {
[ 'setDefault', 'langlinks', 'll_title', '' ],
[ 'changeNullableField', 'langlinks', 'll_lang', 'NOT NULL', true ],
[ 'changeNullableField', 'langlinks', 'll_title', 'NOT NULL', true ],
[ 'addIndex', 'iwlinks', 'iwlinks_pkey', 'patch-iwlinks-pk.sql' ],
];
}

View file

@ -304,6 +304,7 @@ class SqliteUpdater extends DatabaseUpdater {
[ 'modifyField', 'templatelinks', 'tl_title', 'patch-templatelinks-tl_title-varbinary.sql' ],
[ 'modifyField', 'imagelinks', 'il_to', 'patch-imagelinks-il_to-varbinary.sql' ],
[ 'modifyField', 'langlinks', 'll_title', 'patch-langlinks-ll_title-varbinary.sql' ],
[ 'modifyField', 'iwlinks', 'iwl_title', 'patch-iwlinks-iwl_title-varbinary.sql' ],
];
}

View file

@ -0,0 +1 @@
ALTER TABLE /*_*/iwlinks MODIFY iwl_title VARBINARY(255) NOT NULL default '';

View file

@ -0,0 +1,8 @@
DROP INDEX iwl_from;
DROP INDEX iwl_prefix_title_from;
DROP INDEX iwl_prefix_from_title;
ALTER TABLE iwlinks
ADD PRIMARY KEY (iwl_from, iwl_prefix, iwl_title);
CREATE INDEX iwl_prefix_title_from ON iwlinks (iwl_prefix, iwl_title, iwl_from);
CREATE INDEX iwl_prefix_from_title ON iwlinks (iwl_prefix, iwl_from, iwl_title);

View file

@ -220,3 +220,15 @@ CREATE TABLE langlinks (
);
CREATE INDEX ll_lang ON langlinks (ll_lang, ll_title);
CREATE TABLE iwlinks (
iwl_from INT DEFAULT 0 NOT NULL,
iwl_prefix TEXT DEFAULT '' NOT NULL,
iwl_title TEXT DEFAULT '' NOT NULL,
PRIMARY KEY(iwl_from, iwl_prefix, iwl_title)
);
CREATE INDEX iwl_prefix_title_from ON iwlinks (iwl_prefix, iwl_title, iwl_from);
CREATE INDEX iwl_prefix_from_title ON iwlinks (iwl_prefix, iwl_from, iwl_title);

View file

@ -619,14 +619,6 @@ ALTER SEQUENCE category_cat_id_seq OWNED BY category.cat_id;
CREATE UNIQUE INDEX category_title ON category(cat_title);
CREATE INDEX category_pages ON category(cat_pages);
CREATE TABLE iwlinks (
iwl_from INTEGER NOT NULL DEFAULT 0,
iwl_prefix TEXT NOT NULL DEFAULT '',
iwl_title TEXT NOT NULL DEFAULT ''
);
CREATE UNIQUE INDEX iwl_from ON iwlinks (iwl_from, iwl_prefix, iwl_title);
CREATE UNIQUE INDEX iwl_prefix_title_from ON iwlinks (iwl_prefix, iwl_title, iwl_from);
CREATE UNIQUE INDEX iwl_prefix_from_title ON iwlinks (iwl_prefix, iwl_from, iwl_title);
CREATE SEQUENCE sites_site_id_seq;
CREATE TABLE sites (

View file

@ -0,0 +1,16 @@
CREATE TABLE /*_*/iwlinks_tmp (
iwl_from INTEGER UNSIGNED DEFAULT 0 NOT NULL,
iwl_prefix BLOB DEFAULT '' NOT NULL,
iwl_title BLOB DEFAULT '' NOT NULL,
PRIMARY KEY(iwl_from, iwl_prefix, iwl_title)
);
INSERT INTO /*_*/iwlinks_tmp
SELECT iwl_from, iwl_prefix, iwl_title
FROM /*_*/iwlinks;
DROP TABLE /*_*/iwlinks;
ALTER TABLE /*_*/iwlinks_tmp RENAME TO /*_*/iwlinks;
CREATE INDEX iwl_prefix_title_from ON /*_*/iwlinks (iwl_prefix, iwl_title, iwl_from);
CREATE INDEX iwl_prefix_from_title ON /*_*/iwlinks (iwl_prefix, iwl_from, iwl_title);

View file

@ -213,3 +213,15 @@ CREATE TABLE /*_*/langlinks (
);
CREATE INDEX ll_lang ON /*_*/langlinks (ll_lang, ll_title);
CREATE TABLE /*_*/iwlinks (
iwl_from INTEGER UNSIGNED DEFAULT 0 NOT NULL,
iwl_prefix BLOB DEFAULT '' NOT NULL,
iwl_title BLOB DEFAULT '' NOT NULL,
PRIMARY KEY(iwl_from, iwl_prefix, iwl_title)
);
CREATE INDEX iwl_prefix_title_from ON /*_*/iwlinks (iwl_prefix, iwl_title, iwl_from);
CREATE INDEX iwl_prefix_from_title ON /*_*/iwlinks (iwl_prefix, iwl_from, iwl_title);

View file

@ -200,3 +200,13 @@ CREATE TABLE /*_*/langlinks (
INDEX ll_lang (ll_lang, ll_title),
PRIMARY KEY(ll_from, ll_lang)
) /*$wgDBTableOptions*/;
CREATE TABLE /*_*/iwlinks (
iwl_from INT UNSIGNED DEFAULT 0 NOT NULL,
iwl_prefix VARBINARY(20) DEFAULT '' NOT NULL,
iwl_title VARBINARY(255) DEFAULT '' NOT NULL,
INDEX iwl_prefix_title_from (iwl_prefix, iwl_title, iwl_from),
INDEX iwl_prefix_from_title (iwl_prefix, iwl_from, iwl_title),
PRIMARY KEY(iwl_from, iwl_prefix, iwl_title)
) /*$wgDBTableOptions*/;

View file

@ -652,5 +652,44 @@
}
],
"pk": [ "ll_from", "ll_lang" ]
},
{
"name": "iwlinks",
"comment": "Track inline interwiki links",
"columns": [
{
"name": "iwl_from",
"comment": "page_id of the referring page",
"type": "integer",
"options": { "notnull": true, "unsigned": true, "default": 0 }
},
{
"name": "iwl_prefix",
"type": "binary",
"comment": "Interwiki prefix code of the target",
"options": { "notnull": true, "length": 20, "default": "" }
},
{
"name": "iwl_title",
"type": "binary",
"comment": "Title of the target, including namespace",
"options": { "notnull": true, "length": 255, "default": "" }
}
],
"indexes": [
{
"name": "iwl_prefix_title_from",
"columns": [ "iwl_prefix", "iwl_title", "iwl_from" ],
"comment": "Index for ApiQueryIWBacklinks",
"unique": false
},
{
"name": "iwl_prefix_from_title",
"columns": [ "iwl_prefix", "iwl_from", "iwl_title" ],
"comment": "Index for ApiQueryIWLinks",
"unique": false
}
],
"pk": [ "iwl_from", "iwl_prefix", "iwl_title" ]
}
]

View file

@ -652,27 +652,6 @@ CREATE INDEX /*i*/el_index_60 ON /*_*/externallinks (el_index_60, el_id);
CREATE INDEX /*i*/el_from_index_60 ON /*_*/externallinks (el_from, el_index_60, el_id);
--
-- Track inline interwiki links
--
CREATE TABLE /*_*/iwlinks (
-- page_id of the referring page
iwl_from int unsigned NOT NULL default 0,
-- Interwiki prefix code of the target
iwl_prefix varbinary(20) NOT NULL default '',
-- Title of the target, including namespace
iwl_title varchar(255) binary NOT NULL default '',
PRIMARY KEY (iwl_from,iwl_prefix,iwl_title)
) /*$wgDBTableOptions*/;
-- Index for ApiQueryIWBacklinks
CREATE INDEX /*i*/iwl_prefix_title_from ON /*_*/iwlinks (iwl_prefix, iwl_title, iwl_from);
-- Index for ApiQueryIWLinks
CREATE INDEX /*i*/iwl_prefix_from_title ON /*_*/iwlinks (iwl_prefix, iwl_from, iwl_title);
--
-- Blocks against user accounts, IP addresses and IP ranges.
--