Skip to content

Commit 5a3be28

Browse files
committed
Apply assets filter on sequences
1 parent 7780f8d commit 5a3be28

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/Generator/DiffGenerator.php

+10
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,16 @@ private function createToSchema(): Schema
120120

121121
$toSchema->dropTable($tableName);
122122
}
123+
124+
foreach ($toSchema->getSequences() as $sequence) {
125+
$sequenceName = $sequence->getName();
126+
127+
if ($schemaAssetsFilter($sequenceName)) {
128+
continue;
129+
}
130+
131+
$toSchema->dropSequence($sequenceName);
132+
}
123133
}
124134

125135
return $toSchema;

tests/Generator/DiffGeneratorTest.php

+20-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Doctrine\DBAL\Schema\Comparator;
1111
use Doctrine\DBAL\Schema\Schema;
1212
use Doctrine\DBAL\Schema\SchemaDiff;
13+
use Doctrine\DBAL\Schema\Sequence;
1314
use Doctrine\DBAL\Schema\Table;
1415
use Doctrine\Migrations\Generator\DiffGenerator;
1516
use Doctrine\Migrations\Generator\Generator;
@@ -43,7 +44,7 @@ public function testGenerate(): void
4344
$this->dbalConfiguration->expects(self::once())
4445
->method('getSchemaAssetsFilter')
4546
->willReturn(
46-
static fn ($name): bool => $name === 'table_name1',
47+
static fn ($name): bool => in_array($name, ['table_name1', 'table_name2_id_seq'], true),
4748
);
4849

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

65+
$sequence1 = $this->createMock(Sequence::class);
66+
$sequence1->expects(self::once())
67+
->method('getName')
68+
->willReturn('table_name1_id_seq');
69+
70+
$sequence2 = $this->createMock(Sequence::class);
71+
$sequence2->expects(self::once())
72+
->method('getName')
73+
->willReturn('table_name2_id_seq');
74+
6475
$toSchema->expects(self::once())
6576
->method('getTables')
6677
->willReturn([$table1, $table2, $table3]);
6778

79+
$toSchema->expects(self::once())
80+
->method('getSequences')
81+
->willReturn([$sequence1, $sequence2]);
82+
6883
$this->emptySchemaProvider->expects(self::never())
6984
->method('createSchema');
7085

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

98+
$toSchema->expects(self::once())
99+
->method('dropSequence')
100+
->with('table_name1_id_seq');
101+
83102
$schemaDiff = self::createStub(SchemaDiff::class);
84103

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

0 commit comments

Comments
 (0)