MediaWiki  master
PostgresUpdater.php
Go to the documentation of this file.
1 <?php
25 
33 
37  protected $db;
38 
44  protected function getCoreUpdateList() {
45  return [
46  # rename tables 1.7.3
47  # r15791 Change reserved word table names "user" and "text"
48  [ 'renameTable', 'user', 'mwuser' ],
49  [ 'renameTable', 'text', 'pagecontent' ],
50  [ 'renameIndex', 'mwuser', 'user_pkey', 'mwuser_pkey' ],
51  [ 'renameIndex', 'mwuser', 'user_user_name_key', 'mwuser_user_name_key' ],
52  [ 'renameIndex', 'pagecontent', 'text_pkey', 'pagecontent_pkey' ],
53 
54  # renamed sequences
55  [ 'renameSequence', 'ipblocks_ipb_id_val', 'ipblocks_ipb_id_seq' ],
56  [ 'renameSequence', 'rev_rev_id_val', 'revision_rev_id_seq' ],
57  [ 'renameSequence', 'text_old_id_val', 'text_old_id_seq' ],
58  [ 'renameSequence', 'rc_rc_id_seq', 'recentchanges_rc_id_seq' ],
59  [ 'renameSequence', 'log_log_id_seq', 'logging_log_id_seq' ],
60  [ 'renameSequence', 'pr_id_val', 'page_restrictions_pr_id_seq' ],
61  [ 'renameSequence', 'us_id_seq', 'uploadstash_us_id_seq' ],
62 
63  # since r58263
64  [ 'renameSequence', 'category_id_seq', 'category_cat_id_seq' ],
65 
66  # new sequences if not renamed above
67  [ 'addSequence', 'logging', false, 'logging_log_id_seq' ],
68  [ 'addSequence', 'page_restrictions', false, 'page_restrictions_pr_id_seq' ],
69  [ 'addSequence', 'filearchive', 'fa_id', 'filearchive_fa_id_seq' ],
70  [ 'addSequence', 'archive', false, 'archive_ar_id_seq' ],
71  [ 'addSequence', 'externallinks', false, 'externallinks_el_id_seq' ],
72  [ 'addSequence', 'watchlist', false, 'watchlist_wl_id_seq' ],
73  [ 'addSequence', 'change_tag', false, 'change_tag_ct_id_seq' ],
74 
75  # new tables
76  [ 'addTable', 'category', 'patch-category.sql' ],
77  [ 'addTable', 'page', 'patch-page.sql' ],
78  [ 'addTable', 'querycachetwo', 'patch-querycachetwo.sql' ],
79  [ 'addTable', 'page_props', 'patch-page_props.sql' ],
80  [ 'addTable', 'page_restrictions', 'patch-page_restrictions.sql' ],
81  [ 'addTable', 'protected_titles', 'patch-protected_titles.sql' ],
82  [ 'addTable', 'redirect', 'patch-redirect.sql' ],
83  [ 'addTable', 'updatelog', 'patch-updatelog.sql' ],
84  [ 'addTable', 'change_tag', 'patch-change_tag.sql' ],
85  [ 'addTable', 'user_properties', 'patch-user_properties.sql' ],
86  [ 'addTable', 'log_search', 'patch-log_search.sql' ],
87  [ 'addTable', 'l10n_cache', 'patch-l10n_cache.sql' ],
88  [ 'addTable', 'iwlinks', 'patch-iwlinks.sql' ],
89  [ 'addTable', 'module_deps', 'patch-module_deps.sql' ],
90  [ 'addTable', 'uploadstash', 'patch-uploadstash.sql' ],
91  [ 'addTable', 'user_former_groups', 'patch-user_former_groups.sql' ],
92  [ 'addTable', 'sites', 'patch-sites.sql' ],
93  [ 'addTable', 'bot_passwords', 'patch-bot_passwords.sql' ],
94 
95  # Needed before new field
96  [ 'convertArchive2' ],
97 
98  # new fields
99  [ 'addPgField', 'updatelog', 'ul_value', 'TEXT' ],
100  [ 'addPgField', 'archive', 'ar_deleted', 'SMALLINT NOT NULL DEFAULT 0' ],
101  [ 'addPgField', 'archive', 'ar_len', 'INTEGER' ],
102  [ 'addPgField', 'archive', 'ar_page_id', 'INTEGER' ],
103  [ 'addPgField', 'archive', 'ar_parent_id', 'INTEGER' ],
104  [ 'ifFieldExists', 'archive', 'ar_text_id',
105  'addPgField', 'archive', 'ar_content_model', 'TEXT' ],
106  [ 'ifFieldExists', 'archive', 'ar_text_id',
107  'addPgField', 'archive', 'ar_content_format', 'TEXT' ],
108  [ 'addPgField', 'categorylinks', 'cl_sortkey_prefix', "TEXT NOT NULL DEFAULT ''" ],
109  [ 'addPgField', 'categorylinks', 'cl_collation', "TEXT NOT NULL DEFAULT 0" ],
110  [ 'addPgField', 'categorylinks', 'cl_type', "TEXT NOT NULL DEFAULT 'page'" ],
111  [ 'addPgField', 'image', 'img_sha1', "TEXT NOT NULL DEFAULT ''" ],
112  [ 'addPgField', 'ipblocks', 'ipb_allow_usertalk', 'SMALLINT NOT NULL DEFAULT 0' ],
113  [ 'addPgField', 'ipblocks', 'ipb_anon_only', 'SMALLINT NOT NULL DEFAULT 0' ],
114  [ 'ifTableNotExists', 'actor',
115  'addPgField', 'ipblocks', 'ipb_by_text', "TEXT NOT NULL DEFAULT ''" ],
116  [ 'addPgField', 'ipblocks', 'ipb_block_email', 'SMALLINT NOT NULL DEFAULT 0' ],
117  [ 'addPgField', 'ipblocks', 'ipb_create_account', 'SMALLINT NOT NULL DEFAULT 1' ],
118  [ 'addPgField', 'ipblocks', 'ipb_deleted', 'SMALLINT NOT NULL DEFAULT 0' ],
119  [ 'addPgField', 'ipblocks', 'ipb_enable_autoblock', 'SMALLINT NOT NULL DEFAULT 1' ],
120  [ 'addPgField', 'ipblocks', 'ipb_parent_block_id',
121  'INTEGER DEFAULT NULL REFERENCES ipblocks(ipb_id) ' .
122  'ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED' ],
123  [ 'addPgField', 'filearchive', 'fa_deleted', 'SMALLINT NOT NULL DEFAULT 0' ],
124  [ 'addPgField', 'filearchive', 'fa_sha1', "TEXT NOT NULL DEFAULT ''" ],
125  [ 'addPgField', 'logging', 'log_deleted', 'SMALLINT NOT NULL DEFAULT 0' ],
126  [ 'addPgField', 'logging', 'log_id',
127  "INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('logging_log_id_seq')" ],
128  [ 'addPgField', 'logging', 'log_params', 'TEXT' ],
129  [ 'addPgField', 'mwuser', 'user_editcount', 'INTEGER' ],
130  [ 'addPgField', 'mwuser', 'user_newpass_time', 'TIMESTAMPTZ' ],
131  [ 'addPgField', 'oldimage', 'oi_deleted', 'SMALLINT NOT NULL DEFAULT 0' ],
132  [ 'addPgField', 'oldimage', 'oi_major_mime', "TEXT NOT NULL DEFAULT 'unknown'" ],
133  [ 'addPgField', 'oldimage', 'oi_media_type', 'TEXT' ],
134  [ 'addPgField', 'oldimage', 'oi_metadata', "BYTEA NOT NULL DEFAULT ''" ],
135  [ 'addPgField', 'oldimage', 'oi_minor_mime', "TEXT NOT NULL DEFAULT 'unknown'" ],
136  [ 'addPgField', 'oldimage', 'oi_sha1', "TEXT NOT NULL DEFAULT ''" ],
137  [ 'addPgField', 'page', 'page_content_model', 'TEXT' ],
138  [ 'addPgField', 'page_restrictions', 'pr_id',
139  "INTEGER NOT NULL UNIQUE DEFAULT nextval('page_restrictions_pr_id_seq')" ],
140  [ 'addPgField', 'recentchanges', 'rc_deleted', 'SMALLINT NOT NULL DEFAULT 0' ],
141  [ 'addPgField', 'recentchanges', 'rc_log_action', 'TEXT' ],
142  [ 'addPgField', 'recentchanges', 'rc_log_type', 'TEXT' ],
143  [ 'addPgField', 'recentchanges', 'rc_logid', 'INTEGER NOT NULL DEFAULT 0' ],
144  [ 'addPgField', 'recentchanges', 'rc_new_len', 'INTEGER' ],
145  [ 'addPgField', 'recentchanges', 'rc_old_len', 'INTEGER' ],
146  [ 'addPgField', 'recentchanges', 'rc_params', 'TEXT' ],
147  [ 'addPgField', 'redirect', 'rd_interwiki', 'TEXT NULL' ],
148  [ 'addPgField', 'redirect', 'rd_fragment', 'TEXT NULL' ],
149  [ 'addPgField', 'revision', 'rev_deleted', 'SMALLINT NOT NULL DEFAULT 0' ],
150  [ 'addPgField', 'revision', 'rev_len', 'INTEGER' ],
151  [ 'addPgField', 'revision', 'rev_parent_id', 'INTEGER DEFAULT NULL' ],
152  [ 'ifFieldExists', 'revision', 'rev_text_id',
153  'addPgField', 'revision', 'rev_content_model', 'TEXT' ],
154  [ 'ifFieldExists', 'revision', 'rev_text_id',
155  'addPgField', 'revision', 'rev_content_format', 'TEXT' ],
156  [ 'addPgField', 'site_stats', 'ss_active_users', "INTEGER DEFAULT '-1'" ],
157  [ 'addPgField', 'user_newtalk', 'user_last_timestamp', 'TIMESTAMPTZ' ],
158  [ 'ifTableNotExists', 'actor',
159  'addPgField', 'logging', 'log_user_text', "TEXT NOT NULL DEFAULT ''" ],
160  [ 'addPgField', 'logging', 'log_page', 'INTEGER' ],
161  [ 'addPgField', 'interwiki', 'iw_api', "TEXT NOT NULL DEFAULT ''" ],
162  [ 'addPgField', 'interwiki', 'iw_wikiid', "TEXT NOT NULL DEFAULT ''" ],
163  [ 'addPgField', 'revision', 'rev_sha1', "TEXT NOT NULL DEFAULT ''" ],
164  [ 'addPgField', 'archive', 'ar_sha1', "TEXT NOT NULL DEFAULT ''" ],
165  [ 'addPgField', 'uploadstash', 'us_chunk_inx', "INTEGER NULL" ],
166  [ 'addPgField', 'job', 'job_timestamp', "TIMESTAMPTZ" ],
167  [ 'addPgField', 'job', 'job_random', "INTEGER NOT NULL DEFAULT 0" ],
168  [ 'addPgField', 'job', 'job_attempts', "INTEGER NOT NULL DEFAULT 0" ],
169  [ 'addPgField', 'job', 'job_token', "TEXT NOT NULL DEFAULT ''" ],
170  [ 'addPgField', 'job', 'job_token_timestamp', "TIMESTAMPTZ" ],
171  [ 'addPgField', 'job', 'job_sha1', "TEXT NOT NULL DEFAULT ''" ],
172  [ 'addPgField', 'archive', 'ar_id',
173  "INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('archive_ar_id_seq')" ],
174  [ 'addPgField', 'externallinks', 'el_id',
175  "INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('externallinks_el_id_seq')" ],
176  [ 'addPgField', 'uploadstash', 'us_props', "BYTEA" ],
177 
178  # type changes
179  [ 'changeField', 'archive', 'ar_deleted', 'smallint', '' ],
180  [ 'changeField', 'archive', 'ar_minor_edit', 'smallint',
181  'ar_minor_edit::smallint DEFAULT 0' ],
182  [ 'changeField', 'filearchive', 'fa_deleted', 'smallint', '' ],
183  [ 'changeField', 'filearchive', 'fa_height', 'integer', '' ],
184  [ 'changeField', 'filearchive', 'fa_metadata', 'bytea', "decode(fa_metadata,'escape')" ],
185  [ 'changeField', 'filearchive', 'fa_size', 'integer', '' ],
186  [ 'changeField', 'filearchive', 'fa_width', 'integer', '' ],
187  [ 'changeField', 'filearchive', 'fa_storage_group', 'text', '' ],
188  [ 'changeField', 'filearchive', 'fa_storage_key', 'text', '' ],
189  [ 'changeField', 'image', 'img_metadata', 'bytea', "decode(img_metadata,'escape')" ],
190  [ 'changeField', 'image', 'img_size', 'integer', '' ],
191  [ 'changeField', 'image', 'img_width', 'integer', '' ],
192  [ 'changeField', 'image', 'img_height', 'integer', '' ],
193  [ 'changeField', 'interwiki', 'iw_local', 'smallint', 'iw_local::smallint' ],
194  [ 'changeField', 'interwiki', 'iw_trans', 'smallint', 'iw_trans::smallint DEFAULT 0' ],
195  [ 'changeField', 'ipblocks', 'ipb_auto', 'smallint', 'ipb_auto::smallint DEFAULT 0' ],
196  [ 'changeField', 'ipblocks', 'ipb_anon_only', 'smallint',
197  "CASE WHEN ipb_anon_only=' ' THEN 0 ELSE ipb_anon_only::smallint END DEFAULT 0" ],
198  [ 'changeField', 'ipblocks', 'ipb_create_account', 'smallint',
199  "CASE WHEN ipb_create_account=' ' THEN 0 ELSE ipb_create_account::smallint END DEFAULT 1" ],
200  [ 'changeField', 'ipblocks', 'ipb_enable_autoblock', 'smallint',
201  "CASE WHEN ipb_enable_autoblock=' ' THEN 0 ELSE ipb_enable_autoblock::smallint END DEFAULT 1" ],
202  [ 'changeField', 'ipblocks', 'ipb_block_email', 'smallint',
203  "CASE WHEN ipb_block_email=' ' THEN 0 ELSE ipb_block_email::smallint END DEFAULT 0" ],
204  [ 'changeField', 'ipblocks', 'ipb_address', 'text', 'ipb_address::text' ],
205  [ 'changeField', 'ipblocks', 'ipb_deleted', 'smallint', 'ipb_deleted::smallint DEFAULT 0' ],
206  [ 'changeField', 'mwuser', 'user_token', 'text', '' ],
207  [ 'changeField', 'mwuser', 'user_email_token', 'text', '' ],
208  [ 'changeField', 'objectcache', 'keyname', 'text', '' ],
209  [ 'changeField', 'oldimage', 'oi_height', 'integer', '' ],
210  [ 'changeField', 'oldimage', 'oi_metadata', 'bytea', "decode(img_metadata,'escape')" ],
211  [ 'changeField', 'oldimage', 'oi_size', 'integer', '' ],
212  [ 'changeField', 'oldimage', 'oi_width', 'integer', '' ],
213  [ 'changeField', 'page', 'page_is_redirect', 'smallint',
214  'page_is_redirect::smallint DEFAULT 0' ],
215  [ 'changeField', 'page', 'page_is_new', 'smallint', 'page_is_new::smallint DEFAULT 0' ],
216  [ 'changeField', 'querycache', 'qc_value', 'integer', '' ],
217  [ 'changeField', 'querycachetwo', 'qcc_value', 'integer', '' ],
218  [ 'changeField', 'recentchanges', 'rc_bot', 'smallint', 'rc_bot::smallint DEFAULT 0' ],
219  [ 'changeField', 'recentchanges', 'rc_deleted', 'smallint', '' ],
220  [ 'changeField', 'recentchanges', 'rc_minor', 'smallint', 'rc_minor::smallint DEFAULT 0' ],
221  [ 'changeField', 'recentchanges', 'rc_new', 'smallint', 'rc_new::smallint DEFAULT 0' ],
222  [ 'changeField', 'recentchanges', 'rc_type', 'smallint', 'rc_type::smallint DEFAULT 0' ],
223  [ 'changeField', 'recentchanges', 'rc_patrolled', 'smallint',
224  'rc_patrolled::smallint DEFAULT 0' ],
225  [ 'changeField', 'revision', 'rev_deleted', 'smallint', 'rev_deleted::smallint DEFAULT 0' ],
226  [ 'changeField', 'revision', 'rev_minor_edit', 'smallint',
227  'rev_minor_edit::smallint DEFAULT 0' ],
228  [ 'changeField', 'templatelinks', 'tl_namespace', 'smallint', 'tl_namespace::smallint' ],
229  [ 'changeField', 'user_newtalk', 'user_ip', 'text', 'host(user_ip)' ],
230  [ 'changeField', 'uploadstash', 'us_image_bits', 'smallint', '' ],
231 
232  # null changes
233  [ 'changeNullableField', 'oldimage', 'oi_bits', 'NULL' ],
234  [ 'changeNullableField', 'oldimage', 'oi_timestamp', 'NULL' ],
235  [ 'changeNullableField', 'oldimage', 'oi_major_mime', 'NULL' ],
236  [ 'changeNullableField', 'oldimage', 'oi_minor_mime', 'NULL' ],
237  [ 'changeNullableField', 'image', 'img_metadata', 'NOT NULL' ],
238  [ 'changeNullableField', 'filearchive', 'fa_metadata', 'NOT NULL' ],
239  [ 'changeNullableField', 'recentchanges', 'rc_cur_id', 'NULL' ],
240  [ 'changeNullableField', 'recentchanges', 'rc_cur_time', 'NULL' ],
241 
242  [ 'checkOiDeleted' ],
243 
244  # New indexes
245  [ 'ifTableNotExists', 'actor', 'addPgIndex', 'archive', 'archive_user_text', '(ar_user_text)' ],
246  [ 'addPgIndex', 'image', 'img_sha1', '(img_sha1)' ],
247  [ 'addPgIndex', 'ipblocks', 'ipb_parent_block_id', '(ipb_parent_block_id)' ],
248  [ 'addPgIndex', 'oldimage', 'oi_sha1', '(oi_sha1)' ],
249  [ 'addPgIndex', 'page', 'page_mediawiki_title', '(page_title) WHERE page_namespace = 8' ],
250  [ 'addPgIndex', 'pagelinks', 'pagelinks_title', '(pl_title)' ],
251  [ 'addPgIndex', 'page_props', 'pp_propname_page', '(pp_propname, pp_page)' ],
252  [ 'ifFieldExists', 'revision', 'rev_text_id',
253  'addPgIndex', 'revision', 'rev_text_id_idx', '(rev_text_id)' ],
254  [ 'addPgIndex', 'recentchanges', 'rc_timestamp_bot', '(rc_timestamp) WHERE rc_bot = 0' ],
255  [ 'addPgIndex', 'templatelinks', 'templatelinks_from', '(tl_from)' ],
256  [ 'addPgIndex', 'watchlist', 'wl_user', '(wl_user)' ],
257  [ 'addPgIndex', 'watchlist', 'wl_user_notificationtimestamp',
258  '(wl_user, wl_notificationtimestamp)' ],
259  [ 'ifTableNotExists', 'actor', 'addPgIndex', 'logging', 'logging_user_type_time',
260  '(log_user, log_type, log_timestamp)' ],
261  [ 'addPgIndex', 'logging', 'logging_page_id_time', '(log_page,log_timestamp)' ],
262  [ 'addPgIndex', 'iwlinks', 'iwl_prefix_from_title', '(iwl_prefix, iwl_from, iwl_title)' ],
263  [ 'addPgIndex', 'iwlinks', 'iwl_prefix_title_from', '(iwl_prefix, iwl_title, iwl_from)' ],
264  [ 'addPgIndex', 'job', 'job_timestamp_idx', '(job_timestamp)' ],
265  [ 'addPgIndex', 'job', 'job_sha1', '(job_sha1)' ],
266  [ 'addPgIndex', 'job', 'job_cmd_token', '(job_cmd, job_token, job_random)' ],
267  [ 'addPgIndex', 'job', 'job_cmd_token_id', '(job_cmd, job_token, job_id)' ],
268  [ 'addPgIndex', 'filearchive', 'fa_sha1', '(fa_sha1)' ],
269  [ 'ifTableNotExists', 'actor', 'addPgIndex', 'logging', 'logging_user_text_type_time',
270  '(log_user_text, log_type, log_timestamp)' ],
271  [ 'ifTableNotExists', 'actor', 'addPgIndex', 'logging', 'logging_user_text_time',
272  '(log_user_text, log_timestamp)' ],
273 
274  [ 'checkIndex', 'pagelink_unique', [
275  [ 'pl_from', 'int4_ops', 'btree', 0 ],
276  [ 'pl_namespace', 'int2_ops', 'btree', 0 ],
277  [ 'pl_title', 'text_ops', 'btree', 0 ],
278  ],
279  'CREATE UNIQUE INDEX pagelink_unique ON pagelinks (pl_from,pl_namespace,pl_title)' ],
280  [ 'checkIndex', 'cl_sortkey', [
281  [ 'cl_to', 'text_ops', 'btree', 0 ],
282  [ 'cl_sortkey', 'text_ops', 'btree', 0 ],
283  [ 'cl_from', 'int4_ops', 'btree', 0 ],
284  ],
285  'CREATE INDEX cl_sortkey ON "categorylinks" ' .
286  'USING "btree" ("cl_to", "cl_sortkey", "cl_from")' ],
287  [ 'checkIndex', 'iwl_prefix_title_from', [
288  [ 'iwl_prefix', 'text_ops', 'btree', 0 ],
289  [ 'iwl_title', 'text_ops', 'btree', 0 ],
290  [ 'iwl_from', 'int4_ops', 'btree', 0 ],
291  ],
292  'CREATE INDEX iwl_prefix_title_from ON "iwlinks" ' .
293  'USING "btree" ("iwl_prefix", "iwl_title", "iwl_from")' ],
294  [ 'checkIndex', 'logging_times', [
295  [ 'log_timestamp', 'timestamptz_ops', 'btree', 0 ],
296  ],
297  'CREATE INDEX "logging_times" ON "logging" USING "btree" ("log_timestamp")' ],
298  [ 'dropPgIndex', 'oldimage', 'oi_name' ],
299  [ 'checkIndex', 'oi_name_archive_name', [
300  [ 'oi_name', 'text_ops', 'btree', 0 ],
301  [ 'oi_archive_name', 'text_ops', 'btree', 0 ],
302  ],
303  'CREATE INDEX "oi_name_archive_name" ON "oldimage" ' .
304  'USING "btree" ("oi_name", "oi_archive_name")' ],
305  [ 'checkIndex', 'oi_name_timestamp', [
306  [ 'oi_name', 'text_ops', 'btree', 0 ],
307  [ 'oi_timestamp', 'timestamptz_ops', 'btree', 0 ],
308  ],
309  'CREATE INDEX "oi_name_timestamp" ON "oldimage" ' .
310  'USING "btree" ("oi_name", "oi_timestamp")' ],
311  [ 'checkIndex', 'page_main_title', [
312  [ 'page_title', 'text_pattern_ops', 'btree', 0 ],
313  ],
314  'CREATE INDEX "page_main_title" ON "page" ' .
315  'USING "btree" ("page_title" "text_pattern_ops") WHERE ("page_namespace" = 0)' ],
316  [ 'checkIndex', 'page_mediawiki_title', [
317  [ 'page_title', 'text_pattern_ops', 'btree', 0 ],
318  ],
319  'CREATE INDEX "page_mediawiki_title" ON "page" ' .
320  'USING "btree" ("page_title" "text_pattern_ops") WHERE ("page_namespace" = 8)' ],
321  [ 'checkIndex', 'page_project_title', [
322  [ 'page_title', 'text_pattern_ops', 'btree', 0 ],
323  ],
324  'CREATE INDEX "page_project_title" ON "page" ' .
325  'USING "btree" ("page_title" "text_pattern_ops") ' .
326  'WHERE ("page_namespace" = 4)' ],
327  [ 'checkIndex', 'page_talk_title', [
328  [ 'page_title', 'text_pattern_ops', 'btree', 0 ],
329  ],
330  'CREATE INDEX "page_talk_title" ON "page" ' .
331  'USING "btree" ("page_title" "text_pattern_ops") ' .
332  'WHERE ("page_namespace" = 1)' ],
333  [ 'checkIndex', 'page_user_title', [
334  [ 'page_title', 'text_pattern_ops', 'btree', 0 ],
335  ],
336  'CREATE INDEX "page_user_title" ON "page" ' .
337  'USING "btree" ("page_title" "text_pattern_ops") WHERE ' .
338  '("page_namespace" = 2)' ],
339  [ 'checkIndex', 'page_utalk_title', [
340  [ 'page_title', 'text_pattern_ops', 'btree', 0 ],
341  ],
342  'CREATE INDEX "page_utalk_title" ON "page" ' .
343  'USING "btree" ("page_title" "text_pattern_ops") ' .
344  'WHERE ("page_namespace" = 3)' ],
345  [ 'checkIndex', 'ts2_page_text', [
346  [ 'textvector', 'tsvector_ops', 'gist', 0 ],
347  ],
348  'CREATE INDEX "ts2_page_text" ON "pagecontent" USING "gist" ("textvector")' ],
349  [ 'checkIndex', 'ts2_page_title', [
350  [ 'titlevector', 'tsvector_ops', 'gist', 0 ],
351  ],
352  'CREATE INDEX "ts2_page_title" ON "page" USING "gist" ("titlevector")' ],
353 
354  [ 'checkOiNameConstraint' ],
355  [ 'checkPageDeletedTrigger' ],
356  [ 'checkRevUserFkey' ],
357  [ 'dropPgIndex', 'ipblocks', 'ipb_address' ],
358  [ 'checkIndex', 'ipb_address_unique', [
359  [ 'ipb_address', 'text_ops', 'btree', 0 ],
360  [ 'ipb_user', 'int4_ops', 'btree', 0 ],
361  [ 'ipb_auto', 'int2_ops', 'btree', 0 ],
362  ],
363  'CREATE UNIQUE INDEX ipb_address_unique ' .
364  'ON ipblocks (ipb_address,ipb_user,ipb_auto)' ],
365 
366  [ 'checkIwlPrefix' ],
367 
368  # All FK columns should be deferred
369  [ 'ifTableNotExists', 'actor', 'changeFkeyDeferrable', 'archive', 'ar_user',
370  'mwuser(user_id) ON DELETE SET NULL' ],
371  [ 'changeFkeyDeferrable', 'categorylinks', 'cl_from', 'page(page_id) ON DELETE CASCADE' ],
372  [ 'changeFkeyDeferrable', 'externallinks', 'el_from', 'page(page_id) ON DELETE CASCADE' ],
373  [ 'changeFkeyDeferrable', 'filearchive', 'fa_deleted_user',
374  'mwuser(user_id) ON DELETE SET NULL' ],
375  [ 'ifTableNotExists', 'actor', 'changeFkeyDeferrable', 'filearchive', 'fa_user',
376  'mwuser(user_id) ON DELETE SET NULL' ],
377  [ 'ifTableNotExists', 'actor', 'changeFkeyDeferrable', 'image', 'img_user',
378  'mwuser(user_id) ON DELETE SET NULL' ],
379  [ 'changeFkeyDeferrable', 'imagelinks', 'il_from', 'page(page_id) ON DELETE CASCADE' ],
380  [ 'ifTableNotExists', 'actor', 'changeFkeyDeferrable', 'ipblocks', 'ipb_by',
381  'mwuser(user_id) ON DELETE CASCADE' ],
382  [ 'changeFkeyDeferrable', 'ipblocks', 'ipb_user', 'mwuser(user_id) ON DELETE SET NULL' ],
383  [ 'changeFkeyDeferrable', 'ipblocks', 'ipb_parent_block_id',
384  'ipblocks(ipb_id) ON DELETE SET NULL' ],
385  [ 'changeFkeyDeferrable', 'langlinks', 'll_from', 'page(page_id) ON DELETE CASCADE' ],
386  [ 'ifTableNotExists', 'actor', 'changeFkeyDeferrable', 'logging', 'log_user',
387  'mwuser(user_id) ON DELETE SET NULL' ],
388  [ 'changeFkeyDeferrable', 'oldimage', 'oi_name',
389  'image(img_name) ON DELETE CASCADE ON UPDATE CASCADE' ],
390  [ 'ifTableNotExists', 'actor', 'changeFkeyDeferrable', 'oldimage', 'oi_user',
391  'mwuser(user_id) ON DELETE SET NULL' ],
392  [ 'changeFkeyDeferrable', 'pagelinks', 'pl_from', 'page(page_id) ON DELETE CASCADE' ],
393  [ 'changeFkeyDeferrable', 'page_props', 'pp_page', 'page (page_id) ON DELETE CASCADE' ],
394  [ 'changeFkeyDeferrable', 'page_restrictions', 'pr_page',
395  'page(page_id) ON DELETE CASCADE' ],
396  [ 'changeFkeyDeferrable', 'protected_titles', 'pt_user',
397  'mwuser(user_id) ON DELETE SET NULL' ],
398  [ 'ifTableNotExists', 'actor', 'changeFkeyDeferrable', 'recentchanges', 'rc_user',
399  'mwuser(user_id) ON DELETE SET NULL' ],
400  [ 'changeFkeyDeferrable', 'redirect', 'rd_from', 'page(page_id) ON DELETE CASCADE' ],
401  [ 'changeFkeyDeferrable', 'revision', 'rev_page', 'page (page_id) ON DELETE CASCADE' ],
402  [ 'ifFieldExists', 'revision', 'rev_text_id',
403  'changeFkeyDeferrable', 'revision', 'rev_user', 'mwuser(user_id) ON DELETE RESTRICT' ],
404  [ 'changeFkeyDeferrable', 'templatelinks', 'tl_from', 'page(page_id) ON DELETE CASCADE' ],
405  [ 'changeFkeyDeferrable', 'user_groups', 'ug_user', 'mwuser(user_id) ON DELETE CASCADE' ],
406  [ 'changeFkeyDeferrable', 'user_newtalk', 'user_id', 'mwuser(user_id) ON DELETE CASCADE' ],
407  [ 'changeFkeyDeferrable', 'user_properties', 'up_user',
408  'mwuser(user_id) ON DELETE CASCADE' ],
409  [ 'changeFkeyDeferrable', 'watchlist', 'wl_user', 'mwuser(user_id) ON DELETE CASCADE' ],
410 
411  # r81574
412  [ 'addInterwikiType' ],
413  # end
414  [ 'tsearchFixes' ],
415 
416  // 1.23
417  [ 'addPgField', 'recentchanges', 'rc_source', "TEXT NOT NULL DEFAULT ''" ],
418  [ 'addPgField', 'page', 'page_links_updated', "TIMESTAMPTZ NULL" ],
419  [ 'addPgField', 'mwuser', 'user_password_expires', 'TIMESTAMPTZ NULL' ],
420  [ 'changeFieldPurgeTable', 'l10n_cache', 'lc_value', 'bytea',
421  "replace(lc_value,'\','\\\\')::bytea" ],
422  // 1.23.9
423  [ 'rebuildTextSearch' ],
424 
425  // 1.24
426  [ 'addPgField', 'page_props', 'pp_sortkey', 'float NULL' ],
427  [ 'addPgIndex', 'page_props', 'pp_propname_sortkey_page',
428  '( pp_propname, pp_sortkey, pp_page ) WHERE ( pp_sortkey IS NOT NULL )' ],
429  [ 'addPgField', 'page', 'page_lang', 'TEXT default NULL' ],
430  [ 'addPgField', 'pagelinks', 'pl_from_namespace', 'INTEGER NOT NULL DEFAULT 0' ],
431  [ 'addPgField', 'templatelinks', 'tl_from_namespace', 'INTEGER NOT NULL DEFAULT 0' ],
432  [ 'addPgField', 'imagelinks', 'il_from_namespace', 'INTEGER NOT NULL DEFAULT 0' ],
433 
434  // 1.25
435  [ 'dropTable', 'hitcounter' ],
436  [ 'dropField', 'site_stats', 'ss_total_views', 'patch-drop-ss_total_views.sql' ],
437  [ 'dropField', 'page', 'page_counter', 'patch-drop-page_counter.sql' ],
438  [ 'dropFkey', 'recentchanges', 'rc_cur_id' ],
439 
440  // 1.27
441  [ 'dropTable', 'msg_resource_links' ],
442  [ 'dropTable', 'msg_resource' ],
443  [
444  'addPgField', 'watchlist', 'wl_id',
445  "INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('watchlist_wl_id_seq')"
446  ],
447 
448  // 1.28
449  [ 'addPgIndex', 'recentchanges', 'rc_name_type_patrolled_timestamp',
450  '( rc_namespace, rc_type, rc_patrolled, rc_timestamp )' ],
451  [ 'addPgField', 'change_tag', 'ct_id',
452  "INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('change_tag_ct_id_seq')" ],
453 
454  // 1.29
455  [ 'addPgField', 'externallinks', 'el_index_60', "BYTEA NOT NULL DEFAULT ''" ],
456  [ 'addPgIndex', 'externallinks', 'el_index_60', '( el_index_60, el_id )' ],
457  [ 'addPgIndex', 'externallinks', 'el_from_index_60', '( el_from, el_index_60, el_id )' ],
458  [ 'addPgField', 'user_groups', 'ug_expiry', "TIMESTAMPTZ NULL" ],
459  [ 'addPgIndex', 'user_groups', 'user_groups_expiry', '( ug_expiry )' ],
460 
461  // 1.30
462  [ 'addPgEnumValue', 'media_type', '3D' ],
463  [ 'setDefault', 'revision', 'rev_comment', '' ],
464  [ 'changeNullableField', 'revision', 'rev_comment', 'NOT NULL', true ],
465  [ 'setDefault', 'archive', 'ar_comment', '' ],
466  [ 'changeNullableField', 'archive', 'ar_comment', 'NOT NULL', true ],
467  [ 'addPgField', 'archive', 'ar_comment_id', 'INTEGER NOT NULL DEFAULT 0' ],
468  [ 'setDefault', 'ipblocks', 'ipb_reason', '' ],
469  [ 'addPgField', 'ipblocks', 'ipb_reason_id', 'INTEGER NOT NULL DEFAULT 0' ],
470  [ 'setDefault', 'image', 'img_description', '' ],
471  [ 'setDefault', 'oldimage', 'oi_description', '' ],
472  [ 'changeNullableField', 'oldimage', 'oi_description', 'NOT NULL', true ],
473  [ 'addPgField', 'oldimage', 'oi_description_id', 'INTEGER NOT NULL DEFAULT 0' ],
474  [ 'setDefault', 'filearchive', 'fa_deleted_reason', '' ],
475  [ 'changeNullableField', 'filearchive', 'fa_deleted_reason', 'NOT NULL', true ],
476  [ 'addPgField', 'filearchive', 'fa_deleted_reason_id', 'INTEGER NOT NULL DEFAULT 0' ],
477  [ 'setDefault', 'filearchive', 'fa_description', '' ],
478  [ 'addPgField', 'filearchive', 'fa_description_id', 'INTEGER NOT NULL DEFAULT 0' ],
479  [ 'setDefault', 'recentchanges', 'rc_comment', '' ],
480  [ 'changeNullableField', 'recentchanges', 'rc_comment', 'NOT NULL', true ],
481  [ 'addPgField', 'recentchanges', 'rc_comment_id', 'INTEGER NOT NULL DEFAULT 0' ],
482  [ 'setDefault', 'logging', 'log_comment', '' ],
483  [ 'changeNullableField', 'logging', 'log_comment', 'NOT NULL', true ],
484  [ 'addPgField', 'logging', 'log_comment_id', 'INTEGER NOT NULL DEFAULT 0' ],
485  [ 'setDefault', 'protected_titles', 'pt_reason', '' ],
486  [ 'changeNullableField', 'protected_titles', 'pt_reason', 'NOT NULL', true ],
487  [ 'addPgField', 'protected_titles', 'pt_reason_id', 'INTEGER NOT NULL DEFAULT 0' ],
488  [ 'addTable', 'comment', 'patch-comment-table.sql' ],
489  [ 'addTable', 'revision_comment_temp', 'patch-revision_comment_temp-table.sql' ],
490  // image_comment_temp is no longer needed when upgrading to MW 1.31 or newer,
491  // as it is dropped later in the update process as part of 'migrateImageCommentTemp'.
492  // File kept on disk and the updater entry here for historical purposes.
493  // [ 'addTable', 'image_comment_temp', 'patch-image_comment_temp-table.sql' ],
494 
495  // This field was added in 1.31, but is put here so it can be used by 'migrateComments'
496  [ 'addPgField', 'image', 'img_description_id', 'INTEGER NOT NULL DEFAULT 0' ],
497 
498  [ 'migrateComments' ],
499  [ 'addIndex', 'site_stats', 'site_stats_pkey', 'patch-site_stats-pk.sql' ],
500  [ 'addTable', 'ip_changes', 'patch-ip_changes.sql' ],
501 
502  // 1.31
503  [ 'addTable', 'slots', 'patch-slots-table.sql' ],
504  [ 'dropPgIndex', 'slots', 'slot_role_inherited' ],
505  [ 'dropPgField', 'slots', 'slot_inherited' ],
506  [ 'addPgField', 'slots', 'slot_origin', 'INTEGER NOT NULL' ],
507  [
508  'addPgIndex',
509  'slots',
510  'slot_revision_origin_role',
511  '( slot_revision_id, slot_origin, slot_role_id )',
512  ],
513  [ 'addTable', 'content', 'patch-content-table.sql' ],
514  [ 'addTable', 'content_models', 'patch-content_models-table.sql' ],
515  [ 'addTable', 'slot_roles', 'patch-slot_roles-table.sql' ],
516  [ 'migrateArchiveText' ],
517  [ 'addTable', 'actor', 'patch-actor-table.sql' ],
518  [ 'addTable', 'revision_actor_temp', 'patch-revision_actor_temp-table.sql' ],
519  [ 'setDefault', 'revision', 'rev_user', 0 ],
520  [ 'setDefault', 'revision', 'rev_user_text', '' ],
521  [ 'setDefault', 'archive', 'ar_user', 0 ],
522  [ 'changeNullableField', 'archive', 'ar_user', 'NOT NULL', true ],
523  [ 'setDefault', 'archive', 'ar_user_text', '' ],
524  [ 'addPgField', 'archive', 'ar_actor', 'INTEGER NOT NULL DEFAULT 0' ],
525  [ 'addPgIndex', 'archive', 'archive_actor', '( ar_actor )' ],
526  [ 'setDefault', 'ipblocks', 'ipb_by', 0 ],
527  [ 'addPgField', 'ipblocks', 'ipb_by_actor', 'INTEGER NOT NULL DEFAULT 0' ],
528  [ 'setDefault', 'image', 'img_user', 0 ],
529  [ 'changeNullableField', 'image', 'img_user', 'NOT NULL', true ],
530  [ 'setDefault', 'image', 'img_user_text', '' ],
531  [ 'addPgField', 'image', 'img_actor', 'INTEGER NOT NULL DEFAULT 0' ],
532  [ 'setDefault', 'oldimage', 'oi_user', 0 ],
533  [ 'changeNullableField', 'oldimage', 'oi_user', 'NOT NULL', true ],
534  [ 'setDefault', 'oldimage', 'oi_user_text', '' ],
535  [ 'addPgField', 'oldimage', 'oi_actor', 'INTEGER NOT NULL DEFAULT 0' ],
536  [ 'setDefault', 'filearchive', 'fa_user', 0 ],
537  [ 'changeNullableField', 'filearchive', 'fa_user', 'NOT NULL', true ],
538  [ 'setDefault', 'filearchive', 'fa_user_text', '' ],
539  [ 'addPgField', 'filearchive', 'fa_actor', 'INTEGER NOT NULL DEFAULT 0' ],
540  [ 'setDefault', 'recentchanges', 'rc_user', 0 ],
541  [ 'changeNullableField', 'recentchanges', 'rc_user', 'NOT NULL', true ],
542  [ 'setDefault', 'recentchanges', 'rc_user_text', '' ],
543  [ 'addPgField', 'recentchanges', 'rc_actor', 'INTEGER NOT NULL DEFAULT 0' ],
544  [ 'setDefault', 'logging', 'log_user', 0 ],
545  [ 'changeNullableField', 'logging', 'log_user', 'NOT NULL', true ],
546  [ 'addPgField', 'logging', 'log_actor', 'INTEGER NOT NULL DEFAULT 0' ],
547  [ 'addPgIndex', 'logging', 'logging_actor_time_backwards', '( log_timestamp, log_actor )' ],
548  [ 'addPgIndex', 'logging', 'logging_actor_type_time', '( log_actor, log_type, log_timestamp )' ],
549  [ 'addPgIndex', 'logging', 'logging_actor_time', '( log_actor, log_timestamp )' ],
550  [ 'migrateActors' ],
551  [ 'modifyTable', 'site_stats', 'patch-site_stats-modify.sql' ],
552  [ 'populateArchiveRevId' ],
553  [ 'dropPgIndex', 'recentchanges', 'rc_namespace_title' ],
554  [
555  'addPgIndex',
556  'recentchanges',
557  'rc_namespace_title_timestamp', '( rc_namespace, rc_title, rc_timestamp )'
558  ],
559  [ 'setSequenceOwner', 'mwuser', 'user_id', 'user_user_id_seq' ],
560  [ 'setSequenceOwner', 'actor', 'actor_id', 'actor_actor_id_seq' ],
561  [ 'setSequenceOwner', 'page', 'page_id', 'page_page_id_seq' ],
562  [ 'setSequenceOwner', 'revision', 'rev_id', 'revision_rev_id_seq' ],
563  [ 'setSequenceOwner', 'ip_changes', 'ipc_rev_id', 'ip_changes_ipc_rev_id_seq' ],
564  [ 'setSequenceOwner', 'pagecontent', 'old_id', 'text_old_id_seq' ],
565  [ 'setSequenceOwner', 'comment', 'comment_id', 'comment_comment_id_seq' ],
566  [ 'setSequenceOwner', 'page_restrictions', 'pr_id', 'page_restrictions_pr_id_seq' ],
567  [ 'setSequenceOwner', 'archive', 'ar_id', 'archive_ar_id_seq' ],
568  [ 'setSequenceOwner', 'content', 'content_id', 'content_content_id_seq' ],
569  [ 'setSequenceOwner', 'slot_roles', 'role_id', 'slot_roles_role_id_seq' ],
570  [ 'setSequenceOwner', 'content_models', 'model_id', 'content_models_model_id_seq' ],
571  [ 'setSequenceOwner', 'externallinks', 'el_id', 'externallinks_el_id_seq' ],
572  [ 'setSequenceOwner', 'ipblocks', 'ipb_id', 'ipblocks_ipb_id_seq' ],
573  [ 'setSequenceOwner', 'filearchive', 'fa_id', 'filearchive_fa_id_seq' ],
574  [ 'setSequenceOwner', 'uploadstash', 'us_id', 'uploadstash_us_id_seq' ],
575  [ 'setSequenceOwner', 'recentchanges', 'rc_id', 'recentchanges_rc_id_seq' ],
576  [ 'setSequenceOwner', 'watchlist', 'wl_id', 'watchlist_wl_id_seq' ],
577  [ 'setSequenceOwner', 'logging', 'log_id', 'logging_log_id_seq' ],
578  [ 'setSequenceOwner', 'job', 'job_id', 'job_job_id_seq' ],
579  [ 'setSequenceOwner', 'category', 'cat_id', 'category_cat_id_seq' ],
580  [ 'setSequenceOwner', 'change_tag', 'ct_id', 'change_tag_ct_id_seq' ],
581  [ 'setSequenceOwner', 'sites', 'site_id', 'sites_site_id_seq' ],
582 
583  // 1.32
584  [ 'addTable', 'change_tag_def', 'patch-change_tag_def.sql' ],
585  [ 'populateExternallinksIndex60' ],
586  [ 'dropDefault', 'externallinks', 'el_index_60' ],
587  [ 'runMaintenance', DeduplicateArchiveRevId::class, 'maintenance/deduplicateArchiveRevId.php' ],
588  [ 'addPgField', 'change_tag', 'ct_tag_id', 'INTEGER NULL' ],
589  [
590  'addPgIndex',
591  'change_tag',
592  'change_tag_tag_id_id',
593  '( ct_tag_id, ct_rc_id, ct_rev_id, ct_log_id )'
594  ],
595  [ 'addPgIndex', 'archive', 'ar_revid_uniq', '(ar_rev_id)', 'unique' ],
596  [ 'dropPgIndex', 'archive', 'ar_revid' ], // Probably doesn't exist, but do it anyway.
597  [ 'populateContentTables' ],
598  [ 'addPgIndex', 'logging', 'log_type_action', '( log_type, log_action, log_timestamp )' ],
599  [ 'dropPgIndex', 'page_props', 'page_props_propname' ],
600  [ 'addIndex', 'interwiki', 'interwiki_pkey', 'patch-interwiki-pk.sql' ],
601  [ 'addIndex', 'protected_titles', 'protected_titles_pkey', 'patch-protected_titles-pk.sql' ],
602  [ 'addIndex', 'site_identifiers', 'site_identifiers_pkey', 'patch-site_identifiers-pk.sql' ],
603  [ 'addPgIndex', 'recentchanges', 'rc_this_oldid', '(rc_this_oldid)' ],
604  [ 'dropTable', 'transcache' ],
605  [ 'runMaintenance', PopulateChangeTagDef::class, 'maintenance/populateChangeTagDef.php' ],
606  [ 'addIndex', 'change_tag', 'change_tag_rc_tag_id',
607  'patch-change_tag-change_tag_rc_tag_id.sql' ],
608  [ 'addPgField', 'ipblocks', 'ipb_sitewide', 'SMALLINT NOT NULL DEFAULT 1' ],
609  [ 'addTable', 'ipblocks_restrictions', 'patch-ipblocks_restrictions-table.sql' ],
610  [ 'migrateImageCommentTemp' ],
611  [ 'dropPgField', 'category', 'cat_hidden' ],
612  [ 'dropPgField', 'site_stats', 'ss_admins' ],
613  [ 'dropPgField', 'recentchanges', 'rc_cur_time' ],
614 
615  // 1.33
616  [ 'dropField', 'change_tag', 'ct_tag', 'patch-drop-ct_tag.sql' ],
617  [ 'dropTable', 'valid_tag' ],
618  [ 'dropTable', 'tag_summary' ],
619  [ 'dropPgField', 'archive', 'ar_comment' ],
620  [ 'dropDefault', 'archive', 'ar_comment_id' ],
621  [ 'dropPgField', 'ipblocks', 'ipb_reason' ],
622  [ 'dropDefault', 'ipblocks', 'ipb_reason_id' ],
623  [ 'dropPgField', 'image', 'img_description' ],
624  [ 'dropDefault', 'image', 'img_description_id' ],
625  [ 'dropPgField', 'oldimage', 'oi_description' ],
626  [ 'dropDefault', 'oldimage', 'oi_description_id' ],
627  [ 'dropPgField', 'filearchive', 'fa_deleted_reason' ],
628  [ 'dropDefault', 'filearchive', 'fa_deleted_reason_id' ],
629  [ 'dropPgField', 'filearchive', 'fa_description' ],
630  [ 'dropDefault', 'filearchive', 'fa_description_id' ],
631  [ 'dropPgField', 'recentchanges', 'rc_comment' ],
632  [ 'dropDefault', 'recentchanges', 'rc_comment_id' ],
633  [ 'dropPgField', 'logging', 'log_comment' ],
634  [ 'dropDefault', 'logging', 'log_comment_id' ],
635  [ 'dropPgField', 'protected_titles', 'pt_reason' ],
636  [ 'dropDefault', 'protected_titles', 'pt_reason_id' ],
637 
638  // 1.34
639  [ 'dropPgIndex', 'archive', 'archive_user_text' ],
640  [ 'dropPgField', 'archive', 'ar_user' ],
641  [ 'dropPgField', 'archive', 'ar_user_text' ],
642  [ 'dropDefault', 'archive', 'ar_actor' ],
643  [ 'dropPgField', 'ipblocks', 'ipb_by' ],
644  [ 'dropPgField', 'ipblocks', 'ipb_by_text' ],
645  [ 'dropDefault', 'ipblocks', 'ipb_by_actor' ],
646  [ 'dropPgField', 'image', 'img_user' ],
647  [ 'dropPgField', 'image', 'img_user_text' ],
648  [ 'dropDefault', 'image', 'img_actor' ],
649  [ 'dropPgField', 'oldimage', 'oi_user' ],
650  [ 'dropPgField', 'oldimage', 'oi_user_text' ],
651  [ 'dropDefault', 'oldimage', 'oi_actor' ],
652  [ 'dropPgField', 'filearchive', 'fa_user' ],
653  [ 'dropPgField', 'filearchive', 'fa_user_text' ],
654  [ 'dropDefault', 'filearchive', 'fa_actor' ],
655  [ 'dropPgField', 'recentchanges', 'rc_user' ],
656  [ 'dropPgField', 'recentchanges', 'rc_user_text' ],
657  [ 'dropDefault', 'recentchanges', 'rc_actor' ],
658  [ 'dropPgIndex', 'logging', 'logging_user_time' ],
659  [ 'dropPgIndex', 'logging', 'logging_user_type_time' ],
660  [ 'dropPgIndex', 'logging', 'logging_user_text_type_time' ],
661  [ 'dropPgIndex', 'logging', 'logging_user_text_time' ],
662  [ 'dropPgField', 'logging', 'log_user' ],
663  [ 'dropPgField', 'logging', 'log_user_text' ],
664  [ 'dropDefault', 'logging', 'log_actor' ],
665 
666  // 1.35
667  [ 'addIndex', 'redirect', 'redirect_pkey', 'patch-redirect-pk.sql' ],
668  [ 'addTable', 'watchlist_expiry', 'patch-watchlist_expiry.sql' ],
669  [ 'setSequenceOwner', 'watchlist_expiry', 'we_item', 'watchlist_expiry_we_item_seq' ],
670  [ 'setDefault', 'user_newtalk', 'user_ip', '' ],
671  [ 'changeNullableField', 'user_newtalk', 'user_ip', 'NOT NULL', true ],
672  [ 'setDefault', 'user_newtalk', 'user_id', 0 ],
673  [ 'renameIndex', 'revision_actor_temp', 'rev_actor_timestamp', 'revactor_actor_timestamp' ],
674  [ 'renameIndex', 'revision_actor_temp',
675  'rev_page_actor_timestamp', 'revactor_page_actor_timestamp' ],
676  [ 'dropPgIndex', 'revision', 'rev_user_idx' ],
677  [ 'dropPgIndex', 'revision', 'rev_user_text_idx' ],
678  [ 'dropPgIndex', 'revision', 'rev_text_id_idx' ],
679  [ 'dropPgField', 'revision', 'rev_user' ],
680  [ 'dropPgField', 'revision', 'rev_user_text' ],
681  [ 'dropPgField', 'revision', 'rev_comment' ],
682  [ 'dropPgField', 'revision', 'rev_text_id' ],
683  [ 'dropPgField', 'revision', 'rev_content_model' ],
684  [ 'dropPgField', 'revision', 'rev_content_format' ],
685  [ 'addPgField', 'revision', 'rev_comment_id', 'INTEGER NOT NULL DEFAULT 0' ],
686  [ 'addPgField', 'revision', 'rev_actor', 'INTEGER NOT NULL DEFAULT 0' ],
687  [ 'addPgIndex', 'revision', 'rev_actor_timestamp', '(rev_actor,rev_timestamp,rev_id)' ],
688  [ 'addPgIndex', 'revision', 'rev_page_actor_timestamp', '(rev_page,rev_actor,rev_timestamp)' ],
689  [ 'dropPgField', 'archive', 'ar_text_id' ],
690  [ 'dropPgField', 'archive', 'ar_content_model' ],
691  [ 'dropPgField', 'archive', 'ar_content_format' ],
692  [ 'changeField', 'updatelog', 'ul_key', 'varchar(255)', '' ],
693  [ 'changeField', 'updatelog', 'ul_value', 'TEXT', '' ],
694  [ 'changeField', 'site_identifiers', 'si_type', 'TEXT', '' ],
695  [ 'changeField', 'site_identifiers', 'si_key', 'TEXT', '' ],
696  [ 'changeField', 'actor', 'actor_id', 'BIGINT', '' ],
697  [ 'changeField', 'actor', 'actor_name', 'TEXT', '' ],
698  [ 'changeField', 'user_former_groups', 'ufg_group', 'TEXT', '' ],
699  [ 'dropFkey', 'user_former_groups', 'ufg_user' ],
700  [ 'setDefault', 'bot_passwords', 'bp_token', '' ],
701  [ 'changeField', 'comment', 'comment_id', 'BIGINT', '' ],
702  [ 'changeField', 'slots', 'slot_revision_id', 'BIGINT', '' ],
703  [ 'changeField', 'slots', 'slot_content_id', 'BIGINT', '' ],
704  [ 'changeField', 'slots', 'slot_origin', 'BIGINT', '' ],
705  [ 'changeField', 'site_stats', 'ss_total_edits', 'BIGINT', '' ],
706  [ 'changeField', 'site_stats', 'ss_good_articles', 'BIGINT', '' ],
707  [ 'changeField', 'site_stats', 'ss_total_pages', 'BIGINT', '' ],
708  [ 'changeField', 'site_stats', 'ss_users', 'BIGINT', '' ],
709  [ 'changeField', 'site_stats', 'ss_active_users', 'BIGINT', '' ],
710  [ 'changeField', 'site_stats', 'ss_images', 'BIGINT', '' ],
711  [ 'dropFkey', 'user_properties', 'up_user' ],
712  [ 'addIndex', 'user_properties', 'user_properties_pkey', 'patch-user_properties-pk.sql' ],
713  [ 'changeField', 'log_search', 'ls_value', 'VARCHAR(255)', '' ],
714  [ 'changeField', 'content', 'content_id', 'BIGINT', '' ],
715  ];
716  }
717 
718  protected function getOldGlobalUpdates() {
719  global $wgExtNewTables, $wgExtPGNewFields, $wgExtPGAlteredFields, $wgExtNewIndexes;
720 
721  $updates = [];
722 
723  # Add missing extension tables
724  foreach ( $wgExtNewTables as $tableRecord ) {
725  $updates[] = [
726  'addTable', $tableRecord[0], $tableRecord[1], true
727  ];
728  }
729 
730  # Add missing extension fields
731  foreach ( $wgExtPGNewFields as $fieldRecord ) {
732  $updates[] = [
733  'addPgField', $fieldRecord[0], $fieldRecord[1],
734  $fieldRecord[2]
735  ];
736  }
737 
738  # Change altered columns
739  foreach ( $wgExtPGAlteredFields as $fieldRecord ) {
740  $updates[] = [
741  'changeField', $fieldRecord[0], $fieldRecord[1],
742  $fieldRecord[2]
743  ];
744  }
745 
746  # Add missing extension indexes
747  foreach ( $wgExtNewIndexes as $fieldRecord ) {
748  $updates[] = [
749  'addPgExtIndex', $fieldRecord[0], $fieldRecord[1],
750  $fieldRecord[2]
751  ];
752  }
753 
754  return $updates;
755  }
756 
757  protected function describeTable( $table ) {
758  $q = <<<END
759 SELECT attname, attnum FROM pg_namespace, pg_class, pg_attribute
760  WHERE pg_class.relnamespace = pg_namespace.oid
761  AND attrelid=pg_class.oid AND attnum > 0
762  AND relname=%s AND nspname=%s
763 END;
764  $res = $this->db->query(
765  sprintf( $q,
766  $this->db->addQuotes( $table ),
767  $this->db->addQuotes( $this->db->getCoreSchema() )
768  ),
769  __METHOD__
770  );
771  if ( !$res ) {
772  return null;
773  }
774 
775  $cols = [];
776  foreach ( $res as $r ) {
777  $cols[] = [
778  "name" => $r[0],
779  "ord" => $r[1],
780  ];
781  }
782 
783  return $cols;
784  }
785 
786  protected function describeIndex( $idx ) {
787  // first fetch the key (which is a list of columns ords) and
788  // the table the index applies to (an oid)
789  $q = <<<END
790 SELECT indkey, indrelid FROM pg_namespace, pg_class, pg_index
791  WHERE nspname=%s
792  AND pg_class.relnamespace = pg_namespace.oid
793  AND relname=%s
794  AND indexrelid=pg_class.oid
795 END;
796  $res = $this->db->query(
797  sprintf(
798  $q,
799  $this->db->addQuotes( $this->db->getCoreSchema() ),
800  $this->db->addQuotes( $idx )
801  ),
802  __METHOD__
803  );
804  if ( !$res ) {
805  return null;
806  }
807  $r = $this->db->fetchRow( $res );
808  if ( !$r ) {
809  return null;
810  }
811 
812  $indkey = $r[0];
813  $relid = intval( $r[1] );
814  $indkeys = explode( ' ', $indkey );
815 
816  $colnames = [];
817  foreach ( $indkeys as $rid ) {
818  $query = <<<END
819 SELECT attname FROM pg_class, pg_attribute
820  WHERE attrelid=$relid
821  AND attnum=%d
822  AND attrelid=pg_class.oid
823 END;
824  $r2 = $this->db->query( sprintf( $query, $rid ), __METHOD__ );
825  if ( !$r2 ) {
826  return null;
827  }
828  $row2 = $this->db->fetchRow( $r2 );
829  if ( !$row2 ) {
830  return null;
831  }
832  $colnames[] = $row2[0];
833  }
834 
835  return $colnames;
836  }
837 
838  protected function fkeyDeltype( $fkey ) {
839  $q = <<<END
840 SELECT confdeltype FROM pg_constraint, pg_namespace
841  WHERE connamespace=pg_namespace.oid
842  AND nspname=%s
843  AND conname=%s;
844 END;
845  $r = $this->db->query(
846  sprintf(
847  $q,
848  $this->db->addQuotes( $this->db->getCoreSchema() ),
849  $this->db->addQuotes( $fkey )
850  ),
851  __METHOD__
852  );
853  $row = $this->db->fetchRow( $r );
854  if ( !$row ) {
855  return null;
856  }
857 
858  return $row[0];
859  }
860 
861  protected function ruleDef( $table, $rule ) {
862  $q = <<<END
863 SELECT definition FROM pg_rules
864  WHERE schemaname = %s
865  AND tablename = %s
866  AND rulename = %s
867 END;
868  $r = $this->db->query(
869  sprintf(
870  $q,
871  $this->db->addQuotes( $this->db->getCoreSchema() ),
872  $this->db->addQuotes( $table ),
873  $this->db->addQuotes( $rule )
874  ),
875  __METHOD__
876  );
877  $row = $this->db->fetchRow( $r );
878  if ( !$row ) {
879  return null;
880  }
881  $d = $row[0];
882 
883  return $d;
884  }
885 
886  protected function addSequence( $table, $pkey, $ns ) {
887  if ( !$this->db->sequenceExists( $ns ) ) {
888  $this->output( "Creating sequence $ns\n" );
889  if ( $pkey !== false ) {
890  $this->db->query( "CREATE SEQUENCE $ns OWNED BY $table.$pkey", __METHOD__ );
891  $this->setDefault( $table, $pkey, '"nextval"(\'"' . $ns . '"\'::"regclass")' );
892  } else {
893  $this->db->query( "CREATE SEQUENCE $ns", __METHOD__ );
894  }
895  }
896  }
897 
898  protected function dropSequence( $table, $ns ) {
899  if ( $this->db->sequenceExists( $ns ) ) {
900  $this->output( "Dropping sequence $ns\n" );
901  $this->db->query( "DROP SEQUENCE $ns CASCADE", __METHOD__ );
902  }
903  }
904 
905  protected function renameSequence( $old, $new ) {
906  if ( $this->db->sequenceExists( $new ) ) {
907  $this->output( "...sequence $new already exists.\n" );
908 
909  return;
910  }
911  if ( $this->db->sequenceExists( $old ) ) {
912  $this->output( "Renaming sequence $old to $new\n" );
913  $this->db->query( "ALTER SEQUENCE $old RENAME TO $new", __METHOD__ );
914  }
915  }
916 
917  protected function setSequenceOwner( $table, $pkey, $seq ) {
918  if ( $this->db->sequenceExists( $seq ) ) {
919  $this->output( "Setting sequence $seq owner to $table.$pkey\n" );
920  $this->db->query( "ALTER SEQUENCE $seq OWNED BY $table.$pkey", __METHOD__ );
921  }
922  }
923 
924  protected function renameTable( $old, $new, $patch = false ) {
925  if ( $this->db->tableExists( $old, __METHOD__ ) ) {
926  $this->output( "Renaming table $old to $new\n" );
927  $old = $this->db->realTableName( $old, "quoted" );
928  $new = $this->db->realTableName( $new, "quoted" );
929  $this->db->query( "ALTER TABLE $old RENAME TO $new", __METHOD__ );
930  if ( $patch !== false ) {
931  $this->applyPatch( $patch );
932  }
933  }
934  }
935 
936  protected function renameIndex(
937  $table, $old, $new, $skipBothIndexExistWarning = false, $a = false, $b = false
938  ) {
939  // First requirement: the table must exist
940  if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
941  $this->output( "...skipping: '$table' table doesn't exist yet.\n" );
942 
943  return true;
944  }
945 
946  // Second requirement: the new index must be missing
947  if ( $this->db->indexExists( $table, $new, __METHOD__ ) ) {
948  $this->output( "...index $new already set on $table table.\n" );
949  if ( !$skipBothIndexExistWarning
950  && $this->db->indexExists( $table, $old, __METHOD__ )
951  ) {
952  $this->output( "...WARNING: $old still exists, despite it has been " .
953  "renamed into $new (which also exists).\n" .
954  " $old should be manually removed if not needed anymore.\n" );
955  }
956 
957  return true;
958  }
959 
960  // Third requirement: the old index must exist
961  if ( !$this->db->indexExists( $table, $old, __METHOD__ ) ) {
962  $this->output( "...skipping: index $old doesn't exist.\n" );
963 
964  return true;
965  }
966 
967  $this->db->query( "ALTER INDEX $old RENAME TO $new", __METHOD__ );
968  return true;
969  }
970 
971  protected function dropPgField( $table, $field ) {
972  $fi = $this->db->fieldInfo( $table, $field );
973  if ( $fi === null ) {
974  $this->output( "...$table table does not contain $field field.\n" );
975 
976  return;
977  } else {
978  $this->output( "Dropping column '$table.$field'\n" );
979  $this->db->query( "ALTER TABLE $table DROP COLUMN $field", __METHOD__ );
980  }
981  }
982 
983  protected function addPgField( $table, $field, $type ) {
984  $fi = $this->db->fieldInfo( $table, $field );
985  if ( $fi !== null ) {
986  $this->output( "...column '$table.$field' already exists\n" );
987 
988  return;
989  } else {
990  $this->output( "Adding column '$table.$field'\n" );
991  $this->db->query( "ALTER TABLE $table ADD $field $type", __METHOD__ );
992  }
993  }
994 
995  protected function changeField( $table, $field, $newtype, $default ) {
996  $fi = $this->db->fieldInfo( $table, $field );
997  if ( $fi === null ) {
998  $this->output( "...ERROR: expected column $table.$field to exist\n" );
999  exit( 1 );
1000  }
1001 
1002  if ( $fi->type() === $newtype ) {
1003  $this->output( "...column '$table.$field' is already of type '$newtype'\n" );
1004  } else {
1005  $this->output( "Changing column type of '$table.$field' from '{$fi->type()}' to '$newtype'\n" );
1006  $sql = "ALTER TABLE $table ALTER $field TYPE $newtype";
1007  if ( strlen( $default ) ) {
1008  $res = [];
1009  if ( preg_match( '/DEFAULT (.+)/', $default, $res ) ) {
1010  $sqldef = "ALTER TABLE $table ALTER $field SET DEFAULT $res[1]";
1011  $this->db->query( $sqldef, __METHOD__ );
1012  $default = preg_replace( '/\s*DEFAULT .+/', '', $default );
1013  }
1014  $sql .= " USING $default";
1015  }
1016  $this->db->query( $sql, __METHOD__ );
1017  }
1018  }
1019 
1020  protected function changeFieldPurgeTable( $table, $field, $newtype, $default ) {
1021  # # For a cache table, empty it if the field needs to be changed, because the old contents
1022  # # may be corrupted. If the column is already the desired type, refrain from purging.
1023  $fi = $this->db->fieldInfo( $table, $field );
1024  if ( $fi === null ) {
1025  $this->output( "...ERROR: expected column $table.$field to exist\n" );
1026  exit( 1 );
1027  }
1028 
1029  if ( $fi->type() === $newtype ) {
1030  $this->output( "...column '$table.$field' is already of type '$newtype'\n" );
1031  } else {
1032  $this->output( "Purging data from cache table '$table'\n" );
1033  $this->db->query( "DELETE from $table", __METHOD__ );
1034  $this->output( "Changing column type of '$table.$field' from '{$fi->type()}' to '$newtype'\n" );
1035  $sql = "ALTER TABLE $table ALTER $field TYPE $newtype";
1036  if ( strlen( $default ) ) {
1037  $res = [];
1038  if ( preg_match( '/DEFAULT (.+)/', $default, $res ) ) {
1039  $sqldef = "ALTER TABLE $table ALTER $field SET DEFAULT $res[1]";
1040  $this->db->query( $sqldef, __METHOD__ );
1041  $default = preg_replace( '/\s*DEFAULT .+/', '', $default );
1042  }
1043  $sql .= " USING $default";
1044  }
1045  $this->db->query( $sql, __METHOD__ );
1046  }
1047  }
1048 
1049  protected function setDefault( $table, $field, $default ) {
1050  $info = $this->db->fieldInfo( $table, $field );
1051  if ( $info && $info->defaultValue() !== $default ) {
1052  $this->output( "Changing '$table.$field' default value\n" );
1053  $this->db->query( "ALTER TABLE $table ALTER $field SET DEFAULT "
1054  . $this->db->addQuotes( $default ), __METHOD__ );
1055  }
1056  }
1057 
1064  protected function dropDefault( $table, $field ) {
1065  $info = $this->db->fieldInfo( $table, $field );
1066  if ( $info->defaultValue() !== false ) {
1067  $this->output( "Removing '$table.$field' default value\n" );
1068  $this->db->query( "ALTER TABLE $table ALTER $field DROP DEFAULT", __METHOD__ );
1069  }
1070  }
1071 
1072  protected function changeNullableField( $table, $field, $null, $update = false ) {
1073  $fi = $this->db->fieldInfo( $table, $field );
1074  if ( $fi === null ) {
1075  return;
1076  }
1077  if ( $fi->isNullable() ) {
1078  # # It's NULL - does it need to be NOT NULL?
1079  if ( $null === 'NOT NULL' ) {
1080  $this->output( "Changing '$table.$field' to not allow NULLs\n" );
1081  if ( $update ) {
1082  $this->db->query( "UPDATE $table SET $field = DEFAULT WHERE $field IS NULL", __METHOD__ );
1083  }
1084  $this->db->query( "ALTER TABLE $table ALTER $field SET NOT NULL", __METHOD__ );
1085  } else {
1086  $this->output( "...column '$table.$field' is already set as NULL\n" );
1087  }
1088  } else {
1089  # # It's NOT NULL - does it need to be NULL?
1090  if ( $null === 'NULL' ) {
1091  $this->output( "Changing '$table.$field' to allow NULLs\n" );
1092  $this->db->query( "ALTER TABLE $table ALTER $field DROP NOT NULL", __METHOD__ );
1093  } else {
1094  $this->output( "...column '$table.$field' is already set as NOT NULL\n" );
1095  }
1096  }
1097  }
1098 
1099  protected function addPgIndex( $table, $index, $type, $unique = false ) {
1100  if ( $this->db->indexExists( $table, $index, __METHOD__ ) ) {
1101  $this->output( "...index '$index' on table '$table' already exists\n" );
1102  } else {
1103  $this->output( "Creating index '$index' on table '$table' $type\n" );
1104  $unique = $unique ? 'UNIQUE' : '';
1105  $this->db->query( "CREATE $unique INDEX $index ON $table $type", __METHOD__ );
1106  }
1107  }
1108 
1109  protected function addPgExtIndex( $table, $index, $type ) {
1110  if ( $this->db->indexExists( $table, $index, __METHOD__ ) ) {
1111  $this->output( "...index '$index' on table '$table' already exists\n" );
1112  } elseif ( preg_match( '/^\‍(/', $type ) ) {
1113  $this->output( "Creating index '$index' on table '$table'\n" );
1114  $this->db->query( "CREATE INDEX $index ON $table $type", __METHOD__ );
1115  } else {
1116  $this->applyPatch( $type, true, "Creating index '$index' on table '$table'" );
1117  }
1118  }
1119 
1126  protected function addPgEnumValue( $type, $value ) {
1127  $row = $this->db->selectRow(
1128  [
1129  't' => 'pg_catalog.pg_type',
1130  'n' => 'pg_catalog.pg_namespace',
1131  'e' => 'pg_catalog.pg_enum',
1132  ],
1133  [ 't.typname', 't.typtype', 'e.enumlabel' ],
1134  [
1135  't.typname' => $type,
1136  'n.nspname' => $this->db->getCoreSchema(),
1137  ],
1138  __METHOD__,
1139  [],
1140  [
1141  'n' => [ 'JOIN', 't.typnamespace = n.oid' ],
1142  'e' => [ 'LEFT JOIN', [ 'e.enumtypid = t.oid', 'e.enumlabel' => $value ] ],
1143  ]
1144  );
1145 
1146  if ( !$row ) {
1147  $this->output( "...Type $type does not exist, skipping modify enum.\n" );
1148  } elseif ( $row->typtype !== 'e' ) {
1149  $this->output( "...Type $type does not seem to be an enum, skipping modify enum.\n" );
1150  } elseif ( $row->enumlabel === $value ) {
1151  $this->output( "...Enum type $type already contains value '$value'.\n" );
1152  } else {
1153  $this->output( "...Adding value '$value' to enum type $type.\n" );
1154  $etype = $this->db->addIdentifierQuotes( $type );
1155  $evalue = $this->db->addQuotes( $value );
1156  $this->db->query( "ALTER TYPE $etype ADD VALUE $evalue", __METHOD__ );
1157  }
1158  }
1159 
1160  protected function dropFkey( $table, $field ) {
1161  $fi = $this->db->fieldInfo( $table, $field );
1162  if ( $fi === null ) {
1163  $this->output( "WARNING! Column '$table.$field' does not exist but it should! " .
1164  "Please report this.\n" );
1165  return;
1166  }
1167  $conname = $fi->conname();
1168  if ( $fi->conname() ) {
1169  $this->output( "Dropping foreign key constraint on '$table.$field'\n" );
1170  $conclause = "CONSTRAINT \"$conname\"";
1171  $command = "ALTER TABLE $table DROP CONSTRAINT $conname";
1172  $this->db->query( $command, __METHOD__ );
1173  } else {
1174  $this->output( "...foreign key constraint on '$table.$field' already does not exist\n" );
1175  }
1176  }
1177 
1178  protected function changeFkeyDeferrable( $table, $field, $clause ) {
1179  $fi = $this->db->fieldInfo( $table, $field );
1180  if ( $fi === null ) {
1181  $this->output( "WARNING! Column '$table.$field' does not exist but it should! " .
1182  "Please report this.\n" );
1183 
1184  return;
1185  }
1186  if ( $fi->is_deferred() && $fi->is_deferrable() ) {
1187  return;
1188  }
1189  $this->output( "Altering column '$table.$field' to be DEFERRABLE INITIALLY DEFERRED\n" );
1190  $conname = $fi->conname();
1191  if ( $fi->conname() ) {
1192  $conclause = "CONSTRAINT \"$conname\"";
1193  $command = "ALTER TABLE $table DROP CONSTRAINT $conname";
1194  $this->db->query( $command, __METHOD__ );
1195  } else {
1196  $this->output( "Column '$table.$field' does not have a foreign key " .
1197  "constraint, will be added\n" );
1198  $conclause = "";
1199  }
1200  $command =
1201  "ALTER TABLE $table ADD $conclause " .
1202  "FOREIGN KEY ($field) REFERENCES $clause DEFERRABLE INITIALLY DEFERRED";
1203  $this->db->query( $command, __METHOD__ );
1204  }
1205 
1206  protected function convertArchive2() {
1207  if ( $this->db->tableExists( "archive2", __METHOD__ ) ) {
1208  if ( $this->db->ruleExists( 'archive', 'archive_insert' ) ) {
1209  $this->output( "Dropping rule 'archive_insert'\n" );
1210  $this->db->query( 'DROP RULE archive_insert ON archive', __METHOD__ );
1211  }
1212  if ( $this->db->ruleExists( 'archive', 'archive_delete' ) ) {
1213  $this->output( "Dropping rule 'archive_delete'\n" );
1214  $this->db->query( 'DROP RULE archive_delete ON archive', __METHOD__ );
1215  }
1216  $this->applyPatch(
1217  'patch-remove-archive2.sql',
1218  false,
1219  "Converting 'archive2' back to normal archive table"
1220  );
1221  } else {
1222  $this->output( "...obsolete table 'archive2' does not exist\n" );
1223  }
1224  }
1225 
1226  protected function checkOiDeleted() {
1227  if ( $this->db->fieldInfo( 'oldimage', 'oi_deleted' )->type() !== 'smallint' ) {
1228  $this->output( "Changing 'oldimage.oi_deleted' to type 'smallint'\n" );
1229  $this->db->query( "ALTER TABLE oldimage ALTER oi_deleted DROP DEFAULT", __METHOD__ );
1230  $this->db->query(
1231  "ALTER TABLE oldimage ALTER oi_deleted TYPE SMALLINT USING (oi_deleted::smallint)", __METHOD__ );
1232  $this->db->query( "ALTER TABLE oldimage ALTER oi_deleted SET DEFAULT 0", __METHOD__ );
1233  } else {
1234  $this->output( "...column 'oldimage.oi_deleted' is already of type 'smallint'\n" );
1235  }
1236  }
1237 
1238  protected function checkOiNameConstraint() {
1239  if ( $this->db->hasConstraint( "oldimage_oi_name_fkey_cascaded" ) ) {
1240  $this->output( "...table 'oldimage' has correct cascading delete/update " .
1241  "foreign key to image\n" );
1242  } else {
1243  if ( $this->db->hasConstraint( "oldimage_oi_name_fkey" ) ) {
1244  $this->db->query(
1245  "ALTER TABLE oldimage DROP CONSTRAINT oldimage_oi_name_fkey", __METHOD__ );
1246  }
1247  if ( $this->db->hasConstraint( "oldimage_oi_name_fkey_cascade" ) ) {
1248  $this->db->query(
1249  "ALTER TABLE oldimage DROP CONSTRAINT oldimage_oi_name_fkey_cascade", __METHOD__ );
1250  }
1251  $this->output( "Making foreign key on table 'oldimage' (to image) a cascade delete/update\n" );
1252  $this->db->query(
1253  "ALTER TABLE oldimage ADD CONSTRAINT oldimage_oi_name_fkey_cascaded " .
1254  "FOREIGN KEY (oi_name) REFERENCES image(img_name) " .
1255  "ON DELETE CASCADE ON UPDATE CASCADE", __METHOD__ );
1256  }
1257  }
1258 
1259  protected function checkPageDeletedTrigger() {
1260  if ( !$this->db->triggerExists( 'page', 'page_deleted' ) ) {
1261  $this->applyPatch(
1262  'patch-page_deleted.sql',
1263  false,
1264  "Adding function and trigger 'page_deleted' to table 'page'"
1265  );
1266  } else {
1267  $this->output( "...table 'page' has 'page_deleted' trigger\n" );
1268  }
1269  }
1270 
1271  protected function dropPgIndex( $table, $index ) {
1272  if ( $this->db->indexExists( $table, $index, __METHOD__ ) ) {
1273  $this->output( "Dropping obsolete index '$index'\n" );
1274  $this->db->query( "DROP INDEX \"" . $index . "\"", __METHOD__ );
1275  }
1276  }
1277 
1278  protected function checkIndex( $index, $should_be, $good_def ) {
1279  $pu = $this->db->indexAttributes( $index );
1280  if ( !empty( $pu ) && $pu != $should_be ) {
1281  $this->output( "Dropping obsolete version of index '$index'\n" );
1282  $this->db->query( "DROP INDEX \"" . $index . "\"", __METHOD__ );
1283  $pu = [];
1284  } else {
1285  $this->output( "...no need to drop index '$index'\n" );
1286  }
1287 
1288  if ( empty( $pu ) ) {
1289  $this->output( "Creating index '$index'\n" );
1290  $this->db->query( $good_def, __METHOD__ );
1291  } else {
1292  $this->output( "...index '$index' exists\n" );
1293  }
1294  }
1295 
1296  protected function checkRevUserFkey() {
1297  if ( !$this->db->fieldExists( 'revision', 'rev_user', __METHOD__ ) ) {
1298  /* Do nothing */
1299  } elseif ( $this->fkeyDeltype( 'revision_rev_user_fkey' ) == 'r' ) {
1300  $this->output( "...constraint 'revision_rev_user_fkey' is ON DELETE RESTRICT\n" );
1301  } else {
1302  $this->applyPatch(
1303  'patch-revision_rev_user_fkey.sql',
1304  false,
1305  "Changing constraint 'revision_rev_user_fkey' to ON DELETE RESTRICT"
1306  );
1307  }
1308  }
1309 
1310  protected function checkIwlPrefix() {
1311  if ( $this->db->indexExists( 'iwlinks', 'iwl_prefix', __METHOD__ ) ) {
1312  $this->applyPatch(
1313  'patch-rename-iwl_prefix.sql',
1314  false,
1315  "Replacing index 'iwl_prefix' with 'iwl_prefix_title_from'"
1316  );
1317  }
1318  }
1319 
1320  protected function addInterwikiType() {
1321  $this->applyPatch( 'patch-add_interwiki.sql', false, "Refreshing add_interwiki()" );
1322  }
1323 
1324  protected function tsearchFixes() {
1325  # Tweak the page_title tsearch2 trigger to filter out slashes
1326  # This is create or replace, so harmless to call if not needed
1327  $this->applyPatch( 'patch-ts2pagetitle.sql', false, "Refreshing ts2_page_title()" );
1328 
1329  $this->applyPatch( 'patch-tsearch2funcs.sql', false, "Rewriting tsearch2 triggers" );
1330  }
1331 
1332  protected function rebuildTextSearch() {
1333  if ( $this->updateRowExists( 'patch-textsearch_bug66650.sql' ) ) {
1334  $this->output( "...T68650 already fixed or not applicable.\n" );
1335  return;
1336  }
1337  $this->applyPatch( 'patch-textsearch_bug66650.sql', false,
1338  'Rebuilding text search for T68650' );
1339  }
1340 }
DatabaseUpdater\output
output( $str)
Output some text.
Definition: DatabaseUpdater.php:224
PostgresUpdater\rebuildTextSearch
rebuildTextSearch()
Definition: PostgresUpdater.php:1332
PostgresUpdater\renameIndex
renameIndex( $table, $old, $new, $skipBothIndexExistWarning=false, $a=false, $b=false)
Rename an index from an existing table Stable to override.
Definition: PostgresUpdater.php:936
PostgresUpdater\checkOiNameConstraint
checkOiNameConstraint()
Definition: PostgresUpdater.php:1238
PostgresUpdater\changeNullableField
changeNullableField( $table, $field, $null, $update=false)
Definition: PostgresUpdater.php:1072
PostgresUpdater\getCoreUpdateList
getCoreUpdateList()
Definition: PostgresUpdater.php:44
PostgresUpdater\setDefault
setDefault( $table, $field, $default)
Definition: PostgresUpdater.php:1049
PostgresUpdater\addPgEnumValue
addPgEnumValue( $type, $value)
Add a value to an existing PostgreSQL enum type.
Definition: PostgresUpdater.php:1126
DatabaseUpdater\applyPatch
applyPatch( $path, $isFullPath=false, $msg=null)
Applies a SQL patch.
Definition: DatabaseUpdater.php:709
DatabaseUpdater
Class for handling database updates.
Definition: DatabaseUpdater.php:37
PostgresUpdater\convertArchive2
convertArchive2()
Definition: PostgresUpdater.php:1206
true
return true
Definition: router.php:90
PostgresUpdater\dropFkey
dropFkey( $table, $field)
Definition: PostgresUpdater.php:1160
PostgresUpdater\checkPageDeletedTrigger
checkPageDeletedTrigger()
Definition: PostgresUpdater.php:1259
PostgresUpdater\describeIndex
describeIndex( $idx)
Definition: PostgresUpdater.php:786
PostgresUpdater\$db
DatabasePostgres $db
Definition: PostgresUpdater.php:37
PostgresUpdater\renameTable
renameTable( $old, $new, $patch=false)
Definition: PostgresUpdater.php:924
PostgresUpdater\fkeyDeltype
fkeyDeltype( $fkey)
Definition: PostgresUpdater.php:838
Wikimedia\Rdbms\DatabasePostgres
Definition: DatabasePostgres.php:33
PostgresUpdater\checkIwlPrefix
checkIwlPrefix()
Definition: PostgresUpdater.php:1310
$res
$res
Definition: testCompression.php:57
PostgresUpdater\changeField
changeField( $table, $field, $newtype, $default)
Definition: PostgresUpdater.php:995
DatabaseUpdater\$updates
array $updates
Array of updates to perform on the database.
Definition: DatabaseUpdater.php:45
PostgresUpdater\changeFieldPurgeTable
changeFieldPurgeTable( $table, $field, $newtype, $default)
Definition: PostgresUpdater.php:1020
PostgresUpdater\addPgExtIndex
addPgExtIndex( $table, $index, $type)
Definition: PostgresUpdater.php:1109
PostgresUpdater\describeTable
describeTable( $table)
Definition: PostgresUpdater.php:757
PostgresUpdater\ruleDef
ruleDef( $table, $rule)
Definition: PostgresUpdater.php:861
PostgresUpdater\addPgIndex
addPgIndex( $table, $index, $type, $unique=false)
Definition: PostgresUpdater.php:1099
PostgresUpdater\checkRevUserFkey
checkRevUserFkey()
Definition: PostgresUpdater.php:1296
DatabaseUpdater\updateRowExists
updateRowExists( $key)
Helper function: check if the given key is present in the updatelog table.
Definition: DatabaseUpdater.php:532
PostgresUpdater
Class for handling updates to Postgres databases.
Definition: PostgresUpdater.php:32
PostgresUpdater\checkIndex
checkIndex( $index, $should_be, $good_def)
Definition: PostgresUpdater.php:1278
PostgresUpdater\changeFkeyDeferrable
changeFkeyDeferrable( $table, $field, $clause)
Definition: PostgresUpdater.php:1178
PostgresUpdater\renameSequence
renameSequence( $old, $new)
Definition: PostgresUpdater.php:905
PostgresUpdater\dropDefault
dropDefault( $table, $field)
Drop a default value from a field.
Definition: PostgresUpdater.php:1064
PostgresUpdater\setSequenceOwner
setSequenceOwner( $table, $pkey, $seq)
Definition: PostgresUpdater.php:917
$command
$command
Definition: mcc.php:125
PostgresUpdater\addInterwikiType
addInterwikiType()
Definition: PostgresUpdater.php:1320
PostgresUpdater\dropSequence
dropSequence( $table, $ns)
Definition: PostgresUpdater.php:898
PostgresUpdater\addSequence
addSequence( $table, $pkey, $ns)
Definition: PostgresUpdater.php:886
PostgresUpdater\tsearchFixes
tsearchFixes()
Definition: PostgresUpdater.php:1324
PostgresUpdater\addPgField
addPgField( $table, $field, $type)
Definition: PostgresUpdater.php:983
PostgresUpdater\dropPgField
dropPgField( $table, $field)
Definition: PostgresUpdater.php:971
PostgresUpdater\checkOiDeleted
checkOiDeleted()
Definition: PostgresUpdater.php:1226
PostgresUpdater\getOldGlobalUpdates
getOldGlobalUpdates()
Before 1.17, we used to handle updates via stuff like $wgExtNewTables/Fields/Indexes.
Definition: PostgresUpdater.php:718
PostgresUpdater\dropPgIndex
dropPgIndex( $table, $index)
Definition: PostgresUpdater.php:1271
$type
$type
Definition: testCompression.php:52