Skip to content

Commit c7d4228

Browse files
committed
Apply assets filter on sequences
1 parent 8f900b5 commit c7d4228

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/Doctrine/Migrations/Generator/DiffGenerator.php

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

143143
$toSchema->dropTable($tableName);
144144
}
145+
146+
foreach ($toSchema->getSequences() as $sequence) {
147+
$sequenceName = $sequence->getName();
148+
149+
if ($schemaAssetsFilter($sequenceName)) {
150+
continue;
151+
}
152+
153+
$toSchema->dropSequence($sequenceName);
154+
}
145155
}
146156

147157
return $toSchema;

tests/Doctrine/Migrations/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;
@@ -55,7 +56,7 @@ public function testGenerate(): void
5556
->method('getSchemaAssetsFilter')
5657
->willReturn(
5758
static function ($name): bool {
58-
return $name === 'table_name1';
59+
return in_array($name, ['table_name1', 'table_name2_id_seq'], true);
5960
},
6061
);
6162

@@ -74,10 +75,24 @@ static function ($name): bool {
7475
->method('getName')
7576
->willReturn('schema.table_name3');
7677

78+
$sequence1 = $this->createMock(Sequence::class);
79+
$sequence1->expects(self::once())
80+
->method('getName')
81+
->willReturn('table_name1_id_seq');
82+
83+
$sequence2 = $this->createMock(Sequence::class);
84+
$sequence2->expects(self::once())
85+
->method('getName')
86+
->willReturn('table_name2_id_seq');
87+
7788
$toSchema->expects(self::once())
7889
->method('getTables')
7990
->willReturn([$table1, $table2, $table3]);
8091

92+
$toSchema->expects(self::once())
93+
->method('getSequences')
94+
->willReturn([$sequence1, $sequence2]);
95+
8196
$this->emptySchemaProvider->expects(self::never())
8297
->method('createSchema');
8398

@@ -93,6 +108,10 @@ static function ($name): bool {
93108
->method('dropTable')
94109
->willReturnOnConsecutiveCalls('schema.table_name2', 'schema.table_name3');
95110

111+
$toSchema->expects(self::once())
112+
->method('dropSequence')
113+
->with('table_name1_id_seq');
114+
96115
$schemaDiff = self::createStub(SchemaDiff::class);
97116

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

0 commit comments

Comments
 (0)