Fix installation command

This commit is contained in:
adev 2017-11-04 21:23:18 +01:00
parent 2054740fdb
commit 2680b0bc8c
4 changed files with 43 additions and 31 deletions

View file

@ -30,7 +30,20 @@ class Version20160812120952 extends AbstractMigration implements ContainerAwareI
$clientsTable = $schema->getTable($this->getTable('oauth2_clients'));
$this->skipIf($clientsTable->hasColumn('name'), 'It seems that you already played this migration.');
$clientsTable->addColumn('name', 'blob');
if ('sqlite' === $this->connection->getDatabasePlatform()->getName()) {
// Can't use $clientsTable->addColumn('name', 'blob');
// because of the error:
// SQLSTATE[HY000]: General error: 1 Cannot add a NOT NULL column with default value NULL
$databaseTablePrefix = $this->container->getParameter('database_table_prefix');
$this->addSql('CREATE TEMPORARY TABLE __temp__' . $databaseTablePrefix . 'oauth2_clients AS SELECT id, random_id, redirect_uris, secret, allowed_grant_types FROM ' . $databaseTablePrefix . 'oauth2_clients');
$this->addSql('DROP TABLE ' . $databaseTablePrefix . 'oauth2_clients');
$this->addSql('CREATE TABLE ' . $databaseTablePrefix . 'oauth2_clients (id INTEGER NOT NULL, user_id INTEGER DEFAULT NULL, random_id VARCHAR(255) NOT NULL COLLATE BINARY, secret VARCHAR(255) NOT NULL COLLATE BINARY, redirect_uris CLOB NOT NULL, allowed_grant_types CLOB NOT NULL, name CLOB NOT NULL, PRIMARY KEY(id), CONSTRAINT FK_635D765EA76ED395 FOREIGN KEY (user_id) REFERENCES "' . $databaseTablePrefix . 'user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('INSERT INTO ' . $databaseTablePrefix . 'oauth2_clients (id, random_id, redirect_uris, secret, allowed_grant_types) SELECT id, random_id, redirect_uris, secret, allowed_grant_types FROM __temp__' . $databaseTablePrefix . 'oauth2_clients');
$this->addSql('DROP TABLE __temp__' . $databaseTablePrefix . 'oauth2_clients');
$this->addSql('CREATE INDEX IDX_635D765EA76ED395 ON ' . $databaseTablePrefix . 'oauth2_clients (user_id)');
} else {
$clientsTable->addColumn('name', 'blob');
}
}
/**
@ -39,7 +52,18 @@ class Version20160812120952 extends AbstractMigration implements ContainerAwareI
public function down(Schema $schema)
{
$clientsTable = $schema->getTable($this->getTable('oauth2_clients'));
$clientsTable->dropColumn('name');
if ('sqlite' === $this->connection->getDatabasePlatform()->getName()) {
$databaseTablePrefix = $this->container->getParameter('database_table_prefix');
$this->addSql('DROP INDEX IDX_635D765EA76ED395');
$this->addSql('CREATE TEMPORARY TABLE __temp__' . $databaseTablePrefix . 'oauth2_clients AS SELECT id, random_id, redirect_uris, secret, allowed_grant_types FROM ' . $databaseTablePrefix . 'oauth2_clients');
$this->addSql('DROP TABLE ' . $databaseTablePrefix . 'oauth2_clients');
$this->addSql('CREATE TABLE ' . $databaseTablePrefix . 'oauth2_clients (id INTEGER NOT NULL, random_id VARCHAR(255) NOT NULL, secret VARCHAR(255) NOT NULL, redirect_uris CLOB NOT NULL COLLATE BINARY, allowed_grant_types CLOB NOT NULL COLLATE BINARY, PRIMARY KEY(id))');
$this->addSql('INSERT INTO ' . $databaseTablePrefix . 'oauth2_clients (id, random_id, redirect_uris, secret, allowed_grant_types) SELECT id, random_id, redirect_uris, secret, allowed_grant_types FROM __temp__' . $databaseTablePrefix . 'oauth2_clients');
$this->addSql('DROP TABLE __temp__' . $databaseTablePrefix . 'oauth2_clients');
} else {
$clientsTable->dropColumn('name');
}
}
private function getTable($tableName)

View file

@ -41,7 +41,12 @@ class Version20170824113337 extends AbstractMigration implements ContainerAwareI
$entryTable = $schema->getTable($this->getTable('entry'));
$this->skipIf(!$entryTable->hasColumn('starred_at'), 'Unable to add starred_at colum');
$this->connection->executeQuery('UPDATE ' . $this->getTable('entry') . ' SET starred_at = updated_at WHERE is_starred = true');
$this->connection->executeQuery(
'UPDATE ' . $this->getTable('entry') . ' SET starred_at = updated_at WHERE is_starred = :is_starred',
[
'is_starred' => true,
]
);
}
/**

View file

@ -61,7 +61,6 @@ class InstallCommand extends ContainerAwareCommand
->setupDatabase()
->setupAdmin()
->setupConfig()
->runMigrations()
;
$this->io->success('Wallabag has been successfully installed.');
@ -70,7 +69,7 @@ class InstallCommand extends ContainerAwareCommand
protected function checkRequirements()
{
$this->io->section('Step 1 of 5: Checking system requirements.');
$this->io->section('Step 1 of 4: Checking system requirements.');
$doctrineManager = $this->getContainer()->get('doctrine')->getManager();
@ -169,7 +168,7 @@ class InstallCommand extends ContainerAwareCommand
protected function setupDatabase()
{
$this->io->section('Step 2 of 5: Setting up database.');
$this->io->section('Step 2 of 4: Setting up database.');
// user want to reset everything? Don't care about what is already here
if (true === $this->defaultInput->getOption('reset')) {
@ -178,7 +177,7 @@ class InstallCommand extends ContainerAwareCommand
$this
->runCommand('doctrine:database:drop', ['--force' => true])
->runCommand('doctrine:database:create')
->runCommand('doctrine:schema:create')
->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true])
->runCommand('cache:clear')
;
@ -192,7 +191,7 @@ class InstallCommand extends ContainerAwareCommand
$this
->runCommand('doctrine:database:create')
->runCommand('doctrine:schema:create')
->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true])
->runCommand('cache:clear')
;
@ -207,7 +206,7 @@ class InstallCommand extends ContainerAwareCommand
$this
->runCommand('doctrine:database:drop', ['--force' => true])
->runCommand('doctrine:database:create')
->runCommand('doctrine:schema:create')
->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)) {
@ -215,14 +214,14 @@ class InstallCommand extends ContainerAwareCommand
$this
->runCommand('doctrine:schema:drop', ['--force' => true])
->runCommand('doctrine:schema:create')
->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true])
;
}
} else {
$this->io->text('Creating schema...');
$this
->runCommand('doctrine:schema:create')
->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true])
;
}
@ -237,7 +236,7 @@ class InstallCommand extends ContainerAwareCommand
protected function setupAdmin()
{
$this->io->section('Step 3 of 5: Administration setup.');
$this->io->section('Step 3 of 4: Administration setup.');
if (!$this->io->confirm('Would you like to create a new admin user (recommended)?', true)) {
return $this;
@ -272,7 +271,7 @@ class InstallCommand extends ContainerAwareCommand
protected function setupConfig()
{
$this->io->section('Step 4 of 5: Config setup.');
$this->io->section('Step 4 of 4: Config setup.');
$em = $this->getContainer()->get('doctrine.orm.entity_manager');
// cleanup before insert new stuff
@ -293,18 +292,6 @@ class InstallCommand extends ContainerAwareCommand
return $this;
}
protected function runMigrations()
{
$this->io->section('Step 5 of 5: Run migrations.');
$this
->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true]);
$this->io->text('<info>Migrations successfully executed.</info>');
return $this;
}
/**
* Run a command.
*

View file

@ -5,6 +5,7 @@ namespace Tests\Wallabag\CoreBundle\Command;
use DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver;
use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand;
use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand;
use Doctrine\Bundle\MigrationsBundle\Command\MigrationsMigrateDoctrineCommand;
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Symfony\Bundle\FrameworkBundle\Console\Application;
@ -98,7 +99,6 @@ class InstallCommandTest extends WallabagCoreTestCase
$this->assertContains('Setting up database.', $tester->getDisplay());
$this->assertContains('Administration setup.', $tester->getDisplay());
$this->assertContains('Config setup.', $tester->getDisplay());
$this->assertContains('Run migrations.', $tester->getDisplay());
}
public function testRunInstallCommandWithReset()
@ -125,7 +125,6 @@ class InstallCommandTest extends WallabagCoreTestCase
$this->assertContains('Dropping database, creating database and schema, clearing the cache', $tester->getDisplay());
$this->assertContains('Administration setup.', $tester->getDisplay());
$this->assertContains('Config setup.', $tester->getDisplay());
$this->assertContains('Run migrations.', $tester->getDisplay());
// we force to reset everything
$this->assertContains('Dropping database, creating database and schema, clearing the cache', $tester->getDisplay());
@ -171,7 +170,6 @@ class InstallCommandTest extends WallabagCoreTestCase
$this->assertContains('Setting up database.', $tester->getDisplay());
$this->assertContains('Administration setup.', $tester->getDisplay());
$this->assertContains('Config setup.', $tester->getDisplay());
$this->assertContains('Run migrations.', $tester->getDisplay());
// the current database doesn't already exist
$this->assertContains('Creating database and schema, clearing the cache', $tester->getDisplay());
@ -198,7 +196,6 @@ class InstallCommandTest extends WallabagCoreTestCase
$this->assertContains('Setting up database.', $tester->getDisplay());
$this->assertContains('Administration setup.', $tester->getDisplay());
$this->assertContains('Config setup.', $tester->getDisplay());
$this->assertContains('Run migrations.', $tester->getDisplay());
$this->assertContains('Dropping schema and creating schema', $tester->getDisplay());
}
@ -209,6 +206,7 @@ class InstallCommandTest extends WallabagCoreTestCase
$application->add(new InstallCommand());
$application->add(new DropDatabaseDoctrineCommand());
$application->add(new CreateDatabaseDoctrineCommand());
$application->add(new MigrationsMigrateDoctrineCommand());
// drop database first, so the install command won't ask to reset things
$command = new DropDatabaseDoctrineCommand();
@ -242,7 +240,6 @@ class InstallCommandTest extends WallabagCoreTestCase
$this->assertContains('Setting up database.', $tester->getDisplay());
$this->assertContains('Administration setup.', $tester->getDisplay());
$this->assertContains('Config setup.', $tester->getDisplay());
$this->assertContains('Run migrations.', $tester->getDisplay());
$this->assertContains('Creating schema', $tester->getDisplay());
}
@ -265,6 +262,5 @@ class InstallCommandTest extends WallabagCoreTestCase
$this->assertContains('Setting up database.', $tester->getDisplay());
$this->assertContains('Administration setup.', $tester->getDisplay());
$this->assertContains('Config setup.', $tester->getDisplay());
$this->assertContains('Run migrations.', $tester->getDisplay());
}
}