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 8f900b5 commit c7d4228
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/Doctrine/Migrations/Generator/DiffGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,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/Doctrine/Migrations/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 @@ -55,7 +56,7 @@ public function testGenerate(): void
->method('getSchemaAssetsFilter')
->willReturn(
static function ($name): bool {
return $name === 'table_name1';
return in_array($name, ['table_name1', 'table_name2_id_seq'], true);
},
);

Expand All @@ -74,10 +75,24 @@ static function ($name): bool {
->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 @@ -93,6 +108,10 @@ static function ($name): bool {
->method('dropTable')
->willReturnOnConsecutiveCalls('schema.table_name2', 'schema.table_name3');

$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 c7d4228

Please sign in to comment.