Merge "resourceloader: Fix undefined variable in ResourceLoaderFileModule::getSkipFun...
[lhc/web/wiklou.git] / maintenance / archives / patch-restructure.sql
1 -- The Great Restructuring of October 2004
2 -- Creates 'page', 'revision' tables and transforms the classic
3 -- cur+old into a separate page+revision+text structure.
4 --
5 -- The pre-conversion 'old' table is renamed to 'text' and used
6 -- without internal restructuring to avoid rebuilding the entire
7 -- table. (This can be done separately if desired.)
8 --
9 -- The pre-conversion 'cur' table is now redundant and can be
10 -- discarded when done.
11
12 CREATE TABLE /*$wgDBprefix*/page (
13 page_id int unsigned NOT NULL auto_increment,
14 page_namespace tinyint NOT NULL,
15 page_title varchar(255) binary NOT NULL,
16 page_restrictions tinyblob NOT NULL,
17 page_counter bigint unsigned NOT NULL default '0',
18 page_is_redirect tinyint unsigned NOT NULL default '0',
19 page_is_new tinyint unsigned NOT NULL default '0',
20 page_random real unsigned NOT NULL,
21 page_touched binary(14) NOT NULL default '',
22 page_latest int unsigned NOT NULL,
23 page_len int unsigned NOT NULL,
24
25 PRIMARY KEY page_id (page_id),
26 UNIQUE INDEX name_title (page_namespace,page_title),
27 INDEX (page_random),
28 INDEX (page_len)
29 );
30
31 CREATE TABLE /*$wgDBprefix*/revision (
32 rev_id int unsigned NOT NULL auto_increment,
33 rev_page int unsigned NOT NULL,
34 rev_comment tinyblob NOT NULL,
35 rev_user int unsigned NOT NULL default '0',
36 rev_user_text varchar(255) binary NOT NULL default '',
37 rev_timestamp binary(14) NOT NULL default '',
38 rev_minor_edit tinyint unsigned NOT NULL default '0',
39 rev_deleted tinyint unsigned NOT NULL default '0',
40
41 PRIMARY KEY rev_page_id (rev_page, rev_id),
42 UNIQUE INDEX rev_id (rev_id),
43 INDEX rev_timestamp (rev_timestamp),
44 INDEX page_timestamp (rev_page,rev_timestamp),
45 INDEX user_timestamp (rev_user,rev_timestamp),
46 INDEX usertext_timestamp (rev_user_text,rev_timestamp)
47 );
48
49 -- If creating new 'text' table it would look like this:
50 --
51 -- CREATE TABLE /*$wgDBprefix*/text (
52 -- old_id int(8) unsigned NOT NULL auto_increment,
53 -- old_text mediumtext NOT NULL,
54 -- old_flags tinyblob NOT NULL,
55 --
56 -- PRIMARY KEY old_id (old_id)
57 -- );
58
59
60 -- Lock!
61 LOCK TABLES /*$wgDBprefix*/page WRITE, /*$wgDBprefix*/revision WRITE, /*$wgDBprefix*/old WRITE, /*$wgDBprefix*/cur WRITE;
62
63 -- Save the last old_id value for later
64 SELECT (@maxold:=MAX(old_id)) FROM /*$wgDBprefix*/old;
65
66 -- First, copy all current entries into the old table.
67 INSERT
68 INTO /*$wgDBprefix*/old
69 (old_namespace,
70 old_title,
71 old_text,
72 old_comment,
73 old_user,
74 old_user_text,
75 old_timestamp,
76 old_minor_edit,
77 old_flags)
78 SELECT
79 cur_namespace,
80 cur_title,
81 cur_text,
82 cur_comment,
83 cur_user,
84 cur_user_text,
85 cur_timestamp,
86 cur_minor_edit,
87 ''
88 FROM /*$wgDBprefix*/cur;
89
90 -- Now, copy all old data except the text into revisions
91 INSERT
92 INTO /*$wgDBprefix*/revision
93 (rev_id,
94 rev_page,
95 rev_comment,
96 rev_user,
97 rev_user_text,
98 rev_timestamp,
99 rev_minor_edit)
100 SELECT
101 old_id,
102 cur_id,
103 old_comment,
104 old_user,
105 old_user_text,
106 old_timestamp,
107 old_minor_edit
108 FROM /*$wgDBprefix*/old,/*$wgDBprefix*/cur
109 WHERE old_namespace=cur_namespace
110 AND old_title=cur_title;
111
112 -- And, copy the cur data into page
113 INSERT
114 INTO /*$wgDBprefix*/page
115 (page_id,
116 page_namespace,
117 page_title,
118 page_restrictions,
119 page_counter,
120 page_is_redirect,
121 page_is_new,
122 page_random,
123 page_touched,
124 page_latest)
125 SELECT
126 cur_id,
127 cur_namespace,
128 cur_title,
129 cur_restrictions,
130 cur_counter,
131 cur_is_redirect,
132 cur_is_new,
133 cur_random,
134 cur_touched,
135 rev_id
136 FROM /*$wgDBprefix*/cur,/*$wgDBprefix*/revision
137 WHERE cur_id=rev_page
138 AND rev_timestamp=cur_timestamp
139 AND rev_id > @maxold;
140
141 UNLOCK TABLES;
142
143 -- Keep the old table around as the text store.
144 -- Its extra fields will be ignored, but trimming them is slow
145 -- so we won't bother doing it for now.
146 ALTER TABLE /*$wgDBprefix*/old RENAME TO /*$wgDBprefix*/text;