$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');
+ }
}
/**
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)
$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,
+ ]
+ );
}
/**
->setupDatabase()
->setupAdmin()
->setupConfig()
- ->runMigrations()
;
$this->io->success('Wallabag has been successfully installed.');
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();
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')) {
$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')
;
$this
->runCommand('doctrine:database:create')
- ->runCommand('doctrine:schema:create')
+ ->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true])
->runCommand('cache:clear')
;
$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)) {
$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])
;
}
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;
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
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.
*
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;
$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()
$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());
$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());
$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());
}
$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();
$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());
}
$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());
}
}