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 841f800
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()) {

Check failure on line 63 in src/SQL/Builder/DropSchemaObjectsSQLBuilder.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (PHP: 8.3)

Expected 1 space after NOT operator; 0 found
return [];
}

$statements = [];

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

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

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 841f800

Please sign in to comment.