MediaWiki  master
SqliteUpdater.php
Go to the documentation of this file.
1 <?php
25 
33 
34  protected function getCoreUpdateList() {
35  return [
36  [ 'disableContentHandlerUseDB' ],
37 
38  // 1.14
39  [ 'addField', 'site_stats', 'ss_active_users', 'patch-ss_active_users.sql' ],
40  [ 'doActiveUsersInit' ],
41  [ 'addField', 'ipblocks', 'ipb_allow_usertalk', 'patch-ipb_allow_usertalk.sql' ],
42  [ 'sqliteInitialIndexes' ],
43 
44  // 1.15
45  [ 'addTable', 'change_tag', 'patch-change_tag.sql' ],
46 
47  // 1.16
48  [ 'addTable', 'user_properties', 'patch-user_properties.sql' ],
49  [ 'addTable', 'log_search', 'patch-log_search.sql' ],
50  [ 'ifNoActorTable', '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  [ 'ifNoActorTable', '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  [ 'addIndex', 'revision', 'page_user_timestamp', 'patch-revision-user-page-index.sql' ],
88  [ 'addField', 'ipblocks', 'ipb_parent_block_id', 'patch-ipb-parent-block-id.sql' ],
89  [ 'addIndex', 'ipblocks', 'ipb_parent_block_id', 'patch-ipb-parent-block-id-index.sql' ],
90  [ 'dropField', 'category', 'cat_hidden', 'patch-cat_hidden.sql' ],
91 
92  // 1.21
93  [ 'addField', 'revision', 'rev_content_format', 'patch-revision-rev_content_format.sql' ],
94  [ 'addField', 'revision', 'rev_content_model', 'patch-revision-rev_content_model.sql' ],
95  [ 'addField', 'archive', 'ar_content_format', 'patch-archive-ar_content_format.sql' ],
96  [ 'addField', 'archive', 'ar_content_model', 'patch-archive-ar_content_model.sql' ],
97  [ 'addField', 'page', 'page_content_model', 'patch-page-page_content_model.sql' ],
98  [ 'enableContentHandlerUseDB' ],
99 
100  [ 'dropField', 'site_stats', 'ss_admins', 'patch-drop-ss_admins.sql' ],
101  [ 'dropField', 'recentchanges', 'rc_moved_to_title', 'patch-rc_moved.sql' ],
102  [ 'addTable', 'sites', 'patch-sites.sql' ],
103  [ 'addField', 'filearchive', 'fa_sha1', 'patch-fa_sha1.sql' ],
104  [ 'addField', 'job', 'job_token', 'patch-job_token.sql' ],
105  [ 'addField', 'job', 'job_attempts', 'patch-job_attempts.sql' ],
106  [ 'addField', 'uploadstash', 'us_props', 'patch-uploadstash-us_props.sql' ],
107  [ 'modifyField', 'user_groups', 'ug_group', 'patch-ug_group-length-increase-255.sql' ],
108  [ 'modifyField', 'user_former_groups', 'ufg_group',
109  'patch-ufg_group-length-increase-255.sql' ],
110  [ 'addIndex', 'page_props', 'pp_propname_page',
111  'patch-page_props-propname-page-index.sql' ],
112  [ 'addIndex', 'image', 'img_media_mime', 'patch-img_media_mime-index.sql' ],
113 
114  // 1.22
115  [ 'addIndex', 'iwlinks', 'iwl_prefix_from_title', 'patch-iwlinks-from-title-index.sql' ],
116  [ 'addField', 'archive', 'ar_id', 'patch-archive-ar_id.sql' ],
117  [ 'addField', 'externallinks', 'el_id', 'patch-externallinks-el_id.sql' ],
118 
119  // 1.23
120  [ 'addField', 'recentchanges', 'rc_source', 'patch-rc_source.sql' ],
121  [ 'ifNoActorTable', 'addIndex', 'logging', 'log_user_text_type_time',
122  'patch-logging_user_text_type_time_index.sql' ],
123  [ 'ifNoActorTable', 'addIndex', 'logging', 'log_user_text_time',
124  'patch-logging_user_text_time_index.sql' ],
125  [ 'addField', 'page', 'page_links_updated', 'patch-page_links_updated.sql' ],
126  [ 'addField', 'user', 'user_password_expires', 'patch-user_password_expire.sql' ],
127 
128  // 1.24
129  [ 'addField', 'page_props', 'pp_sortkey', 'patch-pp_sortkey.sql' ],
130  [ 'dropField', 'recentchanges', 'rc_cur_time', 'patch-drop-rc_cur_time.sql' ],
131  [ 'addIndex', 'watchlist', 'wl_user_notificationtimestamp',
132  'patch-watchlist-user-notificationtimestamp-index.sql' ],
133  [ 'addField', 'page', 'page_lang', 'patch-page-page_lang.sql' ],
134  [ 'addField', 'pagelinks', 'pl_from_namespace', 'patch-pl_from_namespace.sql' ],
135  [ 'addField', 'templatelinks', 'tl_from_namespace', 'patch-tl_from_namespace.sql' ],
136  [ 'addField', 'imagelinks', 'il_from_namespace', 'patch-il_from_namespace.sql' ],
137 
138  // 1.25
139  [ 'dropTable', 'hitcounter' ],
140  [ 'dropField', 'site_stats', 'ss_total_views', 'patch-drop-ss_total_views.sql' ],
141  [ 'dropField', 'page', 'page_counter', 'patch-drop-page_counter.sql' ],
142  [ 'modifyField', 'filearchive', 'fa_deleted_reason', 'patch-editsummary-length.sql' ],
143 
144  // 1.27
145  [ 'dropTable', 'msg_resource_links' ],
146  [ 'dropTable', 'msg_resource' ],
147  [ 'addTable', 'bot_passwords', 'patch-bot_passwords.sql' ],
148  [ 'addField', 'watchlist', 'wl_id', 'patch-watchlist-wl_id.sql' ],
149  [ 'dropIndex', 'categorylinks', 'cl_collation', 'patch-kill-cl_collation_index.sql' ],
150  [ 'addIndex', 'categorylinks', 'cl_collation_ext',
151  'patch-add-cl_collation_ext_index.sql' ],
152  [ 'doCollationUpdate' ],
153 
154  // 1.28
155  [ 'addIndex', 'recentchanges', 'rc_name_type_patrolled_timestamp',
156  'patch-add-rc_name_type_patrolled_timestamp_index.sql' ],
157  [ 'addField', 'change_tag', 'ct_id', 'patch-change_tag-ct_id.sql' ],
158 
159  // 1.29
160  [ 'addField', 'externallinks', 'el_index_60', 'patch-externallinks-el_index_60.sql' ],
161  [ 'addField', 'user_groups', 'ug_expiry', 'patch-user_groups-ug_expiry.sql' ],
162  [ 'ifNoActorTable', 'addIndex', 'image', 'img_user_timestamp', 'patch-image-user-index-2.sql' ],
163 
164  // 1.30
165  [ 'modifyField', 'image', 'img_media_type', 'patch-add-3d.sql' ],
166  [ 'addTable', 'ip_changes', 'patch-ip_changes.sql' ],
167  [ 'renameIndex', 'categorylinks', 'cl_from', 'PRIMARY', false,
168  'patch-categorylinks-fix-pk.sql' ],
169  [ 'renameIndex', 'templatelinks', 'tl_from', 'PRIMARY', false,
170  'patch-templatelinks-fix-pk.sql' ],
171  [ 'renameIndex', 'pagelinks', 'pl_from', 'PRIMARY', false, 'patch-pagelinks-fix-pk.sql' ],
172  [ 'renameIndex', 'text', 'old_id', 'PRIMARY', false, 'patch-text-fix-pk.sql' ],
173  [ 'renameIndex', 'imagelinks', 'il_from', 'PRIMARY', false, 'patch-imagelinks-fix-pk.sql' ],
174  [ 'renameIndex', 'iwlinks', 'iwl_from', 'PRIMARY', false, 'patch-iwlinks-fix-pk.sql' ],
175  [ 'renameIndex', 'langlinks', 'll_from', 'PRIMARY', false, 'patch-langlinks-fix-pk.sql' ],
176  [ 'renameIndex', 'log_search', 'ls_field_val', 'PRIMARY', false, 'patch-log_search-fix-pk.sql' ],
177  [ 'renameIndex', 'module_deps', 'md_module_skin', 'PRIMARY', false,
178  'patch-module_deps-fix-pk.sql' ],
179  [ 'renameIndex', 'objectcache', 'keyname', 'PRIMARY', false, 'patch-objectcache-fix-pk.sql' ],
180  [ 'renameIndex', 'querycache_info', 'qci_type', 'PRIMARY', false,
181  'patch-querycache_info-fix-pk.sql' ],
182  [ 'renameIndex', 'site_stats', 'ss_row_id', 'PRIMARY', false, 'patch-site_stats-fix-pk.sql' ],
183  [ 'renameIndex', 'user_former_groups', 'ufg_user_group', 'PRIMARY', false,
184  'patch-user_former_groups-fix-pk.sql' ],
185  [ 'renameIndex', 'user_properties', 'user_properties_user_property', 'PRIMARY', false,
186  'patch-user_properties-fix-pk.sql' ],
187  [ 'addTable', 'comment', 'patch-comment-table.sql' ],
188  [ 'addTable', 'revision_comment_temp', 'patch-revision_comment_temp-table.sql' ],
189  // image_comment_temp is no longer needed when upgrading to MW 1.31 or newer,
190  // as it is dropped later in the update process as part of 'migrateImageCommentTemp'.
191  // File kept on disk and the updater entry here for historical purposes.
192  // [ 'addTable', 'image_comment_temp', 'patch-image_comment_temp-table.sql' ],
193  [ 'addField', 'archive', 'ar_comment_id', 'patch-archive-ar_comment_id.sql' ],
194  [ 'modifyField', 'image', 'img_description', 'patch-image-img_description-default.sql' ],
195  [ 'addField', 'ipblocks', 'ipb_reason_id', 'patch-ipblocks-ipb_reason_id.sql' ],
196  [ 'addField', 'logging', 'log_comment_id', 'patch-logging-log_comment_id.sql' ],
197  [ 'addField', 'oldimage', 'oi_description_id', 'patch-oldimage-oi_description_id.sql' ],
198  [ 'addField', 'protected_titles', 'pt_reason_id', 'patch-protected_titles-pt_reason_id.sql' ],
199  [ 'addField', 'recentchanges', 'rc_comment_id', 'patch-recentchanges-rc_comment_id.sql' ],
200  [ 'modifyField', 'revision', 'rev_comment', 'patch-revision-rev_comment-default.sql' ],
201 
202  // This field was added in 1.31, but is put here so it can be used by 'migrateComments'
203  [ 'addField', 'image', 'img_description_id', 'patch-image-img_description_id.sql' ],
204  [ 'addField', 'filearchive', 'fa_description_id', 'patch-filearchive-fa_description_id.sql' ],
205 
206  [ 'migrateComments' ],
207  [ 'renameIndex', 'l10n_cache', 'lc_lang_key', 'PRIMARY', false,
208  'patch-l10n_cache-primary-key.sql' ],
209 
210  // 1.31
211  [ 'addTable', 'content', 'patch-content.sql' ],
212  [ 'addTable', 'content_models', 'patch-content_models.sql' ],
213  [ 'addTable', 'slots', 'patch-slots.sql' ],
214  [ 'addField', 'slots', 'slot_origin', 'patch-slot-origin.sql' ],
215  [ 'addTable', 'slot_roles', 'patch-slot_roles.sql' ],
216  [ 'migrateArchiveText' ],
217  [ 'addTable', 'actor', 'patch-actor-table.sql' ],
218  [ 'addField', 'archive', 'ar_actor', 'patch-archive-ar_actor.sql' ],
219  [ 'addTable', 'revision_actor_temp', 'patch-revision_actor_temp-table.sql' ],
220  [ 'addField', 'ipblocks', 'ipb_by_actor', 'patch-ipblocks-ipb_by_actor.sql' ],
221  [ 'addField', 'image', 'img_actor', 'patch-image-img_actor.sql' ],
222  [ 'addField', 'oldimage', 'oi_actor', 'patch-oldimage-oi_actor.sql' ],
223  [ 'addField', 'filearchive', 'fa_actor', 'patch-filearchive-fa_actor.sql' ],
224  [ 'addField', 'recentchanges', 'rc_actor', 'patch-recentchanges-rc_actor.sql' ],
225  [ 'addField', 'logging', 'log_actor', 'patch-logging-log_actor.sql' ],
226  [ 'migrateActors' ],
227  [ 'modifyField', 'revision', 'rev_text_id', 'patch-rev_text_id-default.sql' ],
228  [ 'modifyTable', 'site_stats', 'patch-site_stats-modify.sql' ],
229  [ 'populateArchiveRevId' ],
230  [ 'addIndex', 'recentchanges', 'rc_namespace_title_timestamp',
231  'patch-recentchanges-nttindex.sql' ],
232 
233  // 1.32
234  [ 'addTable', 'change_tag_def', 'patch-change_tag_def.sql' ],
235  [ 'populateExternallinksIndex60' ],
236  [ 'modifyfield', 'externallinks', 'el_index_60',
237  'patch-externallinks-el_index_60-drop-default.sql' ],
238  [ 'runMaintenance', DeduplicateArchiveRevId::class, 'maintenance/deduplicateArchiveRevId.php' ],
239  [ 'addField', 'change_tag', 'ct_tag_id', 'patch-change_tag-tag_id.sql' ],
240  [ 'addIndex', 'archive', 'ar_revid_uniq', 'patch-archive-ar_rev_id-unique.sql' ],
241  [ 'populateContentTables' ],
242  [ 'addIndex', 'logging', 'log_type_action', 'patch-logging-log-type-action-index.sql' ],
243  [ 'dropIndex', 'logging', 'type_action', 'patch-logging-drop-type-action-index.sql' ],
244  [ 'renameIndex', 'interwiki', 'iw_prefix', 'PRIMARY', false, 'patch-interwiki-fix-pk.sql' ],
245  [ 'renameIndex', 'page_props', 'pp_page_propname', 'PRIMARY', false,
246  'patch-page_props-fix-pk.sql' ],
247  [ 'renameIndex', 'protected_titles', 'pt_namespace_title', 'PRIMARY', false,
248  'patch-protected_titles-fix-pk.sql' ],
249  [ 'renameIndex', 'site_identifiers', 'site_ids_type', 'PRIMARY', false,
250  'patch-site_identifiers-fix-pk.sql' ],
251  [ 'addIndex', 'recentchanges', 'rc_this_oldid', 'patch-recentchanges-rc_this_oldid-index.sql' ],
252  [ 'dropTable', 'transcache' ],
253  [ 'runMaintenance', PopulateChangeTagDef::class, 'maintenance/populateChangeTagDef.php' ],
254  [ 'addIndex', 'change_tag', 'change_tag_rc_tag_id',
255  'patch-change_tag-change_tag_rc_tag_id.sql' ],
256  [ 'addField', 'ipblocks', 'ipb_sitewide', 'patch-ipb_sitewide.sql' ],
257  [ 'addTable', 'ipblocks_restrictions', 'patch-ipblocks_restrictions-table.sql' ],
258  [ 'migrateImageCommentTemp' ],
259 
260  // 1.33
261  [ 'dropField', 'change_tag', 'ct_tag', 'patch-drop-ct_tag.sql' ],
262  [ 'dropTable', 'valid_tag' ],
263  [ 'dropTable', 'tag_summary' ],
264  [ 'dropField', 'archive', 'ar_comment', 'patch-archive-drop-ar_comment.sql' ],
265  [ 'dropField', 'ipblocks', 'ipb_reason', 'patch-ipblocks-drop-ipb_reason.sql' ],
266  [ 'dropField', 'image', 'img_description', 'patch-image-drop-img_description.sql' ],
267  [ 'dropField', 'oldimage', 'oi_description', 'patch-oldimage-drop-oi_description.sql' ],
268  [ 'dropField', 'filearchive', 'fa_description', 'patch-filearchive-drop-fa_description.sql' ],
269  [ 'dropField', 'recentchanges', 'rc_comment', 'patch-recentchanges-drop-rc_comment.sql' ],
270  [ 'dropField', 'logging', 'log_comment', 'patch-logging-drop-log_comment.sql' ],
271  [ 'dropField', 'protected_titles', 'pt_reason', 'patch-protected_titles-drop-pt_reason.sql' ],
272 
273  // 1.34
274  [ 'dropField', 'archive', 'ar_user', 'patch-archive-drop-ar_user.sql' ],
275  [ 'dropField', 'ipblocks', 'ipb_by', 'patch-ipblocks-drop-ipb_by.sql' ],
276  [ 'dropField', 'image', 'img_user', 'patch-image-drop-img_user.sql' ],
277  [ 'dropField', 'oldimage', 'oi_user', 'patch-oldimage-drop-oi_user.sql' ],
278  [ 'dropField', 'filearchive', 'fa_user', 'patch-filearchive-drop-fa_user.sql' ],
279  [ 'dropField', 'recentchanges', 'rc_user', 'patch-recentchanges-drop-rc_user.sql' ],
280  [ 'dropField', 'logging', 'log_user', 'patch-logging-drop-log_user.sql' ],
281  ];
282  }
283 
284  protected function sqliteInitialIndexes() {
285  // initial-indexes.sql fails if the indexes are already present,
286  // so we perform a quick check if our database is newer.
287  if ( $this->updateRowExists( 'initial_indexes' ) ||
288  $this->db->indexExists( 'user', 'user_name', __METHOD__ )
289  ) {
290  $this->output( "...have initial indexes\n" );
291 
292  return;
293  }
294  $this->applyPatch( 'initial-indexes.sql', false, "Adding initial indexes" );
295  }
296 
297  protected function sqliteSetupSearchindex() {
298  $module = DatabaseSqlite::getFulltextSearchModule();
299  $fts3tTable = $this->updateRowExists( 'fts3' );
300  if ( $fts3tTable && !$module ) {
301  $this->applyPatch(
302  'searchindex-no-fts.sql',
303  false,
304  'PHP is missing FTS3 support, downgrading tables'
305  );
306  } elseif ( !$fts3tTable && $module == 'FTS3' ) {
307  $this->applyPatch( 'searchindex-fts3.sql', false, "Adding FTS3 search capabilities" );
308  } else {
309  $this->output( "...fulltext search table appears to be in order.\n" );
310  }
311  }
312 }
Class for handling updates to Sqlite databases.
Class for handling database updates.
output( $str)
Output some text.
applyPatch( $path, $isFullPath=false, $msg=null)
Applies a SQL patch.
updateRowExists( $key)
Helper function: check if the given key is present in the updatelog table.