MediaWiki REL1_35
SqliteUpdater.php
Go to the documentation of this file.
1<?php
25
34
35 protected function getCoreUpdateList() {
36 return [
37 // 1.14
38 [ 'addField', 'site_stats', 'ss_active_users', 'patch-ss_active_users.sql' ],
39 [ 'doActiveUsersInit' ],
40 [ 'addField', 'ipblocks', 'ipb_allow_usertalk', 'patch-ipb_allow_usertalk.sql' ],
41 [ 'sqliteInitialIndexes' ],
42
43 // 1.15
44 [ 'addTable', 'change_tag', 'patch-change_tag.sql' ],
45
46 // 1.16
47 [ 'addTable', 'user_properties', 'patch-user_properties.sql' ],
48 [ 'addTable', 'log_search', 'patch-log_search.sql' ],
49 [ 'ifTableNotExists', 'actor',
50 'addField', 'logging', 'log_user_text', 'patch-log_user_text.sql' ],
51 # listed separately from the previous update because 1.16 was released without this update
52 [ 'ifTableNotExists', 'actor', 'doLogUsertextPopulation' ],
53 [ 'doLogSearchPopulation' ],
54 [ 'addTable', 'l10n_cache', 'patch-l10n_cache.sql' ],
55 [ 'dropIndex', 'change_tag', 'ct_rc_id', 'patch-change_tag-indexes.sql' ],
56 [ 'addField', 'redirect', 'rd_interwiki', 'patch-rd_interwiki.sql' ],
57 [ 'sqliteSetupSearchindex' ],
58
59 // 1.17
60 [ 'addTable', 'iwlinks', 'patch-iwlinks.sql' ],
61 [ 'addIndex', 'iwlinks', 'iwl_prefix_title_from', 'patch-rename-iwl_prefix.sql' ],
62 [ 'addField', 'updatelog', 'ul_value', 'patch-ul_value.sql' ],
63 [ 'addField', 'interwiki', 'iw_api', 'patch-iw_api_and_wikiid.sql' ],
64 [ 'dropIndex', 'iwlinks', 'iwl_prefix', 'patch-kill-iwl_prefix.sql' ],
65 [ 'addField', 'categorylinks', 'cl_collation', 'patch-categorylinks-better-collation.sql' ],
66 [ 'addTable', 'module_deps', 'patch-module_deps.sql' ],
67 [ 'dropIndex', 'archive', 'ar_page_revid', 'patch-archive_kill_ar_page_revid.sql' ],
68 [ 'addIndexIfNoneExist',
69 'archive', [ 'ar_revid', 'ar_revid_uniq' ], 'patch-archive_ar_revid.sql' ],
70
71 // 1.18
72 [ 'addIndex', 'user', 'user_email', 'patch-user_email_index.sql' ],
73 [ 'addTable', 'uploadstash', 'patch-uploadstash.sql' ],
74 [ 'addTable', 'user_former_groups', 'patch-user_former_groups.sql' ],
75
76 // 1.19
77 [ 'doMigrateUserOptions' ],
78 [ 'dropField', 'user', 'user_options', 'patch-drop-user_options.sql' ],
79 [ 'addField', 'revision', 'rev_sha1', 'patch-rev_sha1.sql' ],
80 [ 'addField', 'archive', 'ar_sha1', 'patch-ar_sha1.sql' ],
81 [ 'addIndex', 'page', 'page_redirect_namespace_len',
82 'patch-page_redirect_namespace_len.sql' ],
83 [ 'addField', 'uploadstash', 'us_chunk_inx', 'patch-uploadstash_chunk.sql' ],
84 [ 'addfield', 'job', 'job_timestamp', 'patch-jobs-add-timestamp.sql' ],
85
86 // 1.20
87 [ 'ifFieldExists', 'revision', 'rev_user',
88 'addIndex', 'revision', 'page_user_timestamp', 'patch-revision-user-page-index.sql' ],
89 [ 'addField', 'ipblocks', 'ipb_parent_block_id', 'patch-ipb-parent-block-id.sql' ],
90 [ 'addIndex', 'ipblocks', 'ipb_parent_block_id', 'patch-ipb-parent-block-id-index.sql' ],
91 [ 'dropField', 'category', 'cat_hidden', 'patch-cat_hidden.sql' ],
92
93 // 1.21
94 [ 'ifFieldExists', 'revision', 'rev_text_id',
95 'addField', 'revision', 'rev_content_format', 'patch-revision-rev_content_format.sql' ],
96 [ 'ifFieldExists', 'revision', 'rev_text_id',
97 'addField', 'revision', 'rev_content_model', 'patch-revision-rev_content_model.sql' ],
98 [ 'ifFieldExists', 'archive', 'ar_text_id',
99 'addField', 'archive', 'ar_content_format', 'patch-archive-ar_content_format.sql' ],
100 [ 'ifFieldExists', 'archive', 'ar_text_id',
101 'addField', 'archive', 'ar_content_model', 'patch-archive-ar_content_model.sql' ],
102 [ 'addField', 'page', 'page_content_model', 'patch-page-page_content_model.sql' ],
103
104 [ 'dropField', 'site_stats', 'ss_admins', 'patch-drop-ss_admins.sql' ],
105 [ 'dropField', 'recentchanges', 'rc_moved_to_title', 'patch-rc_moved.sql' ],
106 [ 'addTable', 'sites', 'patch-sites.sql' ],
107 [ 'addField', 'filearchive', 'fa_sha1', 'patch-fa_sha1.sql' ],
108 [ 'addField', 'job', 'job_token', 'patch-job_token.sql' ],
109 [ 'addField', 'job', 'job_attempts', 'patch-job_attempts.sql' ],
110 [ 'addField', 'uploadstash', 'us_props', 'patch-uploadstash-us_props.sql' ],
111 [ 'modifyField', 'user_groups', 'ug_group', 'patch-ug_group-length-increase-255.sql' ],
112 [ 'modifyField', 'user_former_groups', 'ufg_group',
113 'patch-ufg_group-length-increase-255.sql' ],
114 [ 'addIndex', 'page_props', 'pp_propname_page',
115 'patch-page_props-propname-page-index.sql' ],
116 [ 'addIndex', 'image', 'img_media_mime', 'patch-img_media_mime-index.sql' ],
117
118 // 1.22
119 [ 'addIndex', 'iwlinks', 'iwl_prefix_from_title', 'patch-iwlinks-from-title-index.sql' ],
120 [ 'addField', 'archive', 'ar_id', 'patch-archive-ar_id.sql' ],
121 [ 'addField', 'externallinks', 'el_id', 'patch-externallinks-el_id.sql' ],
122
123 // 1.23
124 [ 'addField', 'recentchanges', 'rc_source', 'patch-rc_source.sql' ],
125 [ 'ifTableNotExists', 'actor', 'addIndex', 'logging', 'log_user_text_type_time',
126 'patch-logging_user_text_type_time_index.sql' ],
127 [ 'ifTableNotExists', 'actor', 'addIndex', 'logging', 'log_user_text_time',
128 'patch-logging_user_text_time_index.sql' ],
129 [ 'addField', 'page', 'page_links_updated', 'patch-page_links_updated.sql' ],
130 [ 'addField', 'user', 'user_password_expires', 'patch-user_password_expire.sql' ],
131
132 // 1.24
133 [ 'addField', 'page_props', 'pp_sortkey', 'patch-pp_sortkey.sql' ],
134 [ 'dropField', 'recentchanges', 'rc_cur_time', 'patch-drop-rc_cur_time.sql' ],
135 [ 'addIndex', 'watchlist', 'wl_user_notificationtimestamp',
136 'patch-watchlist-user-notificationtimestamp-index.sql' ],
137 [ 'addField', 'page', 'page_lang', 'patch-page-page_lang.sql' ],
138 [ 'addField', 'pagelinks', 'pl_from_namespace', 'patch-pl_from_namespace.sql' ],
139 [ 'addField', 'templatelinks', 'tl_from_namespace', 'patch-tl_from_namespace.sql' ],
140 [ 'addField', 'imagelinks', 'il_from_namespace', 'patch-il_from_namespace.sql' ],
141
142 // 1.25
143 [ 'dropTable', 'hitcounter' ],
144 [ 'dropField', 'site_stats', 'ss_total_views', 'patch-drop-ss_total_views.sql' ],
145 [ 'dropField', 'page', 'page_counter', 'patch-drop-page_counter.sql' ],
146 [ 'modifyField', 'filearchive', 'fa_deleted_reason', 'patch-editsummary-length.sql' ],
147
148 // 1.27
149 [ 'dropTable', 'msg_resource_links' ],
150 [ 'dropTable', 'msg_resource' ],
151 [ 'addTable', 'bot_passwords', 'patch-bot_passwords.sql' ],
152 [ 'addField', 'watchlist', 'wl_id', 'patch-watchlist-wl_id.sql' ],
153 [ 'dropIndex', 'categorylinks', 'cl_collation', 'patch-kill-cl_collation_index.sql' ],
154 [ 'addIndex', 'categorylinks', 'cl_collation_ext',
155 'patch-add-cl_collation_ext_index.sql' ],
156 [ 'doCollationUpdate' ],
157
158 // 1.28
159 [ 'addIndex', 'recentchanges', 'rc_name_type_patrolled_timestamp',
160 'patch-add-rc_name_type_patrolled_timestamp_index.sql' ],
161 [ 'addField', 'change_tag', 'ct_id', 'patch-change_tag-ct_id.sql' ],
162
163 // 1.29
164 [ 'addField', 'externallinks', 'el_index_60', 'patch-externallinks-el_index_60.sql' ],
165 [ 'addField', 'user_groups', 'ug_expiry', 'patch-user_groups-ug_expiry.sql' ],
166 [ 'ifTableNotExists', 'actor',
167 'addIndex', 'image', 'img_user_timestamp', 'patch-image-user-index-2.sql' ],
168
169 // 1.30
170 [ 'modifyField', 'image', 'img_media_type', 'patch-add-3d.sql' ],
171 [ 'addTable', 'ip_changes', 'patch-ip_changes.sql' ],
172 [ 'renameIndex', 'categorylinks', 'cl_from', 'PRIMARY', false,
173 'patch-categorylinks-fix-pk.sql' ],
174 [ 'renameIndex', 'templatelinks', 'tl_from', 'PRIMARY', false,
175 'patch-templatelinks-fix-pk.sql' ],
176 [ 'renameIndex', 'pagelinks', 'pl_from', 'PRIMARY', false, 'patch-pagelinks-fix-pk.sql' ],
177 [ 'renameIndex', 'text', 'old_id', 'PRIMARY', false, 'patch-text-fix-pk.sql' ],
178 [ 'renameIndex', 'imagelinks', 'il_from', 'PRIMARY', false, 'patch-imagelinks-fix-pk.sql' ],
179 [ 'renameIndex', 'iwlinks', 'iwl_from', 'PRIMARY', false, 'patch-iwlinks-fix-pk.sql' ],
180 [ 'renameIndex', 'langlinks', 'll_from', 'PRIMARY', false, 'patch-langlinks-fix-pk.sql' ],
181 [ 'renameIndex', 'log_search', 'ls_field_val', 'PRIMARY', false, 'patch-log_search-fix-pk.sql' ],
182 [ 'renameIndex', 'module_deps', 'md_module_skin', 'PRIMARY', false,
183 'patch-module_deps-fix-pk.sql' ],
184 [ 'renameIndex', 'objectcache', 'keyname', 'PRIMARY', false, 'patch-objectcache-fix-pk.sql' ],
185 [ 'renameIndex', 'querycache_info', 'qci_type', 'PRIMARY', false,
186 'patch-querycache_info-fix-pk.sql' ],
187 [ 'renameIndex', 'site_stats', 'ss_row_id', 'PRIMARY', false, 'patch-site_stats-fix-pk.sql' ],
188 [ 'renameIndex', 'user_former_groups', 'ufg_user_group', 'PRIMARY', false,
189 'patch-user_former_groups-fix-pk.sql' ],
190 [ 'renameIndex', 'user_properties', 'user_properties_user_property', 'PRIMARY', false,
191 'patch-user_properties-fix-pk.sql' ],
192 [ 'addTable', 'comment', 'patch-comment-table.sql' ],
193 [ 'addTable', 'revision_comment_temp', 'patch-revision_comment_temp-table.sql' ],
194 // image_comment_temp is no longer needed when upgrading to MW 1.31 or newer,
195 // as it is dropped later in the update process as part of 'migrateImageCommentTemp'.
196 // File kept on disk and the updater entry here for historical purposes.
197 // [ 'addTable', 'image_comment_temp', 'patch-image_comment_temp-table.sql' ],
198 [ 'addField', 'archive', 'ar_comment_id', 'patch-archive-ar_comment_id.sql' ],
199 [ 'modifyField', 'image', 'img_description', 'patch-image-img_description-default.sql' ],
200 [ 'addField', 'ipblocks', 'ipb_reason_id', 'patch-ipblocks-ipb_reason_id.sql' ],
201 [ 'addField', 'logging', 'log_comment_id', 'patch-logging-log_comment_id.sql' ],
202 [ 'addField', 'oldimage', 'oi_description_id', 'patch-oldimage-oi_description_id.sql' ],
203 [ 'addField', 'protected_titles', 'pt_reason_id', 'patch-protected_titles-pt_reason_id.sql' ],
204 [ 'addField', 'recentchanges', 'rc_comment_id', 'patch-recentchanges-rc_comment_id.sql' ],
205 [ 'modifyField', 'revision', 'rev_comment', 'patch-revision-rev_comment-default.sql' ],
206
207 // This field was added in 1.31, but is put here so it can be used by 'migrateComments'
208 [ 'addField', 'image', 'img_description_id', 'patch-image-img_description_id.sql' ],
209 [ 'addField', 'filearchive', 'fa_description_id', 'patch-filearchive-fa_description_id.sql' ],
210
211 [ 'migrateComments' ],
212 [ 'renameIndex', 'l10n_cache', 'lc_lang_key', 'PRIMARY', false,
213 'patch-l10n_cache-primary-key.sql' ],
214
215 // 1.31
216 [ 'addTable', 'content', 'patch-content.sql' ],
217 [ 'addTable', 'content_models', 'patch-content_models.sql' ],
218 [ 'addTable', 'slots', 'patch-slots.sql' ],
219 [ 'addField', 'slots', 'slot_origin', 'patch-slot-origin.sql' ],
220 [ 'addTable', 'slot_roles', 'patch-slot_roles.sql' ],
221 [ 'migrateArchiveText' ],
222 [ 'addTable', 'actor', 'patch-actor-table.sql' ],
223 [ 'addField', 'archive', 'ar_actor', 'patch-archive-ar_actor.sql' ],
224 [ 'addTable', 'revision_actor_temp', 'patch-revision_actor_temp-table.sql' ],
225 [ 'addField', 'ipblocks', 'ipb_by_actor', 'patch-ipblocks-ipb_by_actor.sql' ],
226 [ 'addField', 'image', 'img_actor', 'patch-image-img_actor.sql' ],
227 [ 'addField', 'oldimage', 'oi_actor', 'patch-oldimage-oi_actor.sql' ],
228 [ 'addField', 'filearchive', 'fa_actor', 'patch-filearchive-fa_actor.sql' ],
229 [ 'addField', 'recentchanges', 'rc_actor', 'patch-recentchanges-rc_actor.sql' ],
230 [ 'addField', 'logging', 'log_actor', 'patch-logging-log_actor.sql' ],
231 [ 'migrateActors' ],
232 [ 'modifyField', 'revision', 'rev_text_id', 'patch-rev_text_id-default.sql' ],
233 [ 'modifyTable', 'site_stats', 'patch-site_stats-modify.sql' ],
234 [ 'populateArchiveRevId' ],
235 [ 'addIndex', 'recentchanges', 'rc_namespace_title_timestamp',
236 'patch-recentchanges-nttindex.sql' ],
237
238 // 1.32
239 [ 'addTable', 'change_tag_def', 'patch-change_tag_def.sql' ],
240 [ 'populateExternallinksIndex60' ],
241 [ 'modifyfield', 'externallinks', 'el_index_60',
242 'patch-externallinks-el_index_60-drop-default.sql' ],
243 [ 'runMaintenance', DeduplicateArchiveRevId::class, 'maintenance/deduplicateArchiveRevId.php' ],
244 [ 'addField', 'change_tag', 'ct_tag_id', 'patch-change_tag-tag_id.sql' ],
245 [ 'addIndex', 'archive', 'ar_revid_uniq', 'patch-archive-ar_rev_id-unique.sql' ],
246 [ 'populateContentTables' ],
247 [ 'addIndex', 'logging', 'log_type_action', 'patch-logging-log-type-action-index.sql' ],
248 [ 'dropIndex', 'logging', 'type_action', 'patch-logging-drop-type-action-index.sql' ],
249 [ 'renameIndex', 'interwiki', 'iw_prefix', 'PRIMARY', false, 'patch-interwiki-fix-pk.sql' ],
250 [ 'renameIndex', 'page_props', 'pp_page_propname', 'PRIMARY', false,
251 'patch-page_props-fix-pk.sql' ],
252 [ 'renameIndex', 'protected_titles', 'pt_namespace_title', 'PRIMARY', false,
253 'patch-protected_titles-fix-pk.sql' ],
254 [ 'renameIndex', 'site_identifiers', 'site_ids_type', 'PRIMARY', false,
255 'patch-site_identifiers-fix-pk.sql' ],
256 [ 'addIndex', 'recentchanges', 'rc_this_oldid', 'patch-recentchanges-rc_this_oldid-index.sql' ],
257 [ 'dropTable', 'transcache' ],
258 [ 'runMaintenance', PopulateChangeTagDef::class, 'maintenance/populateChangeTagDef.php' ],
259 [ 'addIndex', 'change_tag', 'change_tag_rc_tag_id',
260 'patch-change_tag-change_tag_rc_tag_id.sql' ],
261 [ 'addField', 'ipblocks', 'ipb_sitewide', 'patch-ipb_sitewide.sql' ],
262 [ 'addTable', 'ipblocks_restrictions', 'patch-ipblocks_restrictions-table.sql' ],
263 [ 'migrateImageCommentTemp' ],
264
265 // 1.33
266 [ 'dropField', 'change_tag', 'ct_tag', 'patch-drop-ct_tag.sql' ],
267 [ 'dropTable', 'valid_tag' ],
268 [ 'dropTable', 'tag_summary' ],
269 [ 'dropField', 'archive', 'ar_comment', 'patch-archive-drop-ar_comment.sql' ],
270 [ 'dropField', 'ipblocks', 'ipb_reason', 'patch-ipblocks-drop-ipb_reason.sql' ],
271 [ 'dropField', 'image', 'img_description', 'patch-image-drop-img_description.sql' ],
272 [ 'dropField', 'oldimage', 'oi_description', 'patch-oldimage-drop-oi_description.sql' ],
273 [ 'dropField', 'filearchive', 'fa_description', 'patch-filearchive-drop-fa_description.sql' ],
274 [ 'dropField', 'recentchanges', 'rc_comment', 'patch-recentchanges-drop-rc_comment.sql' ],
275 [ 'dropField', 'logging', 'log_comment', 'patch-logging-drop-log_comment.sql' ],
276 [ 'dropField', 'protected_titles', 'pt_reason', 'patch-protected_titles-drop-pt_reason.sql' ],
277
278 // 1.34
279 [ 'dropField', 'archive', 'ar_user', 'patch-archive-drop-ar_user.sql' ],
280 [ 'dropField', 'ipblocks', 'ipb_by', 'patch-ipblocks-drop-ipb_by.sql' ],
281 [ 'dropField', 'image', 'img_user', 'patch-image-drop-img_user.sql' ],
282 [ 'dropField', 'oldimage', 'oi_user', 'patch-oldimage-drop-oi_user.sql' ],
283 [ 'dropField', 'filearchive', 'fa_user', 'patch-filearchive-drop-fa_user.sql' ],
284 [ 'dropField', 'recentchanges', 'rc_user', 'patch-recentchanges-drop-rc_user.sql' ],
285 [ 'dropField', 'logging', 'log_user', 'patch-logging-drop-log_user.sql' ],
286
287 // 1.35
288 [ 'addTable', 'watchlist_expiry', 'patch-watchlist_expiry.sql' ],
289 [ 'modifyfield', 'filearchive', 'fa_actor', 'patch-filearchive-drop-fa_actor-DEFAULT.sql' ],
290 [ 'modifyfield', 'recentchanges', 'rc_actor', 'patch-recentchanges-drop-rc_actor-DEFAULT.sql' ],
291 [ 'modifyfield', 'logging', 'log_actor', 'patch-logging-drop-log_actor-DEFAULT.sql' ],
292 [ 'modifyField', 'page', 'page_restrictions', 'patch-page_restrictions-null.sql' ],
293 [ 'renameIndex', 'ipblocks', 'ipb_address', 'ipb_address_unique', false,
294 'patch-ipblocks-rename-ipb_address.sql' ],
295 [ 'addField', 'revision', 'rev_actor', 'patch-revision-actor-comment-MCR.sql' ],
296 [ 'dropField', 'archive', 'ar_text_id', 'patch-archive-MCR.sql' ],
297 [ 'doFixIpbAddressUniqueIndex' ],
298 [ 'modifyField', 'actor', 'actor_name', 'patch-actor-actor_name-varbinary.sql' ]
299 ];
300 }
301
302 protected function sqliteInitialIndexes() {
303 // initial-indexes.sql fails if the indexes are already present,
304 // so we perform a quick check if our database is newer.
305 if ( $this->updateRowExists( 'initial_indexes' ) ||
306 $this->db->indexExists( 'user', 'user_name', __METHOD__ )
307 ) {
308 $this->output( "...have initial indexes\n" );
309
310 return;
311 }
312 $this->applyPatch( 'initial-indexes.sql', false, "Adding initial indexes" );
313 }
314
315 protected function sqliteSetupSearchindex() {
316 $module = DatabaseSqlite::getFulltextSearchModule();
317 $fts3tTable = $this->updateRowExists( 'fts3' );
318 if ( $fts3tTable && !$module ) {
319 $this->applyPatch(
320 'searchindex-no-fts.sql',
321 false,
322 'PHP is missing FTS3 support, downgrading tables'
323 );
324 } elseif ( !$fts3tTable && $module == 'FTS3' ) {
325 $this->applyPatch( 'searchindex-fts3.sql', false, "Adding FTS3 search capabilities" );
326 } else {
327 $this->output( "...fulltext search table appears to be in order.\n" );
328 }
329 }
330
339 protected function indexHasField( $table, $index, $field ) {
340 $info = $this->db->indexInfo( $table, $index, __METHOD__ );
341 if ( $info ) {
342 foreach ( $info as $column ) {
343 if ( $column == $field ) {
344 $this->output( "...index $index on table $table includes field $field.\n" );
345 return true;
346 }
347 }
348 }
349 $this->output( "...index $index on table $table has no field $field; added.\n" );
350
351 return false;
352 }
353
354 protected function doFixIpbAddressUniqueIndex() {
355 if ( !$this->indexHasField( 'ipblocks', 'ipb_address_unique', 'ipb_anon_only' ) ) {
356 $this->output( "...ipb_address_unique index up-to-date.\n" );
357 return;
358 }
359
360 $this->applyPatch(
361 'patch-ipblocks-fix-ipb_address_unique.sql',
362 false,
363 'Removing ipb_anon_only column from ipb_address_unique index'
364 );
365 }
366}
Class for handling database updates.
updateRowExists( $key)
Helper function: check if the given key is present in the updatelog table.
output( $str)
Output some text.
applyPatch( $path, $isFullPath=false, $msg=null)
Applies a SQL patch.
getCoreUpdateList()
Get an array of updates to perform on the database.
indexHasField( $table, $index, $field)
Check whether an index contain a field.