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 Oct 27, 2024
1 parent 7a82524 commit 1944fff
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
25 changes: 25 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,28 @@ 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 [];

Check warning on line 64 in src/SQL/Builder/DropSchemaObjectsSQLBuilder.php

View check run for this annotation

Codecov / codecov/patch

src/SQL/Builder/DropSchemaObjectsSQLBuilder.php#L64

Added line #L64 was not covered by tests
}

$statements = [];

foreach ($namespaces as $namespace) {
if ($namespace === 'public') {
continue;

Check warning on line 71 in src/SQL/Builder/DropSchemaObjectsSQLBuilder.php

View check run for this annotation

Codecov / codecov/patch

src/SQL/Builder/DropSchemaObjectsSQLBuilder.php#L70-L71

Added lines #L70 - L71 were not covered by tests
}

$statements[] = $this->platform->getDropSchemaSQL($namespace);

Check warning on line 74 in src/SQL/Builder/DropSchemaObjectsSQLBuilder.php

View check run for this annotation

Codecov / codecov/patch

src/SQL/Builder/DropSchemaObjectsSQLBuilder.php#L74

Added line #L74 was not covered by tests
}

return $statements;
}
}
19 changes: 19 additions & 0 deletions tests/Functional/Schema/PostgreSQLSchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,25 @@ public function testDropWithAutoincrement(): void
self::assertFalse($schemaManager->tablesExist(['test_autoincrement']));
}

public function testDropWithSchema(): void
{
$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(['public'], $schemaManager->listSchemaNames());
}

public function testListTableDetailsWhenCurrentSchemaNameQuoted(): void
{
$this->connection->executeStatement('CREATE SCHEMA "001_test"');
Expand Down

0 comments on commit 1944fff

Please sign in to comment.