diff --git a/src/Database/Models/PgSQL/PgSQLColumn.php b/src/Database/Models/PgSQL/PgSQLColumn.php index f34a71d..5696f86 100644 --- a/src/Database/Models/PgSQL/PgSQLColumn.php +++ b/src/Database/Models/PgSQL/PgSQLColumn.php @@ -164,7 +164,7 @@ private function setRealSpatialColumn(string $fullDefinitionType): void return; } - if (!preg_match('/(\w+)(?:\((\w+)(?:,\s*(\w+))?\))?/', $dataType, $matches)) { + if (!preg_match('/(\w+)(?:\((\w+)(?:,\s*(\w+))?\))?/', $dataType, $matches) || !isset($matches[2])) { return; } diff --git a/src/Migration/Generator/ForeignKeyGenerator.php b/src/Migration/Generator/ForeignKeyGenerator.php index 91d5be1..9a0c319 100644 --- a/src/Migration/Generator/ForeignKeyGenerator.php +++ b/src/Migration/Generator/ForeignKeyGenerator.php @@ -58,10 +58,6 @@ public function makeMethod(ForeignKey $foreignKey): Method return new Method(Foreign::FOREIGN, $foreignKey->getLocalColumns()); } - if ($foreignKey->getName() === null) { - return new Method(Foreign::FOREIGN, $foreignKey->getLocalColumns()); - } - return new Method(Foreign::FOREIGN, $foreignKey->getLocalColumns(), $foreignKey->getName()); } diff --git a/tests/Unit/Migration/Generator/ForeignKeyGeneratorTest.php b/tests/Unit/Migration/Generator/ForeignKeyGeneratorTest.php new file mode 100644 index 0000000..7fe7927 --- /dev/null +++ b/tests/Unit/Migration/Generator/ForeignKeyGeneratorTest.php @@ -0,0 +1,33 @@ +setIgnoreForeignKeyNames(false); + + $foreignKeyGenerator = app(ForeignKeyGenerator::class); + + $method = $foreignKeyGenerator->generateDrop(new SQLiteForeignKey('table', [ + 'name' => null, + 'columns' => ['column'], + 'foreign_schema' => null, + 'foreign_table' => 'foreign_table', + 'foreign_columns' => ['foreign_column'], + 'on_update' => 'on_update', + 'on_delete' => 'on_delete', + ])); + + $this->assertSame($method->getName(), Foreign::DROP_FOREIGN); + $this->assertEmpty($method->getValues()); + } +}