Skip to content

Commit

Permalink
Merge pull request #230 from kitloong/feature/update
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
kitloong authored Sep 9, 2024
2 parents 8b35752 + d2d4708 commit 97d9a6b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Database/Models/PgSQL/PgSQLColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 0 additions & 4 deletions src/Migration/Generator/ForeignKeyGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
33 changes: 33 additions & 0 deletions tests/Unit/Migration/Generator/ForeignKeyGeneratorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace KitLoong\MigrationsGenerator\Tests\Unit\Migration\Generator;

use KitLoong\MigrationsGenerator\Database\Models\SQLite\SQLiteForeignKey;
use KitLoong\MigrationsGenerator\Enum\Migrations\Method\Foreign;
use KitLoong\MigrationsGenerator\Migration\Generator\ForeignKeyGenerator;
use KitLoong\MigrationsGenerator\Setting;
use KitLoong\MigrationsGenerator\Tests\TestCase;

class ForeignKeyGeneratorTest extends TestCase
{
public function testGenerateDropWithNullName(): void
{
$setting = app(Setting::class);
$setting->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());
}
}

0 comments on commit 97d9a6b

Please sign in to comment.