Convert UNIQUE keys into PRIMARY KEY
[lhc/web/wiklou.git] / maintenance / sqlite / archives / patch-categorylinks-fix-pk.sql
1 CREATE TABLE /*_*/categorylinks_tmp (
2 -- Key to page_id of the page defined as a category member.
3 cl_from int unsigned NOT NULL default 0,
4
5 -- Name of the category.
6 -- This is also the page_title of the category's description page;
7 -- all such pages are in namespace 14 (NS_CATEGORY).
8 cl_to varchar(255) binary NOT NULL default '',
9
10 -- A binary string obtained by applying a sortkey generation algorithm
11 -- (Collation::getSortKey()) to page_title, or cl_sortkey_prefix . "\n"
12 -- . page_title if cl_sortkey_prefix is nonempty.
13 cl_sortkey varbinary(230) NOT NULL default '',
14
15 -- A prefix for the raw sortkey manually specified by the user, either via
16 -- [[Category:Foo|prefix]] or {{defaultsort:prefix}}. If nonempty, it's
17 -- concatenated with a line break followed by the page title before the sortkey
18 -- conversion algorithm is run. We store this so that we can update
19 -- collations without reparsing all pages.
20 -- Note: If you change the length of this field, you also need to change
21 -- code in LinksUpdate.php. See T27254.
22 cl_sortkey_prefix varchar(255) binary NOT NULL default '',
23
24 -- This isn't really used at present. Provided for an optional
25 -- sorting method by approximate addition time.
26 cl_timestamp timestamp NOT NULL,
27
28 -- Stores $wgCategoryCollation at the time cl_sortkey was generated. This
29 -- can be used to install new collation versions, tracking which rows are not
30 -- yet updated. '' means no collation, this is a legacy row that needs to be
31 -- updated by updateCollation.php. In the future, it might be possible to
32 -- specify different collations per category.
33 cl_collation varbinary(32) NOT NULL default '',
34
35 -- Stores whether cl_from is a category, file, or other page, so we can
36 -- paginate the three categories separately. This never has to be updated
37 -- after the page is created, since none of these page types can be moved to
38 -- any other.
39 cl_type ENUM('page', 'subcat', 'file') NOT NULL default 'page',
40 PRIMARY KEY (cl_from,cl_to)
41 ) /*$wgDBTableOptions*/;
42
43 INSERT INTO /*_*/categorylinks_tmp
44 SELECT *
45 FROM /*_*/categorylinks;
46
47 DROP TABLE /*_*/categorylinks;
48
49 ALTER TABLE /*_*/categorylinks_tmp RENAME TO /*_*/categorylinks;
50
51 -- We always sort within a given category, and within a given type. FIXME:
52 -- Formerly this index didn't cover cl_type (since that didn't exist), so old
53 -- callers won't be using an index: fix this?
54 CREATE INDEX /*i*/cl_sortkey ON /*_*/categorylinks (cl_to,cl_type,cl_sortkey,cl_from);
55
56 -- Used by the API (and some extensions)
57 CREATE INDEX /*i*/cl_timestamp ON /*_*/categorylinks (cl_to,cl_timestamp);
58
59 -- Used when updating collation (e.g. updateCollation.php)
60 CREATE INDEX /*i*/cl_collation_ext ON /*_*/categorylinks (cl_collation, cl_to, cl_type, cl_from);