From 5c380739b2eb526f231cab972cf0cade7aed94c8 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Mon, 4 Jun 2018 11:35:35 -0400 Subject: [PATCH] Avoid recreating ar_revid index after it's replaced by ar_revid_uniq Bug: T193180 Change-Id: I274e33de0a348c0ee42b08b349272db7e2151647 --- includes/installer/DatabaseUpdater.php | 33 ++++++++++++++++++++++++++ includes/installer/MysqlUpdater.php | 3 ++- includes/installer/SqliteUpdater.php | 3 ++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/includes/installer/DatabaseUpdater.php b/includes/installer/DatabaseUpdater.php index 99d7186fb6..4fc04db12b 100644 --- a/includes/installer/DatabaseUpdater.php +++ b/includes/installer/DatabaseUpdater.php @@ -779,6 +779,39 @@ abstract class DatabaseUpdater { return true; } + /** + * Add a new index to an existing table if none of the given indexes exist + * + * @param string $table Name of the table to modify + * @param string[] $indexes Name of the indexes to check. $indexes[0] should + * be the one actually being added. + * @param string $patch Path to the patch file + * @param bool $fullpath Whether to treat $patch path as a relative or not + * @return bool False if this was skipped because schema changes are skipped + */ + protected function addIndexIfNoneExist( $table, $indexes, $patch, $fullpath = false ) { + if ( !$this->doTable( $table ) ) { + return true; + } + + if ( !$this->db->tableExists( $table, __METHOD__ ) ) { + $this->output( "...skipping: '$table' table doesn't exist yet.\n" ); + return true; + } + + $newIndex = $indexes[0]; + foreach ( $indexes as $index ) { + if ( $this->db->indexExists( $table, $index, __METHOD__ ) ) { + $this->output( + "...skipping index $newIndex because index $index already set on $table table.\n" + ); + return true; + } + } + + return $this->applyPatch( $patch, $fullpath, "Adding index $index to table $table" ); + } + /** * Drop a field from an existing table * diff --git a/includes/installer/MysqlUpdater.php b/includes/installer/MysqlUpdater.php index 476e729363..f8114e3e75 100644 --- a/includes/installer/MysqlUpdater.php +++ b/includes/installer/MysqlUpdater.php @@ -185,7 +185,8 @@ class MysqlUpdater extends DatabaseUpdater { [ 'doClFieldsUpdate' ], [ 'addTable', 'module_deps', 'patch-module_deps.sql' ], [ 'dropIndex', 'archive', 'ar_page_revid', 'patch-archive_kill_ar_page_revid.sql' ], - [ 'addIndex', 'archive', 'ar_revid', 'patch-archive_ar_revid.sql' ], + [ 'addIndexIfNoneExist', + 'archive', [ 'ar_revid', 'ar_revid_uniq' ], 'patch-archive_ar_revid.sql' ], [ 'doLangLinksLengthUpdate' ], // 1.18 diff --git a/includes/installer/SqliteUpdater.php b/includes/installer/SqliteUpdater.php index 2a67a0a91a..fd9179b9e3 100644 --- a/includes/installer/SqliteUpdater.php +++ b/includes/installer/SqliteUpdater.php @@ -68,7 +68,8 @@ class SqliteUpdater extends DatabaseUpdater { [ 'addField', 'categorylinks', 'cl_collation', 'patch-categorylinks-better-collation.sql' ], [ 'addTable', 'module_deps', 'patch-module_deps.sql' ], [ 'dropIndex', 'archive', 'ar_page_revid', 'patch-archive_kill_ar_page_revid.sql' ], - [ 'addIndex', 'archive', 'ar_revid', 'patch-archive_ar_revid.sql' ], + [ 'addIndexIfNoneExist', + 'archive', [ 'ar_revid', 'ar_revid_uniq' ], 'patch-archive_ar_revid.sql' ], // 1.18 [ 'addIndex', 'user', 'user_email', 'patch-user_email_index.sql' ], -- 2.20.1