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 30, 2024
1 parent 7a82524 commit bc07845
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
28 changes: 28 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,31 @@ 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 line after "if", found 0.
return [];
}
var_dump(__METHOD__.'()::'.__LINE__);

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

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm (8.3)

ForbiddenCode

src/SQL/Builder/DropSchemaObjectsSQLBuilder.php:66:9: ForbiddenCode: Unsafe var_dump (see https://psalm.dev/002)

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

View workflow job for this annotation

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

Function var_dump() should not be referenced via a fallback global name, but via a use statement.

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

View workflow job for this annotation

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

Expected at least 1 space before "."; 0 found

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

View workflow job for this annotation

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

Expected at least 1 space after "."; 0 found

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

View workflow job for this annotation

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

Concat operator must be surrounded by a single space

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

View workflow job for this annotation

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

Expected at least 1 space before "."; 0 found

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

View workflow job for this annotation

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

Expected at least 1 space after "."; 0 found

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

View workflow job for this annotation

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

Concat operator must be surrounded by a single space

$statements = [];

foreach ($namespaces as $namespace) {
if ($namespace === 'public') {
var_dump(__METHOD__.'()::'.__LINE__);

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

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm (8.3)

ForbiddenCode

src/SQL/Builder/DropSchemaObjectsSQLBuilder.php:72:17: ForbiddenCode: Unsafe var_dump (see https://psalm.dev/002)

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

View workflow job for this annotation

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

Function var_dump() should not be referenced via a fallback global name, but via a use statement.

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

View workflow job for this annotation

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

Expected at least 1 space before "."; 0 found
continue;
}

$statements[] = $this->platform->getDropSchemaSQL($namespace);
var_dump(__METHOD__.'()::'.__LINE__);

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

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm (8.3)

ForbiddenCode

src/SQL/Builder/DropSchemaObjectsSQLBuilder.php:77:13: ForbiddenCode: Unsafe var_dump (see https://psalm.dev/002)
}

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 bc07845

Please sign in to comment.