diff --git a/Command/CreateDatabaseDoctrineCommand.php b/Command/CreateDatabaseDoctrineCommand.php index e37e1294..ce92f02f 100644 --- a/Command/CreateDatabaseDoctrineCommand.php +++ b/Command/CreateDatabaseDoctrineCommand.php @@ -3,6 +3,7 @@ namespace Doctrine\Bundle\DoctrineBundle\Command; use Doctrine\DBAL\DriverManager; +use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use InvalidArgumentException; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -60,10 +61,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int throw new InvalidArgumentException("Connection does not contain a 'path' or 'dbname' parameter and cannot be created."); } - // Need to get rid of _every_ occurrence of dbname from connection configuration and we have already extracted all relevant info from url + // Need to get rid of _every_ occurrence of dbname from connection configuration as we have already extracted all relevant info from url /** @psalm-suppress InvalidArrayOffset Need to be compatible with DBAL < 4, which still has `$params['url']` */ unset($params['dbname'], $params['path'], $params['url']); + if ($connection->getDatabasePlatform() instanceof PostgreSQLPlatform) { + $params['dbname'] = 'postgres'; + } + $tmpConnection = DriverManager::getConnection($params, $connection->getConfiguration()); $schemaManager = $tmpConnection->createSchemaManager(); $shouldNotCreateDatabase = $ifNotExists && in_array($name, $schemaManager->listDatabases()); diff --git a/Command/DropDatabaseDoctrineCommand.php b/Command/DropDatabaseDoctrineCommand.php index b72c8c0a..05d76202 100644 --- a/Command/DropDatabaseDoctrineCommand.php +++ b/Command/DropDatabaseDoctrineCommand.php @@ -3,6 +3,7 @@ namespace Doctrine\Bundle\DoctrineBundle\Command; use Doctrine\DBAL\DriverManager; +use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\DBAL\Schema\SQLiteSchemaManager; use InvalidArgumentException; use Symfony\Component\Console\Input\InputInterface; @@ -75,6 +76,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int /** @psalm-suppress InvalidArrayOffset Need to be compatible with DBAL < 4, which still has `$params['url']` */ unset($params['dbname'], $params['url']); + if ($connection->getDatabasePlatform() instanceof PostgreSQLPlatform) { + $params['dbname'] = 'postgres'; + } + if (! $input->getOption('force')) { $output->writeln('ATTENTION: This operation should not be executed in a production environment.'); $output->writeln('');