Skip to content

Commit

Permalink
Fixing #DBAL-1114.
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-todorov committed Apr 8, 2015
1 parent 3bf42bf commit 113ebec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Command/CreateDatabaseDoctrineCommand.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
unset($params['dbname']);

// PDO (postgresql) assumes dbname to be the same as username when it's not defined in the dsn.
// In PostgreSQL this results in an exception because PDO is trying to connect to a non-existing database.
if($params['driver'] == 'pdo_pgsql')
{
$params['dbname'] = 'template1';
}

$tmpConnection = DriverManager::getConnection($params);
$shouldNotCreateDatabase = $ifNotExists && in_array($name, $tmpConnection->getSchemaManager()->listDatabases());

Expand Down
9 changes: 9 additions & 0 deletions Command/DropDatabaseDoctrineCommand.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
// Reopen connection without database name set
// as some vendors do not allow dropping the database connected to.
$connection->close();

// PDO (postgresql) assumes dbname to be the same as username when it's not defined in the dsn.
// In PostgreSQL this results in an exception
// SQLSTATE[55006]: Object in use: 7 ERROR: cannot drop the currently open database
if($params['driver'] == 'pdo_pgsql')
{
$params['dbname'] = 'template1';
}

$connection = DriverManager::getConnection($params);
$shouldDropDatabase = !$ifExists || in_array($name, $connection->getSchemaManager()->listDatabases());

Expand Down

0 comments on commit 113ebec

Please sign in to comment.