Merge pull request #9065 from owncloud/migrator-keepprimaryindexname
Do not rename primary key index when renaming table
This commit is contained in:
commit
cce58368ad
|
@ -128,7 +128,13 @@ class Migrator {
|
||||||
$indexes = $table->getIndexes();
|
$indexes = $table->getIndexes();
|
||||||
$newIndexes = array();
|
$newIndexes = array();
|
||||||
foreach ($indexes as $index) {
|
foreach ($indexes as $index) {
|
||||||
$indexName = 'oc_' . uniqid(); // avoid conflicts in index names
|
if ($index->isPrimary()) {
|
||||||
|
// do not rename primary key
|
||||||
|
$indexName = $index->getName();
|
||||||
|
} else {
|
||||||
|
// avoid conflicts in index names
|
||||||
|
$indexName = 'oc_' . uniqid();
|
||||||
|
}
|
||||||
$newIndexes[] = new Index($indexName, $index->getColumns(), $index->isUnique(), $index->isPrimary());
|
$newIndexes[] = new Index($indexName, $index->getColumns(), $index->isUnique(), $index->isPrimary());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,4 +119,25 @@ class Migrator extends \PHPUnit_Framework_TestCase {
|
||||||
$this->assertTrue(true);
|
$this->assertTrue(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAddingPrimaryKeyWithAutoIncrement() {
|
||||||
|
$startSchema = new Schema(array(), array(), $this->getSchemaConfig());
|
||||||
|
$table = $startSchema->createTable($this->tableName);
|
||||||
|
$table->addColumn('id', 'integer');
|
||||||
|
$table->addColumn('name', 'string');
|
||||||
|
|
||||||
|
$endSchema = new Schema(array(), array(), $this->getSchemaConfig());
|
||||||
|
$table = $endSchema->createTable($this->tableName);
|
||||||
|
$table->addColumn('id', 'integer', array('autoincrement' => true));
|
||||||
|
$table->addColumn('name', 'string');
|
||||||
|
$table->setPrimaryKey(array('id'));
|
||||||
|
|
||||||
|
$migrator = $this->getMigrator();
|
||||||
|
$migrator->migrate($startSchema);
|
||||||
|
|
||||||
|
$migrator->checkMigrate($endSchema);
|
||||||
|
$migrator->migrate($endSchema);
|
||||||
|
|
||||||
|
$this->assertTrue(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue