]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Fix installation command
authoradev <adev2000@gmail.com>
Sat, 4 Nov 2017 20:23:18 +0000 (21:23 +0100)
committeradev <adev2000@gmail.com>
Tue, 21 Nov 2017 20:35:17 +0000 (21:35 +0100)
app/DoctrineMigrations/Version20160812120952.php
app/DoctrineMigrations/Version20170824113337.php
src/Wallabag/CoreBundle/Command/InstallCommand.php
tests/Wallabag/CoreBundle/Command/InstallCommandTest.php

index 677f30c32c788ecadf51e4587d3939a9dc2c07fd..d28f3a71d0728eca50b92c83bba90506d26b1ddf 100644 (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)
index 7393d683dbf95c571436b6a3daea5bb5225dbb85..e54a9bcf7ea2bcfcd407b72ffa0de63ab9c531a3 100644 (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,
+            ]
+        );
     }
 
     /**
index 877dbfa27a65ee6d8c50763d341a65e05e8b6234..dec2bf9c15c7e6477a65b088a20fb3c6b3212c05 100644 (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.
      *
index f684a20690c43501e55d300e2c967861f0c9a8b4..bd351b187fd2671480c9a5bc262b600e26c572d7 100644 (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());
     }
 }