Make install command better support PostgreSQL

This commit is contained in:
Yassine Guedidi 2024-01-21 01:47:06 +01:00
parent 96cb024cf5
commit 49df7d8c52
2 changed files with 22 additions and 19 deletions

View file

@ -198,13 +198,21 @@ class InstallCommand extends Command
{ {
$this->io->section('Step 2 of 4: Setting up database.'); $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 // user want to reset everything? Don't care about what is already here
if (true === $this->defaultInput->getOption('reset')) { if (true === $this->defaultInput->getOption('reset')) {
$this->io->text('Dropping database, creating database and schema, clearing the cache'); $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 $this
->runCommand('doctrine:database:drop', ['--force' => true])
->runCommand('doctrine:database:create')
->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true]) ->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true])
->runCommand('cache:clear') ->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)) { 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->io->text('Dropping database, creating database and schema...');
$this $this->runCommand('doctrine:schema:drop', ['--force' => true, '--full-database' => true]);
->runCommand('doctrine:database:drop', ['--force' => true])
->runCommand('doctrine:database:create') if (!$databasePlatform instanceof PostgreSQLPlatform) {
->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true]) $this->runCommand('doctrine:database:drop', ['--force' => true]);
; $this->runCommand('doctrine:database:create');
}
$this->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true]);
} elseif ($this->isSchemaPresent()) { } elseif ($this->isSchemaPresent()) {
if ($this->io->confirm('Seems like your database contains schema. Do you want to reset it?', false)) { 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...'); $this->io->text('Dropping schema and creating schema...');

View file

@ -36,18 +36,6 @@ class InstallCommandTest extends WallabagTestCase
/** @var Connection $connection */ /** @var Connection $connection */
$connection = $this->getTestClient()->getContainer()->get(ManagerRegistry::class)->getConnection(); $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) { if ($connection->getDatabasePlatform() instanceof SqlitePlatform) {
// Environnement variable useful only for sqlite to avoid the error "attempt to write a readonly database" // 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() 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) { if ($this->getTestClient()->getContainer()->get(ManagerRegistry::class)->getConnection()->getDatabasePlatform() instanceof MySQLPlatform) {
$this->markTestSkipped('Rollback are not properly handled for MySQL, skipping.'); $this->markTestSkipped('Rollback are not properly handled for MySQL, skipping.');
} }