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

Create the default namespace in the schema #11658

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 10 additions & 0 deletions src/Tools/SchemaTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use BackedEnum;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Schema\AbstractAsset;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Index;
Expand Down Expand Up @@ -177,6 +178,15 @@ public function getSchemaFromMetadata(array $classes): Schema

$schema = new Schema([], [], $metadataSchemaConfig);

// the platform check should be removed once the support for DBAL 3.x is dropped
// see https://github.com/doctrine/dbal/pull/4821, https://github.com/doctrine/dbal/pull/4831
if ($this->em->getConnection()->getDatabasePlatform() instanceof PostgreSQLPlatform) {
$defaultNamespace = $metadataSchemaConfig->getName();
if ($defaultNamespace !== null) {
$schema->createNamespace($defaultNamespace);
}
}

$addedFks = [];
$blacklistedFks = [];

Expand Down
25 changes: 25 additions & 0 deletions tests/Tests/ORM/Functional/SchemaToolTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional;

use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\Tests\OrmFunctionalTestCase;

class SchemaToolTest extends OrmFunctionalTestCase
{
public function testValidateModelSets(): void
{
$schemaTool = new SchemaTool($this->_em);
$schema = $schemaTool->getSchemaFromMetadata([]);
$namespaces = $schema->getNamespaces();

if ($this->_em->getConnection()->getDatabasePlatform() instanceof PostgreSQLPlatform) {
self::assertContains('public', $namespaces);
} else {
self::assertEmpty($namespaces);
}
}
}
Loading