Skip to content

Commit

Permalink
Apply assets filter on sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
ottaviano committed Jun 1, 2024
1 parent 7780f8d commit 5a3be28
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/Generator/DiffGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ private function createToSchema(): Schema

$toSchema->dropTable($tableName);
}

foreach ($toSchema->getSequences() as $sequence) {
$sequenceName = $sequence->getName();

if ($schemaAssetsFilter($sequenceName)) {
continue;
}

$toSchema->dropSequence($sequenceName);
}
}

return $toSchema;
Expand Down
21 changes: 20 additions & 1 deletion tests/Generator/DiffGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\SchemaDiff;
use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\Table;
use Doctrine\Migrations\Generator\DiffGenerator;
use Doctrine\Migrations\Generator\Generator;
Expand Down Expand Up @@ -43,7 +44,7 @@ public function testGenerate(): void
$this->dbalConfiguration->expects(self::once())
->method('getSchemaAssetsFilter')
->willReturn(
static fn ($name): bool => $name === 'table_name1',
static fn ($name): bool => in_array($name, ['table_name1', 'table_name2_id_seq'], true),

Check failure on line 47 in tests/Generator/DiffGeneratorTest.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.3)

Function in_array() should not be referenced via a fallback global name, but via a use statement.
);

$table1 = $this->createMock(Table::class);
Expand All @@ -61,10 +62,24 @@ public function testGenerate(): void
->method('getName')
->willReturn('schema.table_name3');

$sequence1 = $this->createMock(Sequence::class);
$sequence1->expects(self::once())
->method('getName')
->willReturn('table_name1_id_seq');

$sequence2 = $this->createMock(Sequence::class);
$sequence2->expects(self::once())
->method('getName')
->willReturn('table_name2_id_seq');

$toSchema->expects(self::once())
->method('getTables')
->willReturn([$table1, $table2, $table3]);

$toSchema->expects(self::once())
->method('getSequences')
->willReturn([$sequence1, $sequence2]);

$this->emptySchemaProvider->expects(self::never())
->method('createSchema');

Expand All @@ -80,6 +95,10 @@ public function testGenerate(): void
->method('dropTable')
->willReturnSelf();

$toSchema->expects(self::once())
->method('dropSequence')
->with('table_name1_id_seq');

$schemaDiff = self::createStub(SchemaDiff::class);

$this->platform->method('getAlterSchemaSQL')->willReturnCallback(static function (): array {
Expand Down

0 comments on commit 5a3be28

Please sign in to comment.