Allow to reuse the same name when installing a new instance

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2016-12-06 19:04:57 +01:00
parent 6cd421e603
commit 7293a4e5ec
No known key found for this signature in database
GPG Key ID: E166FD8976B3BAC8
1 changed files with 9 additions and 7 deletions

View File

@ -150,14 +150,16 @@ class PostgreSQL extends AbstractDatabase {
}
private function createDBUser(IDBConnection $connection) {
$dbUser = $this->dbUser;
try {
if ($this->userExists($connection)) {
// change the password
$query = $connection->prepare("ALTER ROLE " . addslashes($this->dbUser) . " WITH CREATEDB PASSWORD '" . addslashes($this->dbPassword) . "'");
} else {
// create the user
$query = $connection->prepare("CREATE USER " . addslashes($this->dbUser) . " CREATEDB PASSWORD '" . addslashes($this->dbPassword) . "'");
}
$i = 1;
while ($this->userExists($connection)) {
$i++;
$this->dbUser = $dbUser . $i;
};
// create the user
$query = $connection->prepare("CREATE USER " . addslashes($this->dbUser) . " CREATEDB PASSWORD '" . addslashes($this->dbPassword) . "'");
$query->execute();
} catch (DatabaseException $e) {
$this->logger->error('Error while trying to create database user');