|
|
|
@ -377,4 +377,40 @@ abstract class SchemaTest extends DatabaseTestCase
|
|
|
|
|
$this->assertSame('', $columnSchema->dbTypecast('')); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testFindUniqueIndexes() |
|
|
|
|
{ |
|
|
|
|
$db = $this->getConnection(); |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
$db->createCommand()->dropTable('uniqueIndex')->execute(); |
|
|
|
|
} catch(\Exception $e) { |
|
|
|
|
} |
|
|
|
|
$db->createCommand()->createTable('uniqueIndex', [ |
|
|
|
|
'somecol' => 'string', |
|
|
|
|
'someCol2' => 'string', |
|
|
|
|
])->execute(); |
|
|
|
|
|
|
|
|
|
/* @var $schema Schema */ |
|
|
|
|
$schema = $db->schema; |
|
|
|
|
|
|
|
|
|
$uniqueIndexes = $schema->findUniqueIndexes($schema->getTableSchema('uniqueIndex', true)); |
|
|
|
|
$this->assertEquals([], $uniqueIndexes); |
|
|
|
|
|
|
|
|
|
$db->createCommand()->createIndex('somecolUnique', 'uniqueIndex', 'somecol', true)->execute(); |
|
|
|
|
|
|
|
|
|
$uniqueIndexes = $schema->findUniqueIndexes($schema->getTableSchema('uniqueIndex', true)); |
|
|
|
|
$this->assertEquals([ |
|
|
|
|
'somecolUnique' => ['somecol'], |
|
|
|
|
], $uniqueIndexes); |
|
|
|
|
|
|
|
|
|
// create another column with upper case letter that fails postgres |
|
|
|
|
// see https://github.com/yiisoft/yii2/issues/10613 |
|
|
|
|
$db->createCommand()->createIndex('someCol2Unique', 'uniqueIndex', 'someCol2', true)->execute(); |
|
|
|
|
|
|
|
|
|
$uniqueIndexes = $schema->findUniqueIndexes($schema->getTableSchema('uniqueIndex', true)); |
|
|
|
|
$this->assertEquals([ |
|
|
|
|
'somecolUnique' => ['somecol'], |
|
|
|
|
'someCol2Unique' => ['someCol2'], |
|
|
|
|
], $uniqueIndexes); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|