Skip to content

Commit 4fdbc3b

Browse files
committed
Apply assets filter on sequences
1 parent 7780f8d commit 4fdbc3b

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-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

+22-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;
@@ -18,6 +19,8 @@
1819
use PHPUnit\Framework\MockObject\MockObject;
1920
use PHPUnit\Framework\TestCase;
2021

22+
use function in_array;
23+
2124
class DiffGeneratorTest extends TestCase
2225
{
2326
private DBALConfiguration&MockObject $dbalConfiguration;
@@ -43,7 +46,7 @@ public function testGenerate(): void
4346
$this->dbalConfiguration->expects(self::once())
4447
->method('getSchemaAssetsFilter')
4548
->willReturn(
46-
static fn ($name): bool => $name === 'table_name1',
49+
static fn ($name): bool => in_array($name, ['table_name1', 'table_name2_id_seq'], true),
4750
);
4851

4952
$table1 = $this->createMock(Table::class);
@@ -61,10 +64,24 @@ public function testGenerate(): void
6164
->method('getName')
6265
->willReturn('schema.table_name3');
6366

67+
$sequence1 = $this->createMock(Sequence::class);
68+
$sequence1->expects(self::once())
69+
->method('getName')
70+
->willReturn('table_name1_id_seq');
71+
72+
$sequence2 = $this->createMock(Sequence::class);
73+
$sequence2->expects(self::once())
74+
->method('getName')
75+
->willReturn('table_name2_id_seq');
76+
6477
$toSchema->expects(self::once())
6578
->method('getTables')
6679
->willReturn([$table1, $table2, $table3]);
6780

81+
$toSchema->expects(self::once())
82+
->method('getSequences')
83+
->willReturn([$sequence1, $sequence2]);
84+
6885
$this->emptySchemaProvider->expects(self::never())
6986
->method('createSchema');
7087

@@ -80,6 +97,10 @@ public function testGenerate(): void
8097
->method('dropTable')
8198
->willReturnSelf();
8299

100+
$toSchema->expects(self::once())
101+
->method('dropSequence')
102+
->with('table_name1_id_seq');
103+
83104
$schemaDiff = self::createStub(SchemaDiff::class);
84105

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

0 commit comments

Comments
 (0)