Skip to content

Commit

Permalink
When dropping schema, drop sequences before tables
Browse files Browse the repository at this point in the history
When dropping a schema, the DBAL explicitly drops all schema sequences,
even if they are owned by one of the tables being dropped.

As a workaround for the regression, we will drop sequences first,
which is how it is implemented in `DropSchemaSqlCollector`.

Co-authored-by: HypeMC <hypemc@gmail.com>
  • Loading branch information
morozov and HypeMC committed Aug 20, 2022
1 parent 94e0164 commit c3d0706
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/SQL/Builder/DropSchemaObjectsSQLBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public function __construct(AbstractPlatform $platform)
public function buildSQL(Schema $schema): array
{
return array_merge(
$this->buildTableStatements($schema->getTables()),
$this->buildSequenceStatements($schema->getSequences()),
$this->buildTableStatements($schema->getTables()),
$this->buildNamespaceStatements($schema->getNamespaces()),
);
}
Expand Down
21 changes: 21 additions & 0 deletions tests/Functional/Schema/SchemaManagerFunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,27 @@ public function testPrimaryKeyAutoIncrement(): void
self::assertGreaterThan($lastUsedIdBeforeDelete, $lastUsedIdAfterDelete);
}

public function testDropWithAutoincrement(): void
{
$this->dropTableIfExists('test_autoincrement');

$schema = new Schema();
$table = $schema->createTable('test_autoincrement');
$table->addColumn('id', 'integer', [
'notnull' => true,
'autoincrement' => true,
]);
$table->setPrimaryKey(['id']);

$schemaManager = $this->connection->createSchemaManager();
$schemaManager->createSchemaObjects($schema);

$schema = $schemaManager->createSchema();
$schemaManager->dropSchemaObjects($schema);

self::assertFalse($schemaManager->tablesExist(['test_autoincrement']));
}

public function testGenerateAnIndexWithPartialColumnLength(): void
{
if (! $this->connection->getDatabasePlatform()->supportsColumnLengthIndexes()) {
Expand Down

0 comments on commit c3d0706

Please sign in to comment.