e9bbab8e9c9f092c939f6617a20ddb66ad7a78c6
[lhc/web/wiklou.git] / maintenance / sqlite / archives / patch-templatelinks-fix-pk.sql
1 CREATE TABLE /*_*/templatelinks_tmp (
2 -- Key to the page_id of the page containing the link.
3 tl_from int unsigned NOT NULL default 0,
4 -- Namespace for this page
5 tl_from_namespace int NOT NULL default 0,
6
7 -- Key to page_namespace/page_title of the target page.
8 -- The target page may or may not exist, and due to renames
9 -- and deletions may refer to different page records as time
10 -- goes by.
11 tl_namespace int NOT NULL default 0,
12 tl_title varchar(255) binary NOT NULL default '',
13 PRIMARY KEY (tl_from,tl_namespace,tl_title)
14 ) /*$wgDBTableOptions*/;
15
16 INSERT INTO /*_*/templatelinks_tmp (tl_from, tl_from_namespace, tl_namespace, tl_title)
17 SELECT tl_from, tl_from_namespace, tl_namespace, tl_title FROM /*_*/templatelinks;
18
19 DROP TABLE /*_*/templatelinks;
20
21 ALTER TABLE /*_*/templatelinks_tmp RENAME TO /*_*/templatelinks;
22
23 -- Reverse index, for Special:Whatlinkshere
24 CREATE INDEX /*i*/tl_namespace ON /*_*/templatelinks (tl_namespace,tl_title,tl_from);
25
26 -- Index for Special:Whatlinkshere with namespace filter
27 CREATE INDEX /*i*/tl_backlinks_namespace ON /*_*/templatelinks (tl_from_namespace,tl_namespace,tl_title,tl_from);