diff --git a/src/Platforms/AbstractPlatform.php b/src/Platforms/AbstractPlatform.php index 2060fbb74ad..c02fad4b76a 100644 --- a/src/Platforms/AbstractPlatform.php +++ b/src/Platforms/AbstractPlatform.php @@ -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'; diff --git a/tests/Platforms/AbstractPlatformTestCase.php b/tests/Platforms/AbstractPlatformTestCase.php index f737da68ab6..520fcc7255b 100644 --- a/tests/Platforms/AbstractPlatformTestCase.php +++ b/tests/Platforms/AbstractPlatformTestCase.php @@ -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);