MediaWiki master
MysqlUpdater.php
Go to the documentation of this file.
1<?php
2
11namespace MediaWiki\Installer;
12
21
31 protected function getCoreUpdateList() {
32 return [
33 // 1.39
34 [ 'addTable', 'user_autocreate_serial', 'patch-user_autocreate_serial.sql' ],
35 [ 'modifyField', 'ipblocks_restrictions', 'ir_ipb_id', 'patch-ipblocks_restrictions-ir_ipb_id.sql' ],
36 [ 'modifyField', 'ipblocks', 'ipb_id', 'patch-ipblocks-ipb_id.sql' ],
37 [ 'modifyField', 'user', 'user_editcount', 'patch-user-user_editcount.sql' ],
38 [ 'runMaintenance', MigrateRevisionActorTemp::class ],
39 [ 'dropTable', 'revision_actor_temp' ],
40 [ 'runMaintenance', UpdateRestrictions::class ],
41 [ 'dropField', 'page', 'page_restrictions', 'patch-page-drop-page_restrictions.sql' ],
42 [ 'migrateTemplatelinks' ],
43 [ 'modifyField', 'templatelinks', 'tl_namespace', 'patch-templatelinks-tl_title-nullable.sql' ],
44 [ 'dropField', 'templatelinks', 'tl_title', 'patch-templatelinks-drop-tl_title.sql' ],
45
46 // 1.40
47 [ 'addField', 'externallinks', 'el_to_path', 'patch-externallinks-el_to_path.sql' ],
48
49 // 1.41
50 [ 'addField', 'user', 'user_is_temp', 'patch-user-user_is_temp.sql' ],
51 [ 'runMaintenance', MigrateRevisionCommentTemp::class ],
52 [ 'dropTable', 'revision_comment_temp' ],
53 [ 'runMaintenance', MigrateExternallinks::class ],
54 [ 'modifyField', 'externallinks', 'el_to', 'patch-externallinks-el_to_default.sql' ],
55 [ 'addField', 'pagelinks', 'pl_target_id', 'patch-pagelinks-target_id.sql' ],
56 [ 'dropField', 'externallinks', 'el_to', 'patch-externallinks-drop-el_to.sql' ],
57 [ 'runMaintenance', FixInconsistentRedirects::class ],
58 [ 'modifyField', 'image', 'img_size', 'patch-image-img_size_to_bigint.sql' ],
59 [ 'modifyField', 'filearchive', 'fa_size', 'patch-filearchive-fa_size_to_bigint.sql' ],
60 [ 'modifyField', 'oldimage', 'oi_size', 'patch-oldimage-oi_size_to_bigint.sql' ],
61 [ 'modifyField', 'uploadstash', 'us_size', 'patch-uploadstash-us_size_to_bigint.sql' ],
62
63 // 1.42
64 [ 'addField', 'user_autocreate_serial', 'uas_year', 'patch-user_autocreate_serial-uas_year.sql' ],
65 [ 'addTable', 'block_target', 'patch-block_target.sql' ],
66 [ 'dropIndex', 'categorylinks', 'cl_collation_ext', 'patch-drop-cl_collation_ext.sql' ],
67 [ 'runMaintenance', PopulateUserIsTemp::class ],
68 [ 'dropIndex', 'sites', 'site_type', 'patch-sites-drop_indexes.sql' ],
69 [ 'dropIndex', 'iwlinks', 'iwl_prefix_from_title', 'patch-iwlinks-drop-iwl_prefix_from_title.sql' ],
70
71 // 1.43
72 [ 'migratePagelinks' ],
73 [ 'modifyField', 'revision', 'rev_id', 'patch-revision-cleanup.sql' ],
74 [ 'modifyField', 'recentchanges', 'rc_id', 'patch-recentchanges-rc_id-bigint.sql' ],
75 [ 'modifyField', 'change_tag', 'ct_rc_id', 'patch-change_tag-ct_rc_id.sql' ],
76 [ 'runMaintenance', \MigrateBlocks::class ],
77 [ 'dropTable', 'ipblocks' ],
78 [ 'dropField', 'pagelinks', 'pl_title', 'patch-pagelinks-drop-pl_title.sql' ],
79 [ 'modifyField', 'page', 'page_links_updated', 'patch-page-page_links_updated-noinfinite.sql' ],
80 [ 'addPostDatabaseUpdateMaintenance', FixAutoblockLogTitles::class ],
81 [ 'changeTableOption', 'searchindex', 'CONVERT TO CHARACTER SET utf8mb4', 'utf8mb4' ],
82 [ 'migrateSearchindex' ],
83
84 // 1.44
85 [ 'addTable', 'file', 'patch-file.sql' ],
86 [ 'addField', 'categorylinks', 'cl_target_id', 'patch-categorylinks-target_id.sql' ],
87 [ 'addTable', 'collation', 'patch-collation.sql' ],
88 [ 'dropTable', 'module_deps' ],
89
90 // 1.45
91 [ 'addTable', 'existencelinks', 'patch-existencelinks.sql' ],
92 [ 'runMaintenance', FixWrongPasswordPrefixes::class ],
93 [ 'addIndex', 'categorylinks', 'cl_timestamp_id', 'patch-categorylinks-cl_timestamp_id.sql' ],
94 [ 'migrateCategorylinks' ],
95 [ 'normalizeCollation' ],
96 [ 'modifyPrimaryKey', 'categorylinks', [ 'cl_from', 'cl_target_id' ], 'patch-categorylinks-pk.sql' ],
97 [ 'addIndex', 'recentchanges', 'rc_source_name_timestamp',
98 'patch-recentchanges-rc_source_name_timestamp.sql' ],
99 [ 'addIndex', 'recentchanges', 'rc_name_source_patrolled_timestamp',
100 'patch-recentchanges-rc_name_source_patrolled_timestamp.sql' ],
101 [ 'dropField', 'recentchanges', 'rc_new', 'patch-recentchanges-drop-rc_new.sql' ],
102 [ 'dropField', 'categorylinks', 'cl_to', 'patch-categorylinks-drop-cl_to-cl_collation.sql' ],
103
104 // 1.46
105 [ 'addTable', 'watchlist_label', 'patch-watchlist_label.sql' ],
106 ];
107 }
108
110 protected function getInitialUpdateKeys() {
111 return [
112 'filearchive-fa_major_mime-patch-fa_major_mime-chemical.sql',
113 'image-img_major_mime-patch-img_major_mime-chemical.sql',
114 'oldimage-oi_major_mime-patch-oi_major_mime-chemical.sql',
115 'user_groups-ug_group-patch-ug_group-length-increase-255.sql',
116 'user_former_groups-ufg_group-patch-ufg_group-length-increase-255.sql',
117 'user_properties-up_property-patch-up_property.sql',
118 ];
119 }
120
122 public function getSchemaVars() {
123 global $wgDBTableOptions;
124
125 $vars = [];
126 $vars['wgDBTableOptions'] = str_replace( 'TYPE', 'ENGINE', $wgDBTableOptions );
127 $vars['wgDBTableOptions'] = str_replace(
128 'CHARSET=mysql4',
129 'CHARSET=binary',
130 $vars['wgDBTableOptions']
131 );
132
133 return $vars;
134 }
135
143 protected function dropDefault( $table, $field ) {
144 $updateKey = "$table-$field-dropDefault";
145
146 if ( $this->updateRowExists( $updateKey ) ) {
147 return;
148 }
149
150 $info = $this->db->fieldInfo( $table, $field );
151 if ( $info && $info->defaultValue() !== false ) {
152 $this->output( "Removing '$table.$field' default value.\n" );
153 $table = $this->db->tableName( $table );
154 $ret = $this->db->query( "ALTER TABLE $table ALTER COLUMN $field DROP DEFAULT", __METHOD__ );
155
156 if ( $ret ) {
157 $this->insertUpdateRow( $updateKey );
158 }
159 }
160 }
161
170 protected function setDefault( $table, $field, $default ) {
171 $info = $this->db->fieldInfo( $table, $field );
172 if ( $info && $info->defaultValue() !== $default ) {
173 $this->output( "Changing '$table.$field' default value.\n" );
174 $table = $this->db->tableName( $table );
175 $this->db->query(
176 "ALTER TABLE $table ALTER COLUMN $field SET DEFAULT "
177 . $this->db->addQuotes( $default ), __METHOD__
178 );
179 }
180 }
181
190 protected function changeTableOption( string $table, string $tableOption, string $updateName ) {
191 $updateKey = "$table-tableoption-$updateName";
192 if ( $this->updateRowExists( $updateKey ) ) {
193 return;
194 }
195
196 $this->output( "Changing table options of '$table'.\n" );
197 $table = $this->db->tableName( $table );
198 $ret = $this->db->query(
199 "ALTER TABLE $table $tableOption",
200 __METHOD__
201 );
202
203 if ( $ret ) {
204 $this->insertUpdateRow( $updateKey );
205 }
206 }
207
208 protected function migrateSearchindex() {
209 $updateKey = 'searchindex-pk-titlelength';
210 if ( !$this->tableExists( 'searchindex' ) ) {
211 return;
212 }
213
214 $primaryIndexExists = $this->db->indexExists( 'searchindex', 'PRIMARY' );
215 if ( $this->updateRowExists( $updateKey ) || $primaryIndexExists ) {
216 $this->output( "...searchindex table has already been migrated.\n" );
217 if ( !$this->updateRowExists( $updateKey ) ) {
218 $this->insertUpdateRow( $updateKey );
219 }
220 return;
221 }
222
223 $apply = $this->applyPatch( 'patch-searchindex-pk-titlelength.sql', false, '...migrating searchindex table' );
224
225 if ( $apply ) {
226 $this->insertUpdateRow( $updateKey );
227 }
228 }
229}
230
232class_alias( MysqlUpdater::class, 'MysqlUpdater' );
Fix redirect pages with missing or incomplete row in the redirect table.
An error in a previous version of MediaWiki caused B type passwords to be written with an :A: prefix ...
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.Should return a multidimensional array....
changeTableOption(string $table, string $tableOption, string $updateName)
Change the table options of a table.
getSchemaVars()
Get appropriate schema variables in the current database connection.This should be called after any r...
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.