diff --git a/includes/installer/MysqlUpdater.php b/includes/installer/MysqlUpdater.php index ba8b2d19e9d..02101e404e3 100644 --- a/includes/installer/MysqlUpdater.php +++ b/includes/installer/MysqlUpdater.php @@ -343,7 +343,7 @@ class MysqlUpdater extends DatabaseUpdater { [ 'addField', 'oldimage', 'oi_description_id', 'patch-oldimage-oi_description_id.sql' ], [ 'addField', 'protected_titles', 'pt_reason_id', 'patch-protected_titles-pt_reason_id.sql' ], [ 'addField', 'recentchanges', 'rc_comment_id', 'patch-recentchanges-rc_comment_id.sql' ], - [ 'modifyField', 'revision', 'rev_comment', 'patch-revision-rev_comment-default.sql' ], + [ 'setDefault', 'revision', 'rev_comment', '' ], // This field was added in 1.31, but is put here so it can be used by 'migrateComments' [ 'addField', 'image', 'img_description_id', 'patch-image-img_description_id.sql' ], @@ -370,7 +370,11 @@ class MysqlUpdater extends DatabaseUpdater { [ 'addField', 'recentchanges', 'rc_actor', 'patch-recentchanges-rc_actor.sql' ], [ 'addField', 'logging', 'log_actor', 'patch-logging-log_actor.sql' ], [ 'migrateActors' ], - [ 'modifyField', 'revision', 'rev_text_id', 'patch-rev_text_id-default.sql' ], + + // Adds a default value to the rev_text_id field to allow Multi Content + // Revisions migration to happen where rows will have to be added to the + // revision table with no rev_text_id. + [ 'setDefault', 'revision', 'rev_text_id', 0 ], [ 'modifyTable', 'site_stats', 'patch-site_stats-modify.sql' ], [ 'populateArchiveRevId' ], [ 'addIndex', 'recentchanges', 'rc_namespace_title_timestamp', @@ -379,8 +383,7 @@ class MysqlUpdater extends DatabaseUpdater { // 1.32 [ 'addTable', 'change_tag_def', 'patch-change_tag_def.sql' ], [ 'populateExternallinksIndex60' ], - [ 'modifyfield', 'externallinks', 'el_index_60', - 'patch-externallinks-el_index_60-drop-default.sql' ], + [ 'dropDefault', 'externallinks', 'el_index_60' ], [ 'runMaintenance', DeduplicateArchiveRevId::class, 'maintenance/deduplicateArchiveRevId.php' ], [ 'addField', 'change_tag', 'ct_tag_id', 'patch-change_tag-tag_id.sql' ], [ 'addIndex', 'archive', 'ar_revid_uniq', 'patch-archive-ar_rev_id-unique.sql' ], @@ -1369,4 +1372,39 @@ class MysqlUpdater extends DatabaseUpdater { return $vars; } + + /** + * Drop a default value from a field + * + * @since 1.36 + * @param string $table + * @param string $field + */ + protected function dropDefault( $table, $field ) { + $info = $this->db->fieldInfo( $table, $field ); + if ( $info && $info->defaultValue() !== false ) { + $this->output( "Removing '$table.$field' default value\n" ); + $this->db->query( "ALTER TABLE $table ALTER COLUMN $field DROP DEFAULT", __METHOD__ ); + } + } + + /** + * Set a default value for a field + * + * @since 1.36 + * @param string $table + * @param string $field + * @param mixed $default + */ + protected function setDefault( $table, $field, $default ) { + $info = $this->db->fieldInfo( $table, $field ); + if ( $info && $info->defaultValue() !== $default ) { + $this->output( "Changing '$table.$field' default value\n" ); + $this->db->query( + "ALTER TABLE $table ALTER COLUMN $field SET DEFAULT " + . $this->db->addQuotes( $default ), __METHOD__ + ); + } + } + } diff --git a/maintenance/archives/patch-externallinks-el_index_60-drop-default.sql b/maintenance/archives/patch-externallinks-el_index_60-drop-default.sql deleted file mode 100644 index f9242c52bbd..00000000000 --- a/maintenance/archives/patch-externallinks-el_index_60-drop-default.sql +++ /dev/null @@ -1,2 +0,0 @@ --- @since 1.32 -ALTER TABLE /*$wgDBprefix*/externallinks ALTER COLUMN el_index_60 DROP DEFAULT; diff --git a/maintenance/archives/patch-rev_text_id-default.sql b/maintenance/archives/patch-rev_text_id-default.sql deleted file mode 100644 index dc6e4c66758..00000000000 --- a/maintenance/archives/patch-rev_text_id-default.sql +++ /dev/null @@ -1,10 +0,0 @@ --- --- Adds a default value to the rev_text_id field in the revision table. --- This is to allow the Multi Content Revisions migration to happen where --- rows will have to be added to the revision table with no rev_text_id. --- --- 2018-03-12 --- - -ALTER TABLE /*$wgDBprefix*/revision - ALTER COLUMN rev_text_id SET DEFAULT 0; \ No newline at end of file diff --git a/maintenance/archives/patch-revision-rev_comment-default.sql b/maintenance/archives/patch-revision-rev_comment-default.sql deleted file mode 100644 index 2beedccdb95..00000000000 --- a/maintenance/archives/patch-revision-rev_comment-default.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE /*_*/revision - ALTER COLUMN rev_comment SET DEFAULT '';