wiki.techinc.nl/maintenance/sqlite/archives/patch-templatelinks-tl_title-varbinary.sql
Amir Sarabadani aecc67b83d Migrate templatelinks table to abstract schema
In order to migrate MySQL and Sqlite to abstract schema changed the
tl_title data type from varchar binary to varbinary. This wouldn't
affect production.

For migrating Postgres:
 - Dropping foreign key on tl_from
 - Changing data type of tl_namespace from SMALLINT to INT and setting
   its default
 - Setting default of empty string for tl_title
 - Completely rewriting indexes to make it synced with MySQL

Bug: T164898
Bug: T230428
Change-Id: Idbb65d870f58f7146b9c8bd860e6530bef1e0f12
2020-08-22 15:23:03 +02:00

20 lines
684 B
SQL

CREATE TABLE /*_*/templatelinks_tmp (
tl_from INTEGER UNSIGNED DEFAULT 0 NOT NULL,
tl_namespace INTEGER DEFAULT 0 NOT NULL,
tl_title BLOB DEFAULT '' NOT NULL,
tl_from_namespace INTEGER DEFAULT 0 NOT NULL,
PRIMARY KEY(tl_from, tl_namespace, tl_title)
);
INSERT INTO /*_*/templatelinks_tmp
SELECT tl_from, tl_namespace, tl_title, tl_from_namespace
FROM /*_*/templatelinks;
DROP TABLE /*_*/templatelinks;
ALTER TABLE /*_*/templatelinks_tmp RENAME TO /*_*/templatelinks;
CREATE INDEX tl_namespace ON /*_*/templatelinks (tl_namespace, tl_title, tl_from);
CREATE INDEX tl_backlinks_namespace ON /*_*/templatelinks (
tl_from_namespace, tl_namespace,
tl_title, tl_from
);