MediaWiki master
MysqlUpdater.php
Go to the documentation of this file.
1<?php
2
25namespace MediaWiki\Installer;
26
34
43 protected function getCoreUpdateList() {
44 return [
45 // 1.36
46 [ 'modifyField', 'redirect', 'rd_title', 'patch-redirect-rd_title-varbinary.sql' ],
47 [ 'modifyField', 'pagelinks', 'pl_title', 'patch-pagelinks-pl_title-varbinary.sql' ],
48 [ 'modifyField', 'templatelinks', 'tl_title', 'patch-templatelinks-tl_title-varbinary.sql' ],
49 [ 'modifyField', 'imagelinks', 'il_to', 'patch-imagelinks-il_to-varbinary.sql' ],
50 [ 'modifyField', 'langlinks', 'll_title', 'patch-langlinks-ll_title-varbinary.sql' ],
51 [ 'modifyField', 'iwlinks', 'iwl_title', 'patch-iwlinks-iwl_title-varbinary.sql' ],
52 [ 'modifyField', 'category', 'cat_title', 'patch-category-cat_title-varbinary.sql' ],
53 [ 'modifyField', 'querycache', 'qc_title', 'patch-querycache-qc_title-varbinary.sql' ],
54 [ 'modifyField', 'querycachetwo', 'qcc_title', 'patch-querycachetwo-qcc_title-varbinary.sql' ],
55 [ 'modifyField', 'watchlist', 'wl_title', 'patch-watchlist-wl_title-varbinary.sql' ],
56 [ 'modifyField', 'user_newtalk', 'user_last_timestamp',
57 'patch-user_newtalk-user_last_timestamp-binary.sql'
58 ],
59 [ 'modifyField', 'protected_titles', 'pt_title', 'patch-protected_titles-pt_title-varbinary.sql' ],
60 [ 'dropDefault', 'protected_titles', 'pt_expiry' ],
61 [ 'dropDefault', 'ip_changes', 'ipc_rev_timestamp' ],
62 [ 'modifyField', 'ipblocks_restrictions', 'ir_type', 'patch-ipblocks_restrictions-ir_type.sql' ],
63 [ 'renameIndex', 'watchlist', 'namespace_title', 'wl_namespace_title', false,
64 'patch-watchlist-namespace_title-rename-index.sql' ],
65 [ 'modifyField', 'job', 'job_title', 'patch-job-job_title-varbinary.sql' ],
66 [ 'modifyField', 'job', 'job_timestamp', 'patch-job_job_timestamp.sql' ],
67 [ 'modifyField', 'job', 'job_token_timestamp', 'patch-job_job_token_timestamp.sql' ],
68 [ 'modifyField', 'watchlist', 'wl_notificationtimestamp', 'patch-watchlist-wl_notificationtimestamp.sql' ],
69 [ 'modifyField', 'slot_roles', 'role_id', 'patch-slot_roles-role_id.sql' ],
70 [ 'modifyField', 'content_models', 'model_id', 'patch-content_models-model_id.sql' ],
71 [ 'modifyField', 'categorylinks', 'cl_to', 'patch-categorylinks-cl_to-varbinary.sql' ],
72 [ 'modifyField', 'logging', 'log_title', 'patch-logging-log_title-varbinary.sql' ],
73 [ 'modifyField', 'uploadstash', 'us_timestamp', 'patch-uploadstash-us_timestamp.sql' ],
74 [ 'renameIndex', 'user_properties', 'user_properties_property', 'up_property', false,
75 'patch-user_properties-rename-index.sql' ],
76 [ 'renameIndex', 'sites', 'sites_global_key', 'site_global_key', false, 'patch-sites-rename-indexes.sql' ],
77 [ 'renameIndex', 'logging', 'type_time', 'log_type_time', false, 'patch-logging-rename-indexes.sql' ],
78 [ 'modifyField', 'filearchive', 'fa_name', 'patch-filearchive-fa_name.sql' ],
79 [ 'dropDefault', 'filearchive', 'fa_deleted_timestamp' ],
80 [ 'dropDefault', 'filearchive', 'fa_timestamp' ],
81 [ 'modifyField', 'oldimage', 'oi_name', 'patch-oldimage-oi_name-varbinary.sql' ],
82 [ 'dropDefault', 'oldimage', 'oi_timestamp' ],
83 [ 'modifyField', 'objectcache', 'exptime', 'patch-objectcache-exptime-notnull.sql' ],
84 [ 'dropDefault', 'ipblocks', 'ipb_timestamp' ],
85 [ 'dropDefault', 'ipblocks', 'ipb_expiry' ],
86 [ 'renameIndex', 'archive', 'name_title_timestamp', 'ar_name_title_timestamp', false,
87 'patch-archive-rename-name_title_timestamp-index.sql' ],
88 [ 'modifyField', 'image', 'img_name', 'patch-image-img_name-varbinary.sql' ],
89 [ 'dropDefault', 'image', 'img_timestamp' ],
90 [ 'modifyField', 'image', 'img_timestamp', 'patch-image-img_timestamp.sql' ],
91 [ 'renameIndex', 'site_identifiers', 'site_ids_key', 'si_key', false,
92 'patch-site_identifiers-rename-indexes.sql' ],
93 [ 'modifyField', 'recentchanges', 'rc_title', 'patch-recentchanges-rc_title-varbinary.sql' ],
94 [ 'dropDefault', 'recentchanges', 'rc_timestamp' ],
95 [ 'modifyField', 'recentchanges', 'rc_timestamp', 'patch-recentchanges-rc_timestamp.sql' ],
96 [ 'modifyField', 'recentchanges', 'rc_id', 'patch-recentchanges-rc_id.sql' ],
97 [ 'renameIndex', 'recentchanges', 'new_name_timestamp', 'rc_new_name_timestamp', false,
98 'patch-recentchanges-rc_new_name_timestamp.sql' ],
99 [ 'dropDefault', 'archive', 'ar_timestamp' ],
100 [ 'modifyField', 'archive', 'ar_title', 'patch-archive-ar_title-varbinary.sql' ],
101 [ 'modifyField', 'page', 'page_title', 'patch-page-page_title-varbinary.sql' ],
102 [ 'dropDefault', 'page', 'page_touched' ],
103 [ 'modifyField', 'user', 'user_name', 'patch-user_table-updates.sql' ],
104
105 // 1.37
106 [ 'renameIndex', 'revision', 'page_timestamp', 'rev_page_timestamp', false,
107 'patch-revision-rename-index.sql' ],
108 [ 'addField', 'objectcache', 'modtoken', 'patch-objectcache-modtoken.sql' ],
109 [ 'dropDefault', 'revision', 'rev_timestamp' ],
110 [ 'addIndex', 'oldimage', 'oi_timestamp', 'patch-oldimage-oi_timestamp.sql' ],
111 [ 'renameIndex', 'page', 'name_title', 'page_name_title', false, 'patch-page-rename-name_title-index.sql' ],
112 [ 'renameIndex', 'change_tag', 'change_tag_rc_tag_id', 'ct_rc_tag_id', false,
113 'patch-change_tag-rename-indexes.sql' ],
114
115 // 1.38
116 [ 'doConvertDjvuMetadata' ],
117 [ 'dropField', 'page_restrictions', 'pr_user', 'patch-drop-page_restrictions-pr_user.sql' ],
118 [ 'modifyField', 'filearchive', 'fa_id', 'patch-filearchive-fa_id.sql' ],
119 [ 'modifyField', 'image', 'img_major_mime', 'patch-image-img_major_mime-default.sql' ],
120 [ 'addTable', 'linktarget', 'patch-linktarget.sql' ],
121 [ 'dropIndex', 'revision', 'rev_page_id', 'patch-drop-rev_page_id.sql' ],
122 [ 'modifyField', 'page_restrictions', 'pr_page', 'patch-page_restrictions-pr_page.sql' ],
123 [ 'modifyField', 'page_props', 'pp_page', 'patch-page_props-pp_page.sql' ],
124 [ 'modifyField', 'ipblocks_restrictions', 'ir_value', 'patch-ipblocks_restrictions-ir_value.sql' ],
125 [ 'addField', 'templatelinks', 'tl_target_id', 'patch-templatelinks-target_id.sql' ],
126
127 // 1.39
128 [ 'addTable', 'user_autocreate_serial', 'patch-user_autocreate_serial.sql' ],
129 [ 'modifyField', 'ipblocks_restrictions', 'ir_ipb_id', 'patch-ipblocks_restrictions-ir_ipb_id.sql' ],
130 [ 'modifyField', 'ipblocks', 'ipb_id', 'patch-ipblocks-ipb_id.sql' ],
131 [ 'modifyField', 'user', 'user_editcount', 'patch-user-user_editcount.sql' ],
132 [ 'runMaintenance', MigrateRevisionActorTemp::class ],
133 [ 'dropTable', 'revision_actor_temp' ],
134 [ 'runMaintenance', UpdateRestrictions::class ],
135 [ 'dropField', 'page', 'page_restrictions', 'patch-page-drop-page_restrictions.sql' ],
136 [ 'migrateTemplatelinks' ],
137 [ 'modifyField', 'templatelinks', 'tl_namespace', 'patch-templatelinks-tl_title-nullable.sql' ],
138 [ 'dropField', 'templatelinks', 'tl_title', 'patch-templatelinks-drop-tl_title.sql' ],
139
140 // 1.40
141 [ 'addField', 'externallinks', 'el_to_path', 'patch-externallinks-el_to_path.sql' ],
142
143 // 1.41
144 [ 'addField', 'user', 'user_is_temp', 'patch-user-user_is_temp.sql' ],
145 [ 'runMaintenance', MigrateRevisionCommentTemp::class ],
146 [ 'dropTable', 'revision_comment_temp' ],
147 [ 'runMaintenance', MigrateExternallinks::class ],
148 [ 'modifyField', 'externallinks', 'el_to', 'patch-externallinks-el_to_default.sql' ],
149 [ 'addField', 'pagelinks', 'pl_target_id', 'patch-pagelinks-target_id.sql' ],
150 [ 'dropField', 'externallinks', 'el_to', 'patch-externallinks-drop-el_to.sql' ],
151 [ 'runMaintenance', FixInconsistentRedirects::class ],
152 [ 'modifyField', 'image', 'img_size', 'patch-image-img_size_to_bigint.sql' ],
153 [ 'modifyField', 'filearchive', 'fa_size', 'patch-filearchive-fa_size_to_bigint.sql' ],
154 [ 'modifyField', 'oldimage', 'oi_size', 'patch-oldimage-oi_size_to_bigint.sql' ],
155 [ 'modifyField', 'uploadstash', 'us_size', 'patch-uploadstash-us_size_to_bigint.sql' ],
156
157 // 1.42
158 [ 'addField', 'user_autocreate_serial', 'uas_year', 'patch-user_autocreate_serial-uas_year.sql' ],
159 [ 'addTable', 'block_target', 'patch-block_target.sql' ],
160 [ 'dropIndex', 'categorylinks', 'cl_collation_ext', 'patch-drop-cl_collation_ext.sql' ],
161 [ 'runMaintenance', PopulateUserIsTemp::class ],
162 [ 'dropIndex', 'sites', 'site_type', 'patch-sites-drop_indexes.sql' ],
163 [ 'dropIndex', 'iwlinks', 'iwl_prefix_from_title', 'patch-iwlinks-drop-iwl_prefix_from_title.sql' ],
164
165 // 1.43
166 [ 'migratePagelinks' ],
167 [ 'modifyField', 'revision', 'rev_id', 'patch-revision-cleanup.sql' ],
168 [ 'modifyField', 'recentchanges', 'rc_id', 'patch-recentchanges-rc_id-bigint.sql' ],
169 [ 'modifyField', 'change_tag', 'ct_rc_id', 'patch-change_tag-ct_rc_id.sql' ],
170 [ 'runMaintenance', \MigrateBlocks::class ],
171 [ 'dropTable', 'ipblocks' ],
172 [ 'dropField', 'pagelinks', 'pl_title', 'patch-pagelinks-drop-pl_title.sql' ],
173 [ 'modifyField', 'page', 'page_links_updated', 'patch-page-page_links_updated-noinfinite.sql' ],
174 [ 'addPostDatabaseUpdateMaintenance', FixAutoblockLogTitles::class ],
175 [ 'changeTableOption', 'searchindex', 'CONVERT TO CHARACTER SET utf8mb4', 'utf8mb4' ],
176 [ 'migrateSearchindex' ],
177
178 // 1.44
179 [ 'addTable', 'file', 'patch-file.sql' ],
180 [ 'addField', 'categorylinks', 'cl_target_id', 'patch-categorylinks-target_id.sql' ],
181 [ 'addTable', 'collation', 'patch-collation.sql' ],
182 [ 'dropTable', 'module_deps' ],
183 ];
184 }
185
186 protected function getInitialUpdateKeys() {
187 return [
188 'filearchive-fa_major_mime-patch-fa_major_mime-chemical.sql',
189 'image-img_major_mime-patch-img_major_mime-chemical.sql',
190 'oldimage-oi_major_mime-patch-oi_major_mime-chemical.sql',
191 'user_groups-ug_group-patch-ug_group-length-increase-255.sql',
192 'user_former_groups-ufg_group-patch-ufg_group-length-increase-255.sql',
193 'user_properties-up_property-patch-up_property.sql',
194 ];
195 }
196
197 public function getSchemaVars() {
198 global $wgDBTableOptions;
199
200 $vars = [];
201 $vars['wgDBTableOptions'] = str_replace( 'TYPE', 'ENGINE', $wgDBTableOptions );
202 $vars['wgDBTableOptions'] = str_replace(
203 'CHARSET=mysql4',
204 'CHARSET=binary',
205 $vars['wgDBTableOptions']
206 );
207
208 return $vars;
209 }
210
218 protected function dropDefault( $table, $field ) {
219 $updateKey = "$table-$field-dropDefault";
220
221 if ( $this->updateRowExists( $updateKey ) ) {
222 return;
223 }
224
225 $info = $this->db->fieldInfo( $table, $field );
226 if ( $info && $info->defaultValue() !== false ) {
227 $this->output( "Removing '$table.$field' default value.\n" );
228 $table = $this->db->tableName( $table );
229 $ret = $this->db->query( "ALTER TABLE $table ALTER COLUMN $field DROP DEFAULT", __METHOD__ );
230
231 if ( $ret ) {
232 $this->insertUpdateRow( $updateKey );
233 }
234 }
235 }
236
245 protected function setDefault( $table, $field, $default ) {
246 $info = $this->db->fieldInfo( $table, $field );
247 if ( $info && $info->defaultValue() !== $default ) {
248 $this->output( "Changing '$table.$field' default value.\n" );
249 $table = $this->db->tableName( $table );
250 $this->db->query(
251 "ALTER TABLE $table ALTER COLUMN $field SET DEFAULT "
252 . $this->db->addQuotes( $default ), __METHOD__
253 );
254 }
255 }
256
265 protected function changeTableOption( string $table, string $tableOption, string $updateName ) {
266 $updateKey = "$table-tableoption-$updateName";
267 if ( $this->updateRowExists( $updateKey ) ) {
268 return;
269 }
270
271 $this->output( "Changing table options of '$table'.\n" );
272 $table = $this->db->tableName( $table );
273 $ret = $this->db->query(
274 "ALTER TABLE $table $tableOption",
275 __METHOD__
276 );
277
278 if ( $ret ) {
279 $this->insertUpdateRow( $updateKey );
280 }
281 }
282
283 protected function migrateSearchindex() {
284 $updateKey = 'searchindex-pk-titlelength';
285 if ( !$this->tableExists( 'searchindex' ) ) {
286 return;
287 }
288
289 $primaryIndexExists = $this->db->indexExists( 'searchindex', 'PRIMARY' );
290 if ( $this->updateRowExists( $updateKey ) || $primaryIndexExists ) {
291 $this->output( "...searchindex table has already been migrated.\n" );
292 if ( !$this->updateRowExists( $updateKey ) ) {
293 $this->insertUpdateRow( $updateKey );
294 }
295 return;
296 }
297
298 $apply = $this->applyPatch( 'patch-searchindex-pk-titlelength.sql', false, '...migrating searchindex table' );
299
300 if ( $apply ) {
301 $this->insertUpdateRow( $updateKey );
302 }
303 }
304}
305
307class_alias( MysqlUpdater::class, 'MysqlUpdater' );
Fix redirect pages with missing or incomplete row in the redirect table.
Apply database changes after updating MediaWiki.
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.
insertUpdateRow( $key, $val=null)
Helper function: Add a key to the updatelog table.
setDefault( $table, $field, $default)
Set a default value for a field.
getCoreUpdateList()
Get an array of updates to perform on the database.
changeTableOption(string $table, string $tableOption, string $updateName)
Change the table options of a table.
getSchemaVars()
Get appropriate schema variables in the current database connection.
dropDefault( $table, $field)
Drops the default value from a field.
getInitialUpdateKeys()
Get an array of update keys to insert into the updatelog table after a new installation.
Maintenance script that merges the revision_actor_temp table into the revision table.
Maintenance script that merges the revision_comment_temp table into the revision table.
Maintenance script that Fills the user_is_temp column of the user table for users created before MW 1...
Maintenance script that updates page_restrictions table from old page_restriction column.
$wgDBTableOptions
Config variable stub for the DBTableOptions setting, for use by phpdoc and IDEs.