MediaWiki  1.29.2
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  [ 'addSequence', 'tag_summary', false, 'tag_summary_ts_id_seq' ],
75 
76  # new tables
77  [ 'addTable', 'category', 'patch-category.sql' ],
78  [ 'addTable', 'page', 'patch-page.sql' ],
79  [ 'addTable', 'querycachetwo', 'patch-querycachetwo.sql' ],
80  [ 'addTable', 'page_props', 'patch-page_props.sql' ],
81  [ 'addTable', 'page_restrictions', 'patch-page_restrictions.sql' ],
82  [ 'addTable', 'profiling', 'patch-profiling.sql' ],
83  [ 'addTable', 'protected_titles', 'patch-protected_titles.sql' ],
84  [ 'addTable', 'redirect', 'patch-redirect.sql' ],
85  [ 'addTable', 'updatelog', 'patch-updatelog.sql' ],
86  [ 'addTable', 'change_tag', 'patch-change_tag.sql' ],
87  [ 'addTable', 'tag_summary', 'patch-tag_summary.sql' ],
88  [ 'addTable', 'valid_tag', 'patch-valid_tag.sql' ],
89  [ 'addTable', 'user_properties', 'patch-user_properties.sql' ],
90  [ 'addTable', 'log_search', 'patch-log_search.sql' ],
91  [ 'addTable', 'l10n_cache', 'patch-l10n_cache.sql' ],
92  [ 'addTable', 'iwlinks', 'patch-iwlinks.sql' ],
93  [ 'addTable', 'module_deps', 'patch-module_deps.sql' ],
94  [ 'addTable', 'uploadstash', 'patch-uploadstash.sql' ],
95  [ 'addTable', 'user_former_groups', 'patch-user_former_groups.sql' ],
96  [ 'addTable', 'sites', 'patch-sites.sql' ],
97  [ 'addTable', 'bot_passwords', 'patch-bot_passwords.sql' ],
98 
99  # Needed before new field
100  [ 'convertArchive2' ],
101 
102  # new fields
103  [ 'addPgField', 'updatelog', 'ul_value', 'TEXT' ],
104  [ 'addPgField', 'archive', 'ar_deleted', 'SMALLINT NOT NULL DEFAULT 0' ],
105  [ 'addPgField', 'archive', 'ar_len', 'INTEGER' ],
106  [ 'addPgField', 'archive', 'ar_page_id', 'INTEGER' ],
107  [ 'addPgField', 'archive', 'ar_parent_id', 'INTEGER' ],
108  [ 'addPgField', 'archive', 'ar_content_model', 'TEXT' ],
109  [ 'addPgField', 'archive', 'ar_content_format', 'TEXT' ],
110  [ 'addPgField', 'categorylinks', 'cl_sortkey_prefix', "TEXT NOT NULL DEFAULT ''" ],
111  [ 'addPgField', 'categorylinks', 'cl_collation', "TEXT NOT NULL DEFAULT 0" ],
112  [ 'addPgField', 'categorylinks', 'cl_type', "TEXT NOT NULL DEFAULT 'page'" ],
113  [ 'addPgField', 'image', 'img_sha1', "TEXT NOT NULL DEFAULT ''" ],
114  [ 'addPgField', 'ipblocks', 'ipb_allow_usertalk', 'SMALLINT NOT NULL DEFAULT 0' ],
115  [ 'addPgField', 'ipblocks', 'ipb_anon_only', 'SMALLINT NOT NULL DEFAULT 0' ],
116  [ 'addPgField', 'ipblocks', 'ipb_by_text', "TEXT NOT NULL DEFAULT ''" ],
117  [ 'addPgField', 'ipblocks', 'ipb_block_email', 'SMALLINT NOT NULL DEFAULT 0' ],
118  [ 'addPgField', 'ipblocks', 'ipb_create_account', 'SMALLINT NOT NULL DEFAULT 1' ],
119  [ 'addPgField', 'ipblocks', 'ipb_deleted', 'SMALLINT NOT NULL DEFAULT 0' ],
120  [ 'addPgField', 'ipblocks', 'ipb_enable_autoblock', 'SMALLINT NOT NULL DEFAULT 1' ],
121  [ 'addPgField', 'ipblocks', 'ipb_parent_block_id',
122  'INTEGER DEFAULT NULL REFERENCES ipblocks(ipb_id) ' .
123  'ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED' ],
124  [ 'addPgField', 'filearchive', 'fa_deleted', 'SMALLINT NOT NULL DEFAULT 0' ],
125  [ 'addPgField', 'filearchive', 'fa_sha1', "TEXT NOT NULL DEFAULT ''" ],
126  [ 'addPgField', 'logging', 'log_deleted', 'SMALLINT NOT NULL DEFAULT 0' ],
127  [ 'addPgField', 'logging', 'log_id',
128  "INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('logging_log_id_seq')" ],
129  [ 'addPgField', 'logging', 'log_params', 'TEXT' ],
130  [ 'addPgField', 'mwuser', 'user_editcount', 'INTEGER' ],
131  [ 'addPgField', 'mwuser', 'user_newpass_time', 'TIMESTAMPTZ' ],
132  [ 'addPgField', 'oldimage', 'oi_deleted', 'SMALLINT NOT NULL DEFAULT 0' ],
133  [ 'addPgField', 'oldimage', 'oi_major_mime', "TEXT NOT NULL DEFAULT 'unknown'" ],
134  [ 'addPgField', 'oldimage', 'oi_media_type', 'TEXT' ],
135  [ 'addPgField', 'oldimage', 'oi_metadata', "BYTEA NOT NULL DEFAULT ''" ],
136  [ 'addPgField', 'oldimage', 'oi_minor_mime', "TEXT NOT NULL DEFAULT 'unknown'" ],
137  [ 'addPgField', 'oldimage', 'oi_sha1', "TEXT NOT NULL DEFAULT ''" ],
138  [ 'addPgField', 'page', 'page_content_model', 'TEXT' ],
139  [ 'addPgField', 'page_restrictions', 'pr_id',
140  "INTEGER NOT NULL UNIQUE DEFAULT nextval('page_restrictions_pr_id_seq')" ],
141  [ 'addPgField', 'profiling', 'pf_memory', 'NUMERIC(18,10) NOT NULL DEFAULT 0' ],
142  [ 'addPgField', 'recentchanges', 'rc_deleted', 'SMALLINT NOT NULL DEFAULT 0' ],
143  [ 'addPgField', 'recentchanges', 'rc_log_action', 'TEXT' ],
144  [ 'addPgField', 'recentchanges', 'rc_log_type', 'TEXT' ],
145  [ 'addPgField', 'recentchanges', 'rc_logid', 'INTEGER NOT NULL DEFAULT 0' ],
146  [ 'addPgField', 'recentchanges', 'rc_new_len', 'INTEGER' ],
147  [ 'addPgField', 'recentchanges', 'rc_old_len', 'INTEGER' ],
148  [ 'addPgField', 'recentchanges', 'rc_params', 'TEXT' ],
149  [ 'addPgField', 'redirect', 'rd_interwiki', 'TEXT NULL' ],
150  [ 'addPgField', 'redirect', 'rd_fragment', 'TEXT NULL' ],
151  [ 'addPgField', 'revision', 'rev_deleted', 'SMALLINT NOT NULL DEFAULT 0' ],
152  [ 'addPgField', 'revision', 'rev_len', 'INTEGER' ],
153  [ 'addPgField', 'revision', 'rev_parent_id', 'INTEGER DEFAULT NULL' ],
154  [ 'addPgField', 'revision', 'rev_content_model', 'TEXT' ],
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  [ 'addPgField', 'logging', 'log_user_text', "TEXT NOT NULL DEFAULT ''" ],
159  [ 'addPgField', 'logging', 'log_page', 'INTEGER' ],
160  [ 'addPgField', 'interwiki', 'iw_api', "TEXT NOT NULL DEFAULT ''" ],
161  [ 'addPgField', 'interwiki', 'iw_wikiid', "TEXT NOT NULL DEFAULT ''" ],
162  [ 'addPgField', 'revision', 'rev_sha1', "TEXT NOT NULL DEFAULT ''" ],
163  [ 'addPgField', 'archive', 'ar_sha1', "TEXT NOT NULL DEFAULT ''" ],
164  [ 'addPgField', 'uploadstash', 'us_chunk_inx', "INTEGER NULL" ],
165  [ 'addPgField', 'job', 'job_timestamp', "TIMESTAMPTZ" ],
166  [ 'addPgField', 'job', 'job_random', "INTEGER NOT NULL DEFAULT 0" ],
167  [ 'addPgField', 'job', 'job_attempts', "INTEGER NOT NULL DEFAULT 0" ],
168  [ 'addPgField', 'job', 'job_token', "TEXT NOT NULL DEFAULT ''" ],
169  [ 'addPgField', 'job', 'job_token_timestamp', "TIMESTAMPTZ" ],
170  [ 'addPgField', 'job', 'job_sha1', "TEXT NOT NULL DEFAULT ''" ],
171  [ 'addPgField', 'archive', 'ar_id',
172  "INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('archive_ar_id_seq')" ],
173  [ 'addPgField', 'externallinks', 'el_id',
174  "INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('externallinks_el_id_seq')" ],
175  [ 'addPgField', 'uploadstash', 'us_props', "BYTEA" ],
176 
177  # type changes
178  [ 'changeField', 'archive', 'ar_deleted', 'smallint', '' ],
179  [ 'changeField', 'archive', 'ar_minor_edit', 'smallint',
180  'ar_minor_edit::smallint DEFAULT 0' ],
181  [ 'changeField', 'filearchive', 'fa_deleted', 'smallint', '' ],
182  [ 'changeField', 'filearchive', 'fa_height', 'integer', '' ],
183  [ 'changeField', 'filearchive', 'fa_metadata', 'bytea', "decode(fa_metadata,'escape')" ],
184  [ 'changeField', 'filearchive', 'fa_size', 'integer', '' ],
185  [ 'changeField', 'filearchive', 'fa_width', 'integer', '' ],
186  [ 'changeField', 'filearchive', 'fa_storage_group', 'text', '' ],
187  [ 'changeField', 'filearchive', 'fa_storage_key', 'text', '' ],
188  [ 'changeField', 'image', 'img_metadata', 'bytea', "decode(img_metadata,'escape')" ],
189  [ 'changeField', 'image', 'img_size', 'integer', '' ],
190  [ 'changeField', 'image', 'img_width', 'integer', '' ],
191  [ 'changeField', 'image', 'img_height', 'integer', '' ],
192  [ 'changeField', 'interwiki', 'iw_local', 'smallint', 'iw_local::smallint' ],
193  [ 'changeField', 'interwiki', 'iw_trans', 'smallint', 'iw_trans::smallint DEFAULT 0' ],
194  [ 'changeField', 'ipblocks', 'ipb_auto', 'smallint', 'ipb_auto::smallint DEFAULT 0' ],
195  [ 'changeField', 'ipblocks', 'ipb_anon_only', 'smallint',
196  "CASE WHEN ipb_anon_only=' ' THEN 0 ELSE ipb_anon_only::smallint END DEFAULT 0" ],
197  [ 'changeField', 'ipblocks', 'ipb_create_account', 'smallint',
198  "CASE WHEN ipb_create_account=' ' THEN 0 ELSE ipb_create_account::smallint END DEFAULT 1" ],
199  [ 'changeField', 'ipblocks', 'ipb_enable_autoblock', 'smallint',
200  "CASE WHEN ipb_enable_autoblock=' ' THEN 0 ELSE ipb_enable_autoblock::smallint END DEFAULT 1" ],
201  [ 'changeField', 'ipblocks', 'ipb_block_email', 'smallint',
202  "CASE WHEN ipb_block_email=' ' THEN 0 ELSE ipb_block_email::smallint END DEFAULT 0" ],
203  [ 'changeField', 'ipblocks', 'ipb_address', 'text', 'ipb_address::text' ],
204  [ 'changeField', 'ipblocks', 'ipb_deleted', 'smallint', 'ipb_deleted::smallint DEFAULT 0' ],
205  [ 'changeField', 'mwuser', 'user_token', 'text', '' ],
206  [ 'changeField', 'mwuser', 'user_email_token', 'text', '' ],
207  [ 'changeField', 'objectcache', 'keyname', 'text', '' ],
208  [ 'changeField', 'oldimage', 'oi_height', 'integer', '' ],
209  [ 'changeField', 'oldimage', 'oi_metadata', 'bytea', "decode(img_metadata,'escape')" ],
210  [ 'changeField', 'oldimage', 'oi_size', 'integer', '' ],
211  [ 'changeField', 'oldimage', 'oi_width', 'integer', '' ],
212  [ 'changeField', 'page', 'page_is_redirect', 'smallint',
213  'page_is_redirect::smallint DEFAULT 0' ],
214  [ 'changeField', 'page', 'page_is_new', 'smallint', 'page_is_new::smallint DEFAULT 0' ],
215  [ 'changeField', 'querycache', 'qc_value', 'integer', '' ],
216  [ 'changeField', 'querycachetwo', 'qcc_value', 'integer', '' ],
217  [ 'changeField', 'recentchanges', 'rc_bot', 'smallint', 'rc_bot::smallint DEFAULT 0' ],
218  [ 'changeField', 'recentchanges', 'rc_deleted', 'smallint', '' ],
219  [ 'changeField', 'recentchanges', 'rc_minor', 'smallint', 'rc_minor::smallint DEFAULT 0' ],
220  [ 'changeField', 'recentchanges', 'rc_new', 'smallint', 'rc_new::smallint DEFAULT 0' ],
221  [ 'changeField', 'recentchanges', 'rc_type', 'smallint', 'rc_type::smallint DEFAULT 0' ],
222  [ 'changeField', 'recentchanges', 'rc_patrolled', 'smallint',
223  'rc_patrolled::smallint DEFAULT 0' ],
224  [ 'changeField', 'revision', 'rev_deleted', 'smallint', 'rev_deleted::smallint DEFAULT 0' ],
225  [ 'changeField', 'revision', 'rev_minor_edit', 'smallint',
226  'rev_minor_edit::smallint DEFAULT 0' ],
227  [ 'changeField', 'templatelinks', 'tl_namespace', 'smallint', 'tl_namespace::smallint' ],
228  [ 'changeField', 'user_newtalk', 'user_ip', 'text', 'host(user_ip)' ],
229  [ 'changeField', 'uploadstash', 'us_image_bits', 'smallint', '' ],
230  [ 'changeField', 'profiling', 'pf_time', 'float', '' ],
231  [ 'changeField', 'profiling', 'pf_memory', 'float', '' ],
232 
233  # null changes
234  [ 'changeNullableField', 'oldimage', 'oi_bits', 'NULL' ],
235  [ 'changeNullableField', 'oldimage', 'oi_timestamp', 'NULL' ],
236  [ 'changeNullableField', 'oldimage', 'oi_major_mime', 'NULL' ],
237  [ 'changeNullableField', 'oldimage', 'oi_minor_mime', 'NULL' ],
238  [ 'changeNullableField', 'image', 'img_metadata', 'NOT NULL' ],
239  [ 'changeNullableField', 'filearchive', 'fa_metadata', 'NOT NULL' ],
240  [ 'changeNullableField', 'recentchanges', 'rc_cur_id', 'NULL' ],
241  [ 'changeNullableField', 'recentchanges', 'rc_cur_time', 'NULL' ],
242 
243  [ 'checkOiDeleted' ],
244 
245  # New indexes
246  [ 'addPgIndex', 'archive', 'archive_user_text', '(ar_user_text)' ],
247  [ 'addPgIndex', 'image', 'img_sha1', '(img_sha1)' ],
248  [ 'addPgIndex', 'ipblocks', 'ipb_parent_block_id', '(ipb_parent_block_id)' ],
249  [ 'addPgIndex', 'oldimage', 'oi_sha1', '(oi_sha1)' ],
250  [ 'addPgIndex', 'page', 'page_mediawiki_title', '(page_title) WHERE page_namespace = 8' ],
251  [ 'addPgIndex', 'pagelinks', 'pagelinks_title', '(pl_title)' ],
252  [ 'addPgIndex', 'page_props', 'pp_propname_page', '(pp_propname, pp_page)' ],
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  [ '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  [ 'addPgIndex', 'logging', 'logging_user_text_type_time',
270  '(log_user_text, log_type, log_timestamp)' ],
271  [ 'addPgIndex', 'logging', 'logging_user_text_time', '(log_user_text, log_timestamp)' ],
272 
273  [ 'checkIndex', 'pagelink_unique', [
274  [ 'pl_from', 'int4_ops', 'btree', 0 ],
275  [ 'pl_namespace', 'int2_ops', 'btree', 0 ],
276  [ 'pl_title', 'text_ops', 'btree', 0 ],
277  ],
278  'CREATE UNIQUE INDEX pagelink_unique ON pagelinks (pl_from,pl_namespace,pl_title)' ],
279  [ 'checkIndex', 'cl_sortkey', [
280  [ 'cl_to', 'text_ops', 'btree', 0 ],
281  [ 'cl_sortkey', 'text_ops', 'btree', 0 ],
282  [ 'cl_from', 'int4_ops', 'btree', 0 ],
283  ],
284  'CREATE INDEX cl_sortkey ON "categorylinks" ' .
285  'USING "btree" ("cl_to", "cl_sortkey", "cl_from")' ],
286  [ 'checkIndex', 'iwl_prefix_title_from', [
287  [ 'iwl_prefix', 'text_ops', 'btree', 0 ],
288  [ 'iwl_title', 'text_ops', 'btree', 0 ],
289  [ 'iwl_from', 'int4_ops', 'btree', 0 ],
290  ],
291  'CREATE INDEX iwl_prefix_title_from ON "iwlinks" ' .
292  'USING "btree" ("iwl_prefix", "iwl_title", "iwl_from")' ],
293  [ 'checkIndex', 'logging_times', [
294  [ 'log_timestamp', 'timestamptz_ops', 'btree', 0 ],
295  ],
296  'CREATE INDEX "logging_times" ON "logging" USING "btree" ("log_timestamp")' ],
297  [ 'dropIndex', 'oldimage', 'oi_name' ],
298  [ 'checkIndex', 'oi_name_archive_name', [
299  [ 'oi_name', 'text_ops', 'btree', 0 ],
300  [ 'oi_archive_name', 'text_ops', 'btree', 0 ],
301  ],
302  'CREATE INDEX "oi_name_archive_name" ON "oldimage" ' .
303  'USING "btree" ("oi_name", "oi_archive_name")' ],
304  [ 'checkIndex', 'oi_name_timestamp', [
305  [ 'oi_name', 'text_ops', 'btree', 0 ],
306  [ 'oi_timestamp', 'timestamptz_ops', 'btree', 0 ],
307  ],
308  'CREATE INDEX "oi_name_timestamp" ON "oldimage" ' .
309  'USING "btree" ("oi_name", "oi_timestamp")' ],
310  [ 'checkIndex', 'page_main_title', [
311  [ 'page_title', 'text_pattern_ops', 'btree', 0 ],
312  ],
313  'CREATE INDEX "page_main_title" ON "page" ' .
314  'USING "btree" ("page_title" "text_pattern_ops") WHERE ("page_namespace" = 0)' ],
315  [ 'checkIndex', 'page_mediawiki_title', [
316  [ 'page_title', 'text_pattern_ops', 'btree', 0 ],
317  ],
318  'CREATE INDEX "page_mediawiki_title" ON "page" ' .
319  'USING "btree" ("page_title" "text_pattern_ops") WHERE ("page_namespace" = 8)' ],
320  [ 'checkIndex', 'page_project_title', [
321  [ 'page_title', 'text_pattern_ops', 'btree', 0 ],
322  ],
323  'CREATE INDEX "page_project_title" ON "page" ' .
324  'USING "btree" ("page_title" "text_pattern_ops") ' .
325  'WHERE ("page_namespace" = 4)' ],
326  [ 'checkIndex', 'page_talk_title', [
327  [ 'page_title', 'text_pattern_ops', 'btree', 0 ],
328  ],
329  'CREATE INDEX "page_talk_title" ON "page" ' .
330  'USING "btree" ("page_title" "text_pattern_ops") ' .
331  'WHERE ("page_namespace" = 1)' ],
332  [ 'checkIndex', 'page_user_title', [
333  [ 'page_title', 'text_pattern_ops', 'btree', 0 ],
334  ],
335  'CREATE INDEX "page_user_title" ON "page" ' .
336  'USING "btree" ("page_title" "text_pattern_ops") WHERE ' .
337  '("page_namespace" = 2)' ],
338  [ 'checkIndex', 'page_utalk_title', [
339  [ 'page_title', 'text_pattern_ops', 'btree', 0 ],
340  ],
341  'CREATE INDEX "page_utalk_title" ON "page" ' .
342  'USING "btree" ("page_title" "text_pattern_ops") ' .
343  'WHERE ("page_namespace" = 3)' ],
344  [ 'checkIndex', 'ts2_page_text', [
345  [ 'textvector', 'tsvector_ops', 'gist', 0 ],
346  ],
347  'CREATE INDEX "ts2_page_text" ON "pagecontent" USING "gist" ("textvector")' ],
348  [ 'checkIndex', 'ts2_page_title', [
349  [ 'titlevector', 'tsvector_ops', 'gist', 0 ],
350  ],
351  'CREATE INDEX "ts2_page_title" ON "page" USING "gist" ("titlevector")' ],
352 
353  [ 'checkOiNameConstraint' ],
354  [ 'checkPageDeletedTrigger' ],
355  [ 'checkRevUserFkey' ],
356  [ 'dropIndex', 'ipblocks', 'ipb_address' ],
357  [ 'checkIndex', 'ipb_address_unique', [
358  [ 'ipb_address', 'text_ops', 'btree', 0 ],
359  [ 'ipb_user', 'int4_ops', 'btree', 0 ],
360  [ 'ipb_auto', 'int2_ops', 'btree', 0 ],
361  [ 'ipb_anon_only', 'int2_ops', 'btree', 0 ],
362  ],
363  'CREATE UNIQUE INDEX ipb_address_unique ' .
364  'ON ipblocks (ipb_address,ipb_user,ipb_auto,ipb_anon_only)' ],
365 
366  [ 'checkIwlPrefix' ],
367 
368  # All FK columns should be deferred
369  [ 'changeFkeyDeferrable', 'archive', 'ar_user', 'mwuser(user_id) ON DELETE SET NULL' ],
370  [ 'changeFkeyDeferrable', 'categorylinks', 'cl_from', 'page(page_id) ON DELETE CASCADE' ],
371  [ 'changeFkeyDeferrable', 'externallinks', 'el_from', 'page(page_id) ON DELETE CASCADE' ],
372  [ 'changeFkeyDeferrable', 'filearchive', 'fa_deleted_user',
373  'mwuser(user_id) ON DELETE SET NULL' ],
374  [ 'changeFkeyDeferrable', 'filearchive', 'fa_user', 'mwuser(user_id) ON DELETE SET NULL' ],
375  [ 'changeFkeyDeferrable', 'image', 'img_user', 'mwuser(user_id) ON DELETE SET NULL' ],
376  [ 'changeFkeyDeferrable', 'imagelinks', 'il_from', 'page(page_id) ON DELETE CASCADE' ],
377  [ 'changeFkeyDeferrable', 'ipblocks', 'ipb_by', 'mwuser(user_id) ON DELETE CASCADE' ],
378  [ 'changeFkeyDeferrable', 'ipblocks', 'ipb_user', 'mwuser(user_id) ON DELETE SET NULL' ],
379  [ 'changeFkeyDeferrable', 'ipblocks', 'ipb_parent_block_id',
380  'ipblocks(ipb_id) ON DELETE SET NULL' ],
381  [ 'changeFkeyDeferrable', 'langlinks', 'll_from', 'page(page_id) ON DELETE CASCADE' ],
382  [ 'changeFkeyDeferrable', 'logging', 'log_user', 'mwuser(user_id) ON DELETE SET NULL' ],
383  [ 'changeFkeyDeferrable', 'oldimage', 'oi_name',
384  'image(img_name) ON DELETE CASCADE ON UPDATE CASCADE' ],
385  [ 'changeFkeyDeferrable', 'oldimage', 'oi_user', 'mwuser(user_id) ON DELETE SET NULL' ],
386  [ 'changeFkeyDeferrable', 'pagelinks', 'pl_from', 'page(page_id) ON DELETE CASCADE' ],
387  [ 'changeFkeyDeferrable', 'page_props', 'pp_page', 'page (page_id) ON DELETE CASCADE' ],
388  [ 'changeFkeyDeferrable', 'page_restrictions', 'pr_page',
389  'page(page_id) ON DELETE CASCADE' ],
390  [ 'changeFkeyDeferrable', 'protected_titles', 'pt_user',
391  'mwuser(user_id) ON DELETE SET NULL' ],
392  [ 'changeFkeyDeferrable', 'recentchanges', 'rc_user',
393  'mwuser(user_id) ON DELETE SET NULL' ],
394  [ 'changeFkeyDeferrable', 'redirect', 'rd_from', 'page(page_id) ON DELETE CASCADE' ],
395  [ 'changeFkeyDeferrable', 'revision', 'rev_page', 'page (page_id) ON DELETE CASCADE' ],
396  [ 'changeFkeyDeferrable', 'revision', 'rev_user', 'mwuser(user_id) ON DELETE RESTRICT' ],
397  [ 'changeFkeyDeferrable', 'templatelinks', 'tl_from', 'page(page_id) ON DELETE CASCADE' ],
398  [ 'changeFkeyDeferrable', 'user_groups', 'ug_user', 'mwuser(user_id) ON DELETE CASCADE' ],
399  [ 'changeFkeyDeferrable', 'user_newtalk', 'user_id', 'mwuser(user_id) ON DELETE CASCADE' ],
400  [ 'changeFkeyDeferrable', 'user_properties', 'up_user',
401  'mwuser(user_id) ON DELETE CASCADE' ],
402  [ 'changeFkeyDeferrable', 'watchlist', 'wl_user', 'mwuser(user_id) ON DELETE CASCADE' ],
403 
404  # r81574
405  [ 'addInterwikiType' ],
406  # end
407  [ 'tsearchFixes' ],
408 
409  // 1.23
410  [ 'addPgField', 'recentchanges', 'rc_source', "TEXT NOT NULL DEFAULT ''" ],
411  [ 'addPgField', 'page', 'page_links_updated', "TIMESTAMPTZ NULL" ],
412  [ 'addPgField', 'mwuser', 'user_password_expires', 'TIMESTAMPTZ NULL' ],
413  [ 'changeFieldPurgeTable', 'l10n_cache', 'lc_value', 'bytea',
414  "replace(lc_value,'\','\\\\')::bytea" ],
415  // 1.23.9
416  [ 'rebuildTextSearch' ],
417 
418  // 1.24
419  [ 'addPgField', 'page_props', 'pp_sortkey', 'float NULL' ],
420  [ 'addPgIndex', 'page_props', 'pp_propname_sortkey_page',
421  '( pp_propname, pp_sortkey, pp_page ) WHERE ( pp_sortkey IS NOT NULL )' ],
422  [ 'addPgField', 'page', 'page_lang', 'TEXT default NULL' ],
423  [ 'addPgField', 'pagelinks', 'pl_from_namespace', 'INTEGER NOT NULL DEFAULT 0' ],
424  [ 'addPgField', 'templatelinks', 'tl_from_namespace', 'INTEGER NOT NULL DEFAULT 0' ],
425  [ 'addPgField', 'imagelinks', 'il_from_namespace', 'INTEGER NOT NULL DEFAULT 0' ],
426 
427  // 1.25
428  [ 'dropTable', 'hitcounter' ],
429  [ 'dropField', 'site_stats', 'ss_total_views', 'patch-drop-ss_total_views.sql' ],
430  [ 'dropField', 'page', 'page_counter', 'patch-drop-page_counter.sql' ],
431  [ 'dropFkey', 'recentchanges', 'rc_cur_id' ],
432 
433  // 1.27
434  [ 'dropTable', 'msg_resource_links' ],
435  [ 'dropTable', 'msg_resource' ],
436  [
437  'addPgField', 'watchlist', 'wl_id',
438  "INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('watchlist_wl_id_seq')"
439  ],
440 
441  // 1.28
442  [ 'addPgIndex', 'recentchanges', 'rc_name_type_patrolled_timestamp',
443  '( rc_namespace, rc_type, rc_patrolled, rc_timestamp )' ],
444  [ 'addPgField', 'change_tag', 'ct_id',
445  "INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('change_tag_ct_id_seq')" ],
446  [ 'addPgField', 'tag_summary', 'ts_id',
447  "INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('tag_summary_ts_id_seq')" ],
448 
449  // 1.29
450  [ 'addPgField', 'externallinks', 'el_index_60', "BYTEA NOT NULL DEFAULT ''" ],
451  [ 'addPgIndex', 'externallinks', 'el_index_60', '( el_index_60, el_id )' ],
452  [ 'addPgIndex', 'externallinks', 'el_from_index_60', '( el_from, el_index_60, el_id )' ],
453  [ 'addPgField', 'user_groups', 'ug_expiry', "TIMESTAMPTZ NULL" ],
454  [ 'addPgIndex', 'user_groups', 'user_groups_expiry', '( ug_expiry )' ],
455  ];
456  }
457 
458  protected function getOldGlobalUpdates() {
459  global $wgExtNewTables, $wgExtPGNewFields, $wgExtPGAlteredFields, $wgExtNewIndexes;
460 
461  $updates = [];
462 
463  # Add missing extension tables
464  foreach ( $wgExtNewTables as $tableRecord ) {
465  $updates[] = [
466  'addTable', $tableRecord[0], $tableRecord[1], true
467  ];
468  }
469 
470  # Add missing extension fields
471  foreach ( $wgExtPGNewFields as $fieldRecord ) {
472  $updates[] = [
473  'addPgField', $fieldRecord[0], $fieldRecord[1],
474  $fieldRecord[2]
475  ];
476  }
477 
478  # Change altered columns
479  foreach ( $wgExtPGAlteredFields as $fieldRecord ) {
480  $updates[] = [
481  'changeField', $fieldRecord[0], $fieldRecord[1],
482  $fieldRecord[2]
483  ];
484  }
485 
486  # Add missing extension indexes
487  foreach ( $wgExtNewIndexes as $fieldRecord ) {
488  $updates[] = [
489  'addPgExtIndex', $fieldRecord[0], $fieldRecord[1],
490  $fieldRecord[2]
491  ];
492  }
493 
494  return $updates;
495  }
496 
497  protected function describeTable( $table ) {
498  $q = <<<END
499 SELECT attname, attnum FROM pg_namespace, pg_class, pg_attribute
500  WHERE pg_class.relnamespace = pg_namespace.oid
501  AND attrelid=pg_class.oid AND attnum > 0
502  AND relname=%s AND nspname=%s
503 END;
504  $res = $this->db->query( sprintf( $q,
505  $this->db->addQuotes( $table ),
506  $this->db->addQuotes( $this->db->getCoreSchema() ) ) );
507  if ( !$res ) {
508  return null;
509  }
510 
511  $cols = [];
512  foreach ( $res as $r ) {
513  $cols[] = [
514  "name" => $r[0],
515  "ord" => $r[1],
516  ];
517  }
518 
519  return $cols;
520  }
521 
522  function describeIndex( $idx ) {
523  // first fetch the key (which is a list of columns ords) and
524  // the table the index applies to (an oid)
525  $q = <<<END
526 SELECT indkey, indrelid FROM pg_namespace, pg_class, pg_index
527  WHERE nspname=%s
528  AND pg_class.relnamespace = pg_namespace.oid
529  AND relname=%s
530  AND indexrelid=pg_class.oid
531 END;
532  $res = $this->db->query(
533  sprintf(
534  $q,
535  $this->db->addQuotes( $this->db->getCoreSchema() ),
536  $this->db->addQuotes( $idx )
537  )
538  );
539  if ( !$res ) {
540  return null;
541  }
542  $r = $this->db->fetchRow( $res );
543  if ( !$r ) {
544  return null;
545  }
546 
547  $indkey = $r[0];
548  $relid = intval( $r[1] );
549  $indkeys = explode( ' ', $indkey );
550 
551  $colnames = [];
552  foreach ( $indkeys as $rid ) {
553  $query = <<<END
554 SELECT attname FROM pg_class, pg_attribute
555  WHERE attrelid=$relid
556  AND attnum=%d
557  AND attrelid=pg_class.oid
558 END;
559  $r2 = $this->db->query( sprintf( $query, $rid ) );
560  if ( !$r2 ) {
561  return null;
562  }
563  $row2 = $this->db->fetchRow( $r2 );
564  if ( !$row2 ) {
565  return null;
566  }
567  $colnames[] = $row2[0];
568  }
569 
570  return $colnames;
571  }
572 
573  function fkeyDeltype( $fkey ) {
574  $q = <<<END
575 SELECT confdeltype FROM pg_constraint, pg_namespace
576  WHERE connamespace=pg_namespace.oid
577  AND nspname=%s
578  AND conname=%s;
579 END;
580  $r = $this->db->query(
581  sprintf(
582  $q,
583  $this->db->addQuotes( $this->db->getCoreSchema() ),
584  $this->db->addQuotes( $fkey )
585  )
586  );
587  $row = $this->db->fetchRow( $r );
588  if ( !$row ) {
589  return null;
590  }
591 
592  return $row[0];
593  }
594 
595  function ruleDef( $table, $rule ) {
596  $q = <<<END
597 SELECT definition FROM pg_rules
598  WHERE schemaname = %s
599  AND tablename = %s
600  AND rulename = %s
601 END;
602  $r = $this->db->query(
603  sprintf(
604  $q,
605  $this->db->addQuotes( $this->db->getCoreSchema() ),
606  $this->db->addQuotes( $table ),
607  $this->db->addQuotes( $rule )
608  )
609  );
610  $row = $this->db->fetchRow( $r );
611  if ( !$row ) {
612  return null;
613  }
614  $d = $row[0];
615 
616  return $d;
617  }
618 
619  protected function addSequence( $table, $pkey, $ns ) {
620  if ( !$this->db->sequenceExists( $ns ) ) {
621  $this->output( "Creating sequence $ns\n" );
622  $this->db->query( "CREATE SEQUENCE $ns" );
623  if ( $pkey !== false ) {
624  $this->setDefault( $table, $pkey, '"nextval"(\'"' . $ns . '"\'::"regclass")' );
625  }
626  }
627  }
628 
629  protected function renameSequence( $old, $new ) {
630  if ( $this->db->sequenceExists( $new ) ) {
631  $this->output( "...sequence $new already exists.\n" );
632 
633  return;
634  }
635  if ( $this->db->sequenceExists( $old ) ) {
636  $this->output( "Renaming sequence $old to $new\n" );
637  $this->db->query( "ALTER SEQUENCE $old RENAME TO $new" );
638  }
639  }
640 
641  protected function renameTable( $old, $new, $patch = false ) {
642  if ( $this->db->tableExists( $old ) ) {
643  $this->output( "Renaming table $old to $new\n" );
644  $old = $this->db->realTableName( $old, "quoted" );
645  $new = $this->db->realTableName( $new, "quoted" );
646  $this->db->query( "ALTER TABLE $old RENAME TO $new" );
647  if ( $patch !== false ) {
648  $this->applyPatch( $patch );
649  }
650  }
651  }
652 
653  protected function renameIndex(
654  $table, $old, $new, $skipBothIndexExistWarning = false, $a = false, $b = false
655  ) {
656  // First requirement: the table must exist
657  if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
658  $this->output( "...skipping: '$table' table doesn't exist yet.\n" );
659 
660  return;
661  }
662 
663  // Second requirement: the new index must be missing
664  if ( $this->db->indexExists( $table, $new, __METHOD__ ) ) {
665  $this->output( "...index $new already set on $table table.\n" );
666  if ( !$skipBothIndexExistWarning
667  && $this->db->indexExists( $table, $old, __METHOD__ )
668  ) {
669  $this->output( "...WARNING: $old still exists, despite it has been " .
670  "renamed into $new (which also exists).\n" .
671  " $old should be manually removed if not needed anymore.\n" );
672  }
673 
674  return;
675  }
676 
677  // Third requirement: the old index must exist
678  if ( !$this->db->indexExists( $table, $old, __METHOD__ ) ) {
679  $this->output( "...skipping: index $old doesn't exist.\n" );
680 
681  return;
682  }
683 
684  $this->db->query( "ALTER INDEX $old RENAME TO $new" );
685  }
686 
687  protected function addPgField( $table, $field, $type ) {
688  $fi = $this->db->fieldInfo( $table, $field );
689  if ( !is_null( $fi ) ) {
690  $this->output( "...column '$table.$field' already exists\n" );
691 
692  return;
693  } else {
694  $this->output( "Adding column '$table.$field'\n" );
695  $this->db->query( "ALTER TABLE $table ADD $field $type" );
696  }
697  }
698 
699  protected function changeField( $table, $field, $newtype, $default ) {
700  $fi = $this->db->fieldInfo( $table, $field );
701  if ( is_null( $fi ) ) {
702  $this->output( "...ERROR: expected column $table.$field to exist\n" );
703  exit( 1 );
704  }
705 
706  if ( $fi->type() === $newtype ) {
707  $this->output( "...column '$table.$field' is already of type '$newtype'\n" );
708  } else {
709  $this->output( "Changing column type of '$table.$field' from '{$fi->type()}' to '$newtype'\n" );
710  $sql = "ALTER TABLE $table ALTER $field TYPE $newtype";
711  if ( strlen( $default ) ) {
712  $res = [];
713  if ( preg_match( '/DEFAULT (.+)/', $default, $res ) ) {
714  $sqldef = "ALTER TABLE $table ALTER $field SET DEFAULT $res[1]";
715  $this->db->query( $sqldef );
716  $default = preg_replace( '/\s*DEFAULT .+/', '', $default );
717  }
718  $sql .= " USING $default";
719  }
720  $this->db->query( $sql );
721  }
722  }
723 
724  protected function changeFieldPurgeTable( $table, $field, $newtype, $default ) {
725  # # For a cache table, empty it if the field needs to be changed, because the old contents
726  # # may be corrupted. If the column is already the desired type, refrain from purging.
727  $fi = $this->db->fieldInfo( $table, $field );
728  if ( is_null( $fi ) ) {
729  $this->output( "...ERROR: expected column $table.$field to exist\n" );
730  exit( 1 );
731  }
732 
733  if ( $fi->type() === $newtype ) {
734  $this->output( "...column '$table.$field' is already of type '$newtype'\n" );
735  } else {
736  $this->output( "Purging data from cache table '$table'\n" );
737  $this->db->query( "DELETE from $table" );
738  $this->output( "Changing column type of '$table.$field' from '{$fi->type()}' to '$newtype'\n" );
739  $sql = "ALTER TABLE $table ALTER $field TYPE $newtype";
740  if ( strlen( $default ) ) {
741  $res = [];
742  if ( preg_match( '/DEFAULT (.+)/', $default, $res ) ) {
743  $sqldef = "ALTER TABLE $table ALTER $field SET DEFAULT $res[1]";
744  $this->db->query( $sqldef );
745  $default = preg_replace( '/\s*DEFAULT .+/', '', $default );
746  }
747  $sql .= " USING $default";
748  }
749  $this->db->query( $sql );
750  }
751  }
752 
753  protected function setDefault( $table, $field, $default ) {
754 
755  $info = $this->db->fieldInfo( $table, $field );
756  if ( $info->defaultValue() !== $default ) {
757  $this->output( "Changing '$table.$field' default value\n" );
758  $this->db->query( "ALTER TABLE $table ALTER $field SET DEFAULT "
759  . $this->db->addQuotes( $default ) );
760  }
761  }
762 
763  protected function changeNullableField( $table, $field, $null ) {
764  $fi = $this->db->fieldInfo( $table, $field );
765  if ( is_null( $fi ) ) {
766  $this->output( "...ERROR: expected column $table.$field to exist\n" );
767  exit( 1 );
768  }
769  if ( $fi->isNullable() ) {
770  # # It's NULL - does it need to be NOT NULL?
771  if ( 'NOT NULL' === $null ) {
772  $this->output( "Changing '$table.$field' to not allow NULLs\n" );
773  $this->db->query( "ALTER TABLE $table ALTER $field SET NOT NULL" );
774  } else {
775  $this->output( "...column '$table.$field' is already set as NULL\n" );
776  }
777  } else {
778  # # It's NOT NULL - does it need to be NULL?
779  if ( 'NULL' === $null ) {
780  $this->output( "Changing '$table.$field' to allow NULLs\n" );
781  $this->db->query( "ALTER TABLE $table ALTER $field DROP NOT NULL" );
782  } else {
783  $this->output( "...column '$table.$field' is already set as NOT NULL\n" );
784  }
785  }
786  }
787 
788  public function addPgIndex( $table, $index, $type ) {
789  if ( $this->db->indexExists( $table, $index ) ) {
790  $this->output( "...index '$index' on table '$table' already exists\n" );
791  } else {
792  $this->output( "Creating index '$index' on table '$table' $type\n" );
793  $this->db->query( "CREATE INDEX $index ON $table $type" );
794  }
795  }
796 
797  public function addPgExtIndex( $table, $index, $type ) {
798  if ( $this->db->indexExists( $table, $index ) ) {
799  $this->output( "...index '$index' on table '$table' already exists\n" );
800  } else {
801  if ( preg_match( '/^\(/', $type ) ) {
802  $this->output( "Creating index '$index' on table '$table'\n" );
803  $this->db->query( "CREATE INDEX $index ON $table $type" );
804  } else {
805  $this->applyPatch( $type, true, "Creating index '$index' on table '$table'" );
806  }
807  }
808  }
809 
810  protected function dropFkey( $table, $field ) {
811  $fi = $this->db->fieldInfo( $table, $field );
812  if ( is_null( $fi ) ) {
813  $this->output( "WARNING! Column '$table.$field' does not exist but it should! " .
814  "Please report this.\n" );
815  return;
816  }
817  $conname = $fi->conname();
818  if ( $fi->conname() ) {
819  $this->output( "Dropping foreign key constraint on '$table.$field'\n" );
820  $conclause = "CONSTRAINT \"$conname\"";
821  $command = "ALTER TABLE $table DROP CONSTRAINT $conname";
822  $this->db->query( $command );
823  } else {
824  $this->output( "...foreign key constraint on '$table.$field' already does not exist\n" );
825  };
826  }
827 
828  protected function changeFkeyDeferrable( $table, $field, $clause ) {
829  $fi = $this->db->fieldInfo( $table, $field );
830  if ( is_null( $fi ) ) {
831  $this->output( "WARNING! Column '$table.$field' does not exist but it should! " .
832  "Please report this.\n" );
833 
834  return;
835  }
836  if ( $fi->is_deferred() && $fi->is_deferrable() ) {
837  return;
838  }
839  $this->output( "Altering column '$table.$field' to be DEFERRABLE INITIALLY DEFERRED\n" );
840  $conname = $fi->conname();
841  if ( $fi->conname() ) {
842  $conclause = "CONSTRAINT \"$conname\"";
843  $command = "ALTER TABLE $table DROP CONSTRAINT $conname";
844  $this->db->query( $command );
845  } else {
846  $this->output( "Column '$table.$field' does not have a foreign key " .
847  "constraint, will be added\n" );
848  $conclause = "";
849  }
850  $command =
851  "ALTER TABLE $table ADD $conclause " .
852  "FOREIGN KEY ($field) REFERENCES $clause DEFERRABLE INITIALLY DEFERRED";
853  $this->db->query( $command );
854  }
855 
856  protected function convertArchive2() {
857  if ( $this->db->tableExists( "archive2" ) ) {
858  if ( $this->db->ruleExists( 'archive', 'archive_insert' ) ) {
859  $this->output( "Dropping rule 'archive_insert'\n" );
860  $this->db->query( 'DROP RULE archive_insert ON archive' );
861  }
862  if ( $this->db->ruleExists( 'archive', 'archive_delete' ) ) {
863  $this->output( "Dropping rule 'archive_delete'\n" );
864  $this->db->query( 'DROP RULE archive_delete ON archive' );
865  }
866  $this->applyPatch(
867  'patch-remove-archive2.sql',
868  false,
869  "Converting 'archive2' back to normal archive table"
870  );
871  } else {
872  $this->output( "...obsolete table 'archive2' does not exist\n" );
873  }
874  }
875 
876  protected function checkOiDeleted() {
877  if ( $this->db->fieldInfo( 'oldimage', 'oi_deleted' )->type() !== 'smallint' ) {
878  $this->output( "Changing 'oldimage.oi_deleted' to type 'smallint'\n" );
879  $this->db->query( "ALTER TABLE oldimage ALTER oi_deleted DROP DEFAULT" );
880  $this->db->query(
881  "ALTER TABLE oldimage ALTER oi_deleted TYPE SMALLINT USING (oi_deleted::smallint)" );
882  $this->db->query( "ALTER TABLE oldimage ALTER oi_deleted SET DEFAULT 0" );
883  } else {
884  $this->output( "...column 'oldimage.oi_deleted' is already of type 'smallint'\n" );
885  }
886  }
887 
888  protected function checkOiNameConstraint() {
889  if ( $this->db->hasConstraint( "oldimage_oi_name_fkey_cascaded" ) ) {
890  $this->output( "...table 'oldimage' has correct cascading delete/update " .
891  "foreign key to image\n" );
892  } else {
893  if ( $this->db->hasConstraint( "oldimage_oi_name_fkey" ) ) {
894  $this->db->query(
895  "ALTER TABLE oldimage DROP CONSTRAINT oldimage_oi_name_fkey" );
896  }
897  if ( $this->db->hasConstraint( "oldimage_oi_name_fkey_cascade" ) ) {
898  $this->db->query(
899  "ALTER TABLE oldimage DROP CONSTRAINT oldimage_oi_name_fkey_cascade" );
900  }
901  $this->output( "Making foreign key on table 'oldimage' (to image) a cascade delete/update\n" );
902  $this->db->query(
903  "ALTER TABLE oldimage ADD CONSTRAINT oldimage_oi_name_fkey_cascaded " .
904  "FOREIGN KEY (oi_name) REFERENCES image(img_name) " .
905  "ON DELETE CASCADE ON UPDATE CASCADE" );
906  }
907  }
908 
909  protected function checkPageDeletedTrigger() {
910  if ( !$this->db->triggerExists( 'page', 'page_deleted' ) ) {
911  $this->applyPatch(
912  'patch-page_deleted.sql',
913  false,
914  "Adding function and trigger 'page_deleted' to table 'page'"
915  );
916  } else {
917  $this->output( "...table 'page' has 'page_deleted' trigger\n" );
918  }
919  }
920 
921  protected function dropIndex( $table, $index, $patch = '', $fullpath = false ) {
922  if ( $this->db->indexExists( $table, $index ) ) {
923  $this->output( "Dropping obsolete index '$index'\n" );
924  $this->db->query( "DROP INDEX \"" . $index . "\"" );
925  }
926  }
927 
928  protected function checkIndex( $index, $should_be, $good_def ) {
929  $pu = $this->db->indexAttributes( $index );
930  if ( !empty( $pu ) && $pu != $should_be ) {
931  $this->output( "Dropping obsolete version of index '$index'\n" );
932  $this->db->query( "DROP INDEX \"" . $index . "\"" );
933  $pu = [];
934  } else {
935  $this->output( "...no need to drop index '$index'\n" );
936  }
937 
938  if ( empty( $pu ) ) {
939  $this->output( "Creating index '$index'\n" );
940  $this->db->query( $good_def );
941  } else {
942  $this->output( "...index '$index' exists\n" );
943  }
944  }
945 
946  protected function checkRevUserFkey() {
947  if ( $this->fkeyDeltype( 'revision_rev_user_fkey' ) == 'r' ) {
948  $this->output( "...constraint 'revision_rev_user_fkey' is ON DELETE RESTRICT\n" );
949  } else {
950  $this->applyPatch(
951  'patch-revision_rev_user_fkey.sql',
952  false,
953  "Changing constraint 'revision_rev_user_fkey' to ON DELETE RESTRICT"
954  );
955  }
956  }
957 
958  protected function checkIwlPrefix() {
959  if ( $this->db->indexExists( 'iwlinks', 'iwl_prefix' ) ) {
960  $this->applyPatch(
961  'patch-rename-iwl_prefix.sql',
962  false,
963  "Replacing index 'iwl_prefix' with 'iwl_prefix_title_from'"
964  );
965  }
966  }
967 
968  protected function addInterwikiType() {
969  $this->applyPatch( 'patch-add_interwiki.sql', false, "Refreshing add_interwiki()" );
970  }
971 
972  protected function tsearchFixes() {
973  # Tweak the page_title tsearch2 trigger to filter out slashes
974  # This is create or replace, so harmless to call if not needed
975  $this->applyPatch( 'patch-ts2pagetitle.sql', false, "Refreshing ts2_page_title()" );
976 
977  # If the server is 8.3 or higher, rewrite the tsearch2 triggers
978  # in case they have the old 'default' versions
979  # Gather version numbers in case we need them
980  if ( $this->db->getServerVersion() >= 8.3 ) {
981  $this->applyPatch( 'patch-tsearch2funcs.sql', false, "Rewriting tsearch2 triggers" );
982  }
983  }
984 
985  protected function rebuildTextSearch() {
986  if ( $this->updateRowExists( 'patch-textsearch_bug66650.sql' ) ) {
987  $this->output( "...T68650 already fixed or not applicable.\n" );
988  return;
989  };
990  $this->applyPatch( 'patch-textsearch_bug66650.sql', false,
991  'Rebuilding text search for T68650' );
992  }
993 }
DatabaseUpdater\output
output( $str)
Output some text.
Definition: DatabaseUpdater.php:212
PostgresUpdater\rebuildTextSearch
rebuildTextSearch()
Definition: PostgresUpdater.php:985
PostgresUpdater\renameIndex
renameIndex( $table, $old, $new, $skipBothIndexExistWarning=false, $a=false, $b=false)
Rename an index from an existing table.
Definition: PostgresUpdater.php:653
PostgresUpdater\checkOiNameConstraint
checkOiNameConstraint()
Definition: PostgresUpdater.php:888
PostgresUpdater\getCoreUpdateList
getCoreUpdateList()
Definition: PostgresUpdater.php:44
PostgresUpdater\setDefault
setDefault( $table, $field, $default)
Definition: PostgresUpdater.php:753
DatabaseUpdater\applyPatch
applyPatch( $path, $isFullPath=false, $msg=null)
Applies a SQL patch.
Definition: DatabaseUpdater.php:655
DatabaseUpdater
Class for handling database updates.
Definition: DatabaseUpdater.php:36
PostgresUpdater\convertArchive2
convertArchive2()
Definition: PostgresUpdater.php:856
PostgresUpdater\dropFkey
dropFkey( $table, $field)
Definition: PostgresUpdater.php:810
PostgresUpdater\checkPageDeletedTrigger
checkPageDeletedTrigger()
Definition: PostgresUpdater.php:909
PostgresUpdater\describeIndex
describeIndex( $idx)
Definition: PostgresUpdater.php:522
FROM
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to and or sell copies of the and to permit persons to whom the Software is furnished to do subject to the following WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR ARISING FROM
Definition: MIT-LICENSE.txt:10
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
PostgresUpdater\$db
DatabasePostgres $db
Definition: PostgresUpdater.php:37
PostgresUpdater\renameTable
renameTable( $old, $new, $patch=false)
Definition: PostgresUpdater.php:641
PostgresUpdater\fkeyDeltype
fkeyDeltype( $fkey)
Definition: PostgresUpdater.php:573
Wikimedia\Rdbms\DatabasePostgres
Definition: DatabasePostgres.php:33
$res
$res
Definition: database.txt:21
$type
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
Definition: hooks.txt:2536
PostgresUpdater\checkIwlPrefix
checkIwlPrefix()
Definition: PostgresUpdater.php:958
PostgresUpdater\changeField
changeField( $table, $field, $newtype, $default)
Definition: PostgresUpdater.php:699
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
DatabaseUpdater\$updates
array $updates
Array of updates to perform on the database.
Definition: DatabaseUpdater.php:42
PostgresUpdater\changeFieldPurgeTable
changeFieldPurgeTable( $table, $field, $newtype, $default)
Definition: PostgresUpdater.php:724
PostgresUpdater\addPgExtIndex
addPgExtIndex( $table, $index, $type)
Definition: PostgresUpdater.php:797
$query
null for the wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1572
PostgresUpdater\describeTable
describeTable( $table)
Definition: PostgresUpdater.php:497
PostgresUpdater\ruleDef
ruleDef( $table, $rule)
Definition: PostgresUpdater.php:595
PostgresUpdater\checkRevUserFkey
checkRevUserFkey()
Definition: PostgresUpdater.php:946
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
DatabaseUpdater\updateRowExists
updateRowExists( $key)
Helper function: check if the given key is present in the updatelog table.
Definition: DatabaseUpdater.php:492
PostgresUpdater\changeNullableField
changeNullableField( $table, $field, $null)
Definition: PostgresUpdater.php:763
$command
$command
Definition: cdb.php:64
PostgresUpdater
Class for handling updates to Postgres databases.
Definition: PostgresUpdater.php:32
PostgresUpdater\checkIndex
checkIndex( $index, $should_be, $good_def)
Definition: PostgresUpdater.php:928
PostgresUpdater\changeFkeyDeferrable
changeFkeyDeferrable( $table, $field, $clause)
Definition: PostgresUpdater.php:828
PostgresUpdater\renameSequence
renameSequence( $old, $new)
Definition: PostgresUpdater.php:629
PostgresUpdater\dropIndex
dropIndex( $table, $index, $patch='', $fullpath=false)
Drop an index from an existing table.
Definition: PostgresUpdater.php:921
PostgresUpdater\addInterwikiType
addInterwikiType()
Definition: PostgresUpdater.php:968
PostgresUpdater\addSequence
addSequence( $table, $pkey, $ns)
Definition: PostgresUpdater.php:619
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
PostgresUpdater\tsearchFixes
tsearchFixes()
Definition: PostgresUpdater.php:972
true
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition: hooks.txt:1956
PostgresUpdater\addPgField
addPgField( $table, $field, $type)
Definition: PostgresUpdater.php:687
definition
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation and configuration files Object form shall mean any form resulting from mechanical transformation or translation of a Source including but not limited to compiled object generated and conversions to other media types Work shall mean the work of whether in Source or Object made available under the as indicated by a copyright notice that is included in or attached to the whether in Source or Object that is based or other modifications as a an original work of authorship For the purposes of this Derivative Works shall not include works that remain separable or merely the Work and Derivative Works thereof Contribution shall mean any work of including the original version of the Work and any modifications or additions to that Work or Derivative Works that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner For the purposes of this definition
Definition: APACHE-LICENSE-2.0.txt:49
PostgresUpdater\checkOiDeleted
checkOiDeleted()
Definition: PostgresUpdater.php:876
PostgresUpdater\getOldGlobalUpdates
getOldGlobalUpdates()
Before 1.17, we used to handle updates via stuff like $wgExtNewTables/Fields/Indexes.
Definition: PostgresUpdater.php:458
PostgresUpdater\addPgIndex
addPgIndex( $table, $index, $type)
Definition: PostgresUpdater.php:788