Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply assets filter on sequences #1328

Open
wants to merge 1 commit into
base: 3.8.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/Doctrine/Migrations/Generator/DiffGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,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')
->will(self::onConsecutiveCalls('schema.table_name2', 'schema.table_name3'));

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

$schemaDiff = $this->createStub(SchemaDiff::class);

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