Skip to content

Commit

Permalink
Merge pull request #4672 from hschletz/fix-create-unique-constraint
Browse files Browse the repository at this point in the history
Fixed generated SQL for UniqueConstraint objects
  • Loading branch information
morozov committed Jun 15, 2021
2 parents e6add29 + f0f1961 commit 1c7c4aa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Platforms/AbstractPlatform.php
Expand Up @@ -1776,6 +1776,8 @@ public function getCreateConstraintSQL(Constraint $constraint, $table)
'Can only create primary or unique constraints, no common indexes with getCreateConstraintSQL().'
);
}
} elseif ($constraint instanceof UniqueConstraint) {
$query .= ' UNIQUE';
} elseif ($constraint instanceof ForeignKeyConstraint) {
$query .= ' FOREIGN KEY';

Expand Down
4 changes: 4 additions & 0 deletions tests/Platforms/AbstractPlatformTestCase.php
Expand Up @@ -258,6 +258,10 @@ public function testGeneratesConstraintCreationSql(): void
$sql = $this->platform->getCreateConstraintSQL($pk, 'test');
self::assertEquals($this->getGenerateConstraintPrimaryIndexSql(), $sql);

$uc = new UniqueConstraint('constraint_name', ['test']);
$sql = $this->platform->getCreateConstraintSQL($uc, 'test');
self::assertEquals($this->getGenerateConstraintUniqueIndexSql(), $sql);

$fk = new ForeignKeyConstraint(['fk_name'], 'foreign', ['id'], 'constraint_fk');
$sql = $this->platform->getCreateConstraintSQL($fk, 'test');
self::assertEquals($this->getGenerateConstraintForeignKeySql($fk), $sql);
Expand Down

0 comments on commit 1c7c4aa

Please sign in to comment.