Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add missing drop schema when dropping database #6576

Open
wants to merge 1 commit into
base: 4.2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
return array_merge(
$this->buildSequenceStatements($schema->getSequences()),
$this->buildTableStatements($schema->getTables()),
$this->buildNamespaceStatements($schema->getNamespaces()),
);
}

Expand Down Expand Up @@ -51,4 +52,24 @@

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) {
$statements[] = $this->platform->getDropSchemaSQL($namespace);

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

View check run for this annotation

Codecov / codecov/patch

src/SQL/Builder/DropSchemaObjectsSQLBuilder.php#L70

Added line #L70 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the code affects all platforms, the test should cover all platforms as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @morozov

I'm OK with this, but I'm stucked because I don't know how to resolve this problem

{
$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());
}

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