diff --git a/src/Command/InstallCommand.php b/src/Command/InstallCommand.php index cbfcad442..6b1d4fd23 100644 --- a/src/Command/InstallCommand.php +++ b/src/Command/InstallCommand.php @@ -198,13 +198,21 @@ class InstallCommand extends Command { $this->io->section('Step 2 of 4: Setting up database.'); + $conn = $this->entityManager->getConnection(); + $databasePlatform = $conn->isConnected() ? $conn->getDatabasePlatform() : null; + // user want to reset everything? Don't care about what is already here if (true === $this->defaultInput->getOption('reset')) { $this->io->text('Dropping database, creating database and schema, clearing the cache'); + $this->runCommand('doctrine:schema:drop', ['--force' => true, '--full-database' => true]); + + if (!$databasePlatform instanceof PostgreSQLPlatform) { + $this->runCommand('doctrine:database:drop', ['--force' => true]); + $this->runCommand('doctrine:database:create'); + } + $this - ->runCommand('doctrine:database:drop', ['--force' => true]) - ->runCommand('doctrine:database:create') ->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true]) ->runCommand('cache:clear') ; @@ -231,11 +239,14 @@ class InstallCommand extends Command if ($this->io->confirm('It appears that your database already exists. Would you like to reset it?', false)) { $this->io->text('Dropping database, creating database and schema...'); - $this - ->runCommand('doctrine:database:drop', ['--force' => true]) - ->runCommand('doctrine:database:create') - ->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true]) - ; + $this->runCommand('doctrine:schema:drop', ['--force' => true, '--full-database' => true]); + + if (!$databasePlatform instanceof PostgreSQLPlatform) { + $this->runCommand('doctrine:database:drop', ['--force' => true]); + $this->runCommand('doctrine:database:create'); + } + + $this->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true]); } elseif ($this->isSchemaPresent()) { if ($this->io->confirm('Seems like your database contains schema. Do you want to reset it?', false)) { $this->io->text('Dropping schema and creating schema...'); diff --git a/tests/Command/InstallCommandTest.php b/tests/Command/InstallCommandTest.php index 4f4f3c790..b2a9ac52d 100644 --- a/tests/Command/InstallCommandTest.php +++ b/tests/Command/InstallCommandTest.php @@ -36,18 +36,6 @@ class InstallCommandTest extends WallabagTestCase /** @var Connection $connection */ $connection = $this->getTestClient()->getContainer()->get(ManagerRegistry::class)->getConnection(); - if ($connection->getDatabasePlatform() instanceof PostgreSQLPlatform) { - /* - * LOG: statement: CREATE DATABASE "wallabag" - * ERROR: source database "template1" is being accessed by other users - * DETAIL: There is 1 other session using the database. - * STATEMENT: CREATE DATABASE "wallabag" - * FATAL: database "wallabag" does not exist - * - * http://stackoverflow.com/a/14374832/569101 - */ - $this->markTestSkipped('PostgreSQL spotted: can\'t find a good way to drop current database, skipping.'); - } if ($connection->getDatabasePlatform() instanceof SqlitePlatform) { // Environnement variable useful only for sqlite to avoid the error "attempt to write a readonly database" @@ -142,6 +130,10 @@ class InstallCommandTest extends WallabagTestCase public function testRunInstallCommandWithDatabaseRemoved() { + if ($this->getTestClient()->getContainer()->get(ManagerRegistry::class)->getConnection()->getDatabasePlatform() instanceof PostgreSQLPlatform) { + $this->markTestSkipped('PostgreSQL spotted: can\'t find a good way to drop current database, skipping.'); + } + if ($this->getTestClient()->getContainer()->get(ManagerRegistry::class)->getConnection()->getDatabasePlatform() instanceof MySQLPlatform) { $this->markTestSkipped('Rollback are not properly handled for MySQL, skipping.'); }