New methods to drop or rename extension index in DatabaseUpdater
- DatabaseUpdater::dropExtensionIndex( $tableName, $indexName, $sqlPath ) - DatabaseUpdater::renameExtensionIndex( $tableName, $oldIndexName, $newIndexName, $sqlPath, $skipBothIndexExistWarning = false ) [ Case use ] This feature is required to help extensions schema change to ensure compatibility with SQLite. First extensions to use it will be Echo and Flagged Revisions. Change-Id: Ia2782d644593ab6b64b67720ed61b3994db10346
This commit is contained in:
parent
ac9d8f3afc
commit
2f60cd20b6
2 changed files with 72 additions and 1 deletions
|
|
@ -66,6 +66,8 @@ production.
|
|||
* (bug 24620) Add types to LogFormatter.
|
||||
* jQuery JSON upgraded from 2.3 to 2.4.0.
|
||||
* Added GetDoubleUnderscoreIDs hook, for modifying the list of magic words.
|
||||
* DatabaseUpdater class has two new methods to ease extensions schema changes:
|
||||
dropExtensionIndex and renameExtensionIndex.
|
||||
|
||||
=== Bug fixes in 1.21 ===
|
||||
* (bug 40353) SpecialDoubleRedirect should support interwiki redirects.
|
||||
|
|
|
|||
|
|
@ -256,6 +256,19 @@ abstract class DatabaseUpdater {
|
|||
$this->extensionUpdates[] = array( 'dropField', $tableName, $columnName, $sqlPath, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Drop an index from an extension table
|
||||
*
|
||||
* @since 1.21
|
||||
*
|
||||
* @param $tableName string The table name
|
||||
* @param $indexName string The index name
|
||||
* @param $sqlPath string The path to the SQL change path
|
||||
*/
|
||||
public function dropExtensionIndex( $tableName, $indexName, $sqlPath ) {
|
||||
$this->extensionUpdates[] = array( 'dropIndex', $tableName, $indexName, $sqlPath, true );
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @since 1.20
|
||||
|
|
@ -267,6 +280,21 @@ abstract class DatabaseUpdater {
|
|||
$this->extensionUpdates[] = array( 'dropTable', $tableName, $sqlPath, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename an index on an extension table
|
||||
*
|
||||
* @since 1.21
|
||||
*
|
||||
* @param $tableName string The table name
|
||||
* @param $oldIndexName string The old index name
|
||||
* @param $newIndexName string The new index name
|
||||
* @param $skipBothIndexExistWarning Boolean: Whether to warn if both the old and the new indexes exist. [facultative; by default, false]
|
||||
* @param $sqlPath string The path to the SQL change path
|
||||
*/
|
||||
public function renameExtensionIndex( $tableName, $oldIndexName, $newIndexName, $sqlPath, $skipBothIndexExistWarning = false ) {
|
||||
$this->extensionUpdates[] = array( 'renameIndex', $tableName, $oldIndexName, $newIndexName, $skipBothIndexExistWarning, $sqlPath, true );
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @since 1.20
|
||||
|
|
@ -569,6 +597,7 @@ abstract class DatabaseUpdater {
|
|||
|
||||
/**
|
||||
* Applies a SQL patch
|
||||
*
|
||||
* @param $path String Path to the patch file
|
||||
* @param $isFullPath Boolean Whether to treat $path as a relative or not
|
||||
* @param $msg String Description of the patch
|
||||
|
|
@ -599,6 +628,7 @@ abstract class DatabaseUpdater {
|
|||
|
||||
/**
|
||||
* Add a new table to the database
|
||||
*
|
||||
* @param $name String Name of the new table
|
||||
* @param $patch String Path to the patch file
|
||||
* @param $fullpath Boolean Whether to treat $patch path as a relative or not
|
||||
|
|
@ -619,6 +649,7 @@ abstract class DatabaseUpdater {
|
|||
|
||||
/**
|
||||
* Add a new field to an existing table
|
||||
*
|
||||
* @param $table String Name of the table to modify
|
||||
* @param $field String Name of the new field
|
||||
* @param $patch String Path to the patch file
|
||||
|
|
@ -642,6 +673,7 @@ abstract class DatabaseUpdater {
|
|||
|
||||
/**
|
||||
* Add a new index to an existing table
|
||||
*
|
||||
* @param $table String Name of the table to modify
|
||||
* @param $index String Name of the new index
|
||||
* @param $patch String Path to the patch file
|
||||
|
|
@ -690,7 +722,7 @@ abstract class DatabaseUpdater {
|
|||
* Drop an index from an existing table
|
||||
*
|
||||
* @param $table String: Name of the table to modify
|
||||
* @param $index String: Name of the old index
|
||||
* @param $index String: Name of the index
|
||||
* @param $patch String: Path to the patch file
|
||||
* @param $fullpath Boolean: Whether to treat $patch path as a relative or not
|
||||
* @return Boolean false if this was skipped because schema changes are skipped
|
||||
|
|
@ -708,6 +740,43 @@ abstract class DatabaseUpdater {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename an index from an existing table
|
||||
*
|
||||
* @param $table String: Name of the table to modify
|
||||
* @param $oldIndex String: Old name of the index
|
||||
* @param $newIndex String: New name of the index
|
||||
* @param $skipBothIndexExistWarning Boolean: Whether to warn if both the old and the new indexes exist.
|
||||
* @param $patch String: Path to the patch file
|
||||
* @param $fullpath Boolean: Whether to treat $patch path as a relative or not
|
||||
* @return Boolean false if this was skipped because schema changes are skipped
|
||||
*/
|
||||
protected function renameIndex( $table, $oldIndex, $newIndex, $skipBothIndexExistWarning, $patch, $fullpath = false ) {
|
||||
// First requirement: the table must exist
|
||||
if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
|
||||
$this->output( "...skipping: '$table' table doesn't exist yet.\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
// Second requirement: the new index must be missing
|
||||
if ( $this->db->indexExists( $table, $newIndex, __METHOD__ ) ) {
|
||||
$this->output( "...index $newIndex already set on $table table.\n" );
|
||||
if ( !$skipBothIndexExistWarning && $this->db->indexExists( $table, $oldIndex, __METHOD__ ) ) {
|
||||
$this->output( "...WARNING: $oldIndex still exists, despite it has been renamed into $newIndex (which also exists).\n $oldIndex should be manually removed if not needed anymore.\n" );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Third requirement: the old index must exist
|
||||
if ( !$this->db->indexExists( $table, $oldIndex, __METHOD__ ) ) {
|
||||
$this->output( "...skipping: index $oldIndex doesn't exist.\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
// Requirements have been satisfied, patch can be applied
|
||||
return $this->applyPatch( $patch, $fullpath, "Renaming index $oldIndex into $newIndex to table $table" );
|
||||
}
|
||||
|
||||
/**
|
||||
* If the specified table exists, drop it, or execute the
|
||||
* patch if one is provided.
|
||||
|
|
|
|||
Loading…
Reference in a new issue