diff --git a/src/SQL/Builder/DropSchemaObjectsSQLBuilder.php b/src/SQL/Builder/DropSchemaObjectsSQLBuilder.php index c0384897fa2..091b2d6bded 100644 --- a/src/SQL/Builder/DropSchemaObjectsSQLBuilder.php +++ b/src/SQL/Builder/DropSchemaObjectsSQLBuilder.php @@ -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()), ); } @@ -51,4 +52,31 @@ private function buildSequenceStatements(array $sequences): array return $statements; } + + /** + * @param list $namespaces + * + * @return list + */ + private function buildNamespaceStatements(array $namespaces): array + { + if (! $this->platform->supportsSchemas()) { + return []; + } + var_dump(__METHOD__.'()::'.__LINE__); + + $statements = []; + + foreach ($namespaces as $namespace) { + if ($namespace === 'public') { + var_dump(__METHOD__.'()::'.__LINE__); + continue; + } + + $statements[] = $this->platform->getDropSchemaSQL($namespace); + var_dump(__METHOD__.'()::'.__LINE__); + } + + return $statements; + } } diff --git a/tests/Functional/Schema/PostgreSQLSchemaManagerTest.php b/tests/Functional/Schema/PostgreSQLSchemaManagerTest.php index 2480a472163..3fa69d6341a 100644 --- a/tests/Functional/Schema/PostgreSQLSchemaManagerTest.php +++ b/tests/Functional/Schema/PostgreSQLSchemaManagerTest.php @@ -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"');