Skip to content

Commit

Permalink
fix: add missing drop schema when dropping database
Browse files Browse the repository at this point in the history
  • Loading branch information
nikophil committed Dec 18, 2024
1 parent 7a82524 commit cca8165
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/SQL/Builder/DropSchemaObjectsSQLBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function buildSQL(Schema $schema): array
return array_merge(
$this->buildSequenceStatements($schema->getSequences()),
$this->buildTableStatements($schema->getTables()),
$this->buildNamespaceStatements($schema->getNamespaces()),
);
}

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

return $statements;
}

/**
* @param list<string> $namespaces
*
* @return list<string>
*/
private function buildNamespaceStatements(array $namespaces): array
{
if (! $this->platform->supportsSchemas()) {
return [];
}

$statements = [];

foreach ($namespaces as $namespace) {
$statements[] = $this->platform->getDropSchemaSQL($namespace);
}

return $statements;
}
}
25 changes: 25 additions & 0 deletions tests/Functional/Schema/SchemaManagerFunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,31 @@ public function testDropColumnWithDefault(): void
self::assertCount(1, $columns);
}

public function testDropWithSchema(): void
{
$platform = $this->connection->getDatabasePlatform();

if (! $platform->supportsSchemas()) {
self::markTestSkipped('The platform does not support schemas/namespaces.');
}

$this->dropTableIfExists('some_schema.test_namespace');

$schema = new Schema();
$table = $schema->createTable('some_schema.test_namespace');
$table->addColumn('id', Types::INTEGER, ['notnull' => true]);
$table->setPrimaryKey(['id']);

$schemaManager = $this->connection->createSchemaManager();
$schemaManager->createSchemaObjects($schema);
self::assertSame(['public', 'some_schema'], $schemaManager->listSchemaNames());

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

self::assertSame([], $schemaManager->listSchemaNames());
}

/** @param list<Table> $tables */
protected function findTableByName(array $tables, string $name): ?Table
{
Expand Down

0 comments on commit cca8165

Please sign in to comment.