Commit eeda97b6 authored by Marco Pivetta's avatar Marco Pivetta

Merge pull request #533 from deeky666/DBAL-807

[DBAL-807] Respect schema when renaming indexes
parents e7a917e9 9aeefcb9
......@@ -555,6 +555,11 @@ class DB2Platform extends AbstractPlatform
*/
protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName)
{
if (strpos($tableName, '.') !== false) {
list($schema) = explode('.', $tableName);
$oldIndexName = $schema . '.' . $oldIndexName;
}
return array('RENAME INDEX ' . $oldIndexName . ' TO ' . $index->getQuotedName($this));
}
......
......@@ -771,6 +771,11 @@ LEFT JOIN user_cons_columns r_cols
*/
protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName)
{
if (strpos($tableName, '.') !== false) {
list($schema) = explode('.', $tableName);
$oldIndexName = $schema . '.' . $oldIndexName;
}
return array('ALTER INDEX ' . $oldIndexName . ' RENAME TO ' . $index->getQuotedName($this));
}
......
......@@ -563,6 +563,11 @@ class PostgreSqlPlatform extends AbstractPlatform
*/
protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName)
{
if (strpos($tableName, '.') !== false) {
list($schema) = explode('.', $tableName);
$oldIndexName = $schema . '.' . $oldIndexName;
}
return array('ALTER INDEX ' . $oldIndexName . ' RENAME TO ' . $index->getQuotedName($this));
}
......
......@@ -514,6 +514,30 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
);
}
/**
* @group DBAL-807
*/
protected function getAlterTableRenameIndexInSchemaSQL()
{
return array(
'DROP INDEX idx_foo ON myschema.mytable',
'CREATE INDEX idx_bar ON myschema.mytable (id)',
);
}
/**
* @group DBAL-807
*/
protected function getQuotedAlterTableRenameIndexInSchemaSQL()
{
return array(
'DROP INDEX `create` ON `schema`.`table`',
'CREATE INDEX `select` ON `schema`.`table` (id)',
'DROP INDEX `foo` ON `schema`.`table`',
'CREATE INDEX `bar` ON `schema`.`table` (id)',
);
}
public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes()
{
$table = new Table("text_blob_default_value");
......
......@@ -716,4 +716,67 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
* @group DBAL-835
*/
abstract protected function getQuotedAlterTableRenameColumnSQL();
/**
* @group DBAL-807
*/
public function testAlterTableRenameIndexInSchema()
{
$tableDiff = new TableDiff('myschema.mytable');
$tableDiff->fromTable = new Table('myschema.mytable');
$tableDiff->fromTable->addColumn('id', 'integer');
$tableDiff->fromTable->setPrimaryKey(array('id'));
$tableDiff->renamedIndexes = array(
'idx_foo' => new Index('idx_bar', array('id'))
);
$this->assertSame(
$this->getAlterTableRenameIndexInSchemaSQL(),
$this->_platform->getAlterTableSQL($tableDiff)
);
}
/**
* @group DBAL-807
*/
protected function getAlterTableRenameIndexInSchemaSQL()
{
return array(
'DROP INDEX idx_foo',
'CREATE INDEX idx_bar ON myschema.mytable (id)',
);
}
/**
* @group DBAL-807
*/
public function testQuotesAlterTableRenameIndexInSchema()
{
$tableDiff = new TableDiff('`schema`.table');
$tableDiff->fromTable = new Table('`schema`.table');
$tableDiff->fromTable->addColumn('id', 'integer');
$tableDiff->fromTable->setPrimaryKey(array('id'));
$tableDiff->renamedIndexes = array(
'create' => new Index('select', array('id')),
'`foo`' => new Index('`bar`', array('id')),
);
$this->assertSame(
$this->getQuotedAlterTableRenameIndexInSchemaSQL(),
$this->_platform->getAlterTableSQL($tableDiff)
);
}
/**
* @group DBAL-234
*/
protected function getQuotedAlterTableRenameIndexInSchemaSQL()
{
return array(
'DROP INDEX "schema"."create"',
'CREATE INDEX "select" ON "schema"."table" (id)',
'DROP INDEX "schema"."foo"',
'CREATE INDEX "bar" ON "schema"."table" (id)',
);
}
}
......@@ -538,4 +538,25 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
'ALTER TABLE mytable RENAME COLUMN quoted3 TO "baz"',
);
}
/**
* @group DBAL-807
*/
protected function getAlterTableRenameIndexInSchemaSQL()
{
return array(
'ALTER INDEX myschema.idx_foo RENAME TO idx_bar',
);
}
/**
* @group DBAL-807
*/
protected function getQuotedAlterTableRenameIndexInSchemaSQL()
{
return array(
'ALTER INDEX "schema"."create" RENAME TO "select"',
'ALTER INDEX "schema"."foo" RENAME TO "bar"',
);
}
}
......@@ -881,4 +881,25 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
"sp_RENAME 'mytable.quoted3', '[baz]', 'COLUMN'",
);
}
/**
* @group DBAL-807
*/
protected function getAlterTableRenameIndexInSchemaSQL()
{
return array(
"EXEC sp_RENAME N'myschema.mytable.idx_foo', N'idx_bar', N'INDEX'",
);
}
/**
* @group DBAL-807
*/
protected function getQuotedAlterTableRenameIndexInSchemaSQL()
{
return array(
"EXEC sp_RENAME N'[schema].[table].[create]', N'[select]', N'INDEX'",
"EXEC sp_RENAME N'[schema].[table].[foo]', N'[bar]', N'INDEX'",
);
}
}
......@@ -434,4 +434,25 @@ class DB2PlatformTest extends AbstractPlatformTestCase
'RENAME COLUMN quoted3 TO "baz"'
);
}
/**
* @group DBAL-807
*/
protected function getAlterTableRenameIndexInSchemaSQL()
{
return array(
'RENAME INDEX myschema.idx_foo TO idx_bar',
);
}
/**
* @group DBAL-807
*/
protected function getQuotedAlterTableRenameIndexInSchemaSQL()
{
return array(
'RENAME INDEX "schema"."create" TO "select"',
'RENAME INDEX "schema"."foo" TO "bar"',
);
}
}
......@@ -34,4 +34,25 @@ class MySQL57PlatformTest extends AbstractMySQLPlatformTestCase
'ALTER TABLE `table` RENAME INDEX `foo` TO `bar`',
);
}
/**
* @group DBAL-807
*/
protected function getAlterTableRenameIndexInSchemaSQL()
{
return array(
'ALTER TABLE myschema.mytable RENAME INDEX idx_foo TO idx_bar',
);
}
/**
* @group DBAL-807
*/
protected function getQuotedAlterTableRenameIndexInSchemaSQL()
{
return array(
'ALTER TABLE `schema`.`table` RENAME INDEX `create` TO `select`',
'ALTER TABLE `schema`.`table` RENAME INDEX `foo` TO `bar`',
);
}
}
......@@ -455,4 +455,25 @@ class OraclePlatformTest extends AbstractPlatformTestCase
'ALTER TABLE mytable RENAME COLUMN quoted3 TO "baz"',
);
}
/**
* @group DBAL-807
*/
protected function getAlterTableRenameIndexInSchemaSQL()
{
return array(
'ALTER INDEX myschema.idx_foo RENAME TO idx_bar',
);
}
/**
* @group DBAL-807
*/
protected function getQuotedAlterTableRenameIndexInSchemaSQL()
{
return array(
'ALTER INDEX "schema"."create" RENAME TO "select"',
'ALTER INDEX "schema"."foo" RENAME TO "bar"',
);
}
}
......@@ -845,4 +845,25 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
'ALTER TABLE mytable RENAME quoted3 TO "baz"',
);
}
/**
* @group DBAL-807
*/
protected function getAlterTableRenameIndexInSchemaSQL()
{
return array(
'ALTER INDEX idx_foo ON myschema.mytable RENAME TO idx_bar',
);
}
/**
* @group DBAL-807
*/
protected function getQuotedAlterTableRenameIndexInSchemaSQL()
{
return array(
'ALTER INDEX "create" ON "schema"."table" RENAME TO "select"',
'ALTER INDEX "foo" ON "schema"."table" RENAME TO "bar"',
);
}
}
......@@ -496,4 +496,26 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
'DROP TABLE __temp__mytable',
);
}
/**
* @group DBAL-807
*/
public function testAlterTableRenameIndexInSchema()
{
$this->markTestIncomplete(
'Test currently produces broken SQL due to SQLLitePlatform::getAlterTable being broken ' .
'when used with schemas.'
);
}
/**
* @group DBAL-807
*/
public function testQuotesAlterTableRenameIndexInSchema()
{
$this->markTestIncomplete(
'Test currently produces broken SQL due to SQLLitePlatform::getAlterTable being broken ' .
'when used with schemas.'
);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment