Skip to content

Commit ad2a79f

Browse files
committed
fix: add missing drop schema when dropping database
1 parent 7a82524 commit ad2a79f

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/SQL/Builder/DropSchemaObjectsSQLBuilder.php

+21
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public function buildSQL(Schema $schema): array
2323
return array_merge(
2424
$this->buildSequenceStatements($schema->getSequences()),
2525
$this->buildTableStatements($schema->getTables()),
26+
$this->buildNamespaceStatements($schema->getNamespaces()),
2627
);
2728
}
2829

@@ -51,4 +52,24 @@ private function buildSequenceStatements(array $sequences): array
5152

5253
return $statements;
5354
}
55+
56+
/**
57+
* @param list<string> $namespaces
58+
*
59+
* @return list<string>
60+
*/
61+
private function buildNamespaceStatements(array $namespaces): array
62+
{
63+
if (! $this->platform->supportsSchemas()) {
64+
return [];
65+
}
66+
67+
$statements = [];
68+
69+
foreach ($namespaces as $namespace) {
70+
$statements[] = $this->platform->getDropSchemaSQL($namespace);
71+
}
72+
73+
return $statements;
74+
}
5475
}

tests/Functional/Schema/PostgreSQLSchemaManagerTest.php

+19
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,25 @@ public function testDropWithAutoincrement(): void
366366
self::assertFalse($schemaManager->tablesExist(['test_autoincrement']));
367367
}
368368

369+
public function testDropWithSchema(): void
370+
{
371+
$this->dropTableIfExists('some_schema.test_namespace');
372+
373+
$schema = new Schema();
374+
$table = $schema->createTable('some_schema.test_namespace');
375+
$table->addColumn('id', Types::INTEGER, ['notnull' => true]);
376+
$table->setPrimaryKey(['id']);
377+
378+
$schemaManager = $this->connection->createSchemaManager();
379+
$schemaManager->createSchemaObjects($schema);
380+
self::assertSame(['public', 'some_schema'], $schemaManager->listSchemaNames());
381+
382+
$schema = $schemaManager->introspectSchema();
383+
$schemaManager->dropSchemaObjects($schema);
384+
385+
self::assertSame([], $schemaManager->listSchemaNames());
386+
}
387+
369388
public function testListTableDetailsWhenCurrentSchemaNameQuoted(): void
370389
{
371390
$this->connection->executeStatement('CREATE SCHEMA "001_test"');

0 commit comments

Comments
 (0)