]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Merge pull request #2650 from wallabag/add-hascolumn
authorJeremy Benoist <j0k3r@users.noreply.github.com>
Wed, 30 Nov 2016 13:17:40 +0000 (14:17 +0100)
committerGitHub <noreply@github.com>
Wed, 30 Nov 2016 13:17:40 +0000 (14:17 +0100)
Added hasColumn() in migration to check column existence

14 files changed:
app/DoctrineMigrations/Version20160410190541.php
app/DoctrineMigrations/Version20160812120952.php
app/DoctrineMigrations/Version20160911214952.php
app/DoctrineMigrations/Version20160916201049.php
app/DoctrineMigrations/Version20161001072726.php
app/DoctrineMigrations/Version20161022134138.php
app/DoctrineMigrations/Version20161024212538.php
app/DoctrineMigrations/Version20161031132655.php
app/DoctrineMigrations/Version20161104073720.php
app/DoctrineMigrations/Version20161106113822.php
app/DoctrineMigrations/Version20161117071626.php
app/DoctrineMigrations/Version20161118134328.php
app/DoctrineMigrations/Version20161122144743.php
app/DoctrineMigrations/Version20161122203647.php

index f034b0e467b46c83ffc67e393adfc6737c9b6845..0cdec00852dd1a715a9898dd7e5c02d56f06b0d4 100644 (file)
@@ -21,7 +21,7 @@ class Version20160410190541 extends AbstractMigration implements ContainerAwareI
 
     private function getTable($tableName)
     {
-        return $this->container->getParameter('database_table_prefix') . $tableName;
+        return $this->container->getParameter('database_table_prefix').$tableName;
     }
 
     /**
@@ -29,13 +29,14 @@ class Version20160410190541 extends AbstractMigration implements ContainerAwareI
      */
     public function up(Schema $schema)
     {
-        if ($this->connection->getDatabasePlatform()->getName() == 'postgresql') {
-            $this->addSql('ALTER TABLE "'.$this->getTable('entry').'" ADD uuid UUID DEFAULT NULL');
-        } else {
-            $this->addSql('ALTER TABLE "'.$this->getTable('entry').'" ADD uuid LONGTEXT DEFAULT NULL');
-        }
+        $entryTable = $schema->getTable($this->getTable('entry'));
 
-        $this->addSql("INSERT INTO \"".$this->getTable('craue_config_setting')."\" (name, value, section) VALUES ('share_public', '1', 'entry')");
+        $this->skipIf($entryTable->hasColumn('uuid'), 'It seems that you already played this migration.');
+
+        $entryTable->addColumn('uuid', 'guid', [
+            'notnull' => false,
+        ]);
+        $this->addSql('INSERT INTO '.$this->getTable('craue_config_setting')." (name, value, section) VALUES ('share_public', '1', 'entry')");
     }
 
     /**
@@ -43,9 +44,9 @@ class Version20160410190541 extends AbstractMigration implements ContainerAwareI
      */
     public function down(Schema $schema)
     {
-        $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'sqlite', 'This down migration can\'t be executed on SQLite databases, because SQLite don\'t support DROP COLUMN.');
+        $entryTable = $schema->getTable($this->getTable('entry'));
+        $entryTable->dropColumn('uuid');
 
-        $this->addSql('ALTER TABLE "'.$this->getTable('entry').'" DROP uuid');
-        $this->addSql("DELETE FROM \"".$this->getTable('craue_config_setting')."\" WHERE name = 'share_public'");
+        $this->addSql('DELETE FROM '.$this->getTable('craue_config_setting')." WHERE name = 'share_public'");
     }
 }
index 39423e2f56d1a9eb8004bc01bb82f373435bb8c2..053b8d889c736baf3030d0c89c1ffdcbdb357af6 100644 (file)
@@ -21,7 +21,7 @@ class Version20160812120952 extends AbstractMigration implements ContainerAwareI
 
     private function getTable($tableName)
     {
-        return $this->container->getParameter('database_table_prefix') . $tableName;
+        return $this->container->getParameter('database_table_prefix').$tableName;
     }
 
     /**
@@ -29,18 +29,10 @@ class Version20160812120952 extends AbstractMigration implements ContainerAwareI
      */
     public function up(Schema $schema)
     {
-        switch ($this->connection->getDatabasePlatform()->getName()) {
-            case 'sqlite':
-                $this->addSql('ALTER TABLE '.$this->getTable('oauth2_clients').' ADD name longtext DEFAULT NULL');
-                break;
-
-            case 'mysql':
-                $this->addSql('ALTER TABLE '.$this->getTable('oauth2_clients').' ADD name longtext COLLATE \'utf8_unicode_ci\' DEFAULT NULL');
-                break;
-
-            case 'postgresql':
-                $this->addSql('ALTER TABLE '.$this->getTable('oauth2_clients').' ADD name text DEFAULT NULL');
-        }
+        $clientsTable = $schema->getTable($this->getTable('oauth2_clients'));
+        $this->skipIf($clientsTable->hasColumn('name'), 'It seems that you already played this migration.');
+
+        $clientsTable->addColumn('name', 'blob');
     }
 
     /**
@@ -48,8 +40,7 @@ class Version20160812120952 extends AbstractMigration implements ContainerAwareI
      */
     public function down(Schema $schema)
     {
-        $this->abortIf($this->connection->getDatabasePlatform()->getName() == 'sqlite', 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.');
-
-        $this->addSql('ALTER TABLE '.$this->getTable('oauth2_clients').' DROP COLUMN name');
+        $clientsTable = $schema->getTable($this->getTable('oauth2_clients'));
+        $clientsTable->dropColumn('name');
     }
 }
index f14f7bc6f825a61564f4e376f402f2328ccb4675..963821ae81ee6c4cf1c97661a2bcae2eeed642fe 100644 (file)
@@ -21,7 +21,7 @@ class Version20160911214952 extends AbstractMigration implements ContainerAwareI
 
     private function getTable($tableName)
     {
-        return $this->container->getParameter('database_table_prefix') . $tableName;
+        return $this->container->getParameter('database_table_prefix').$tableName;
     }
 
     /**
@@ -29,8 +29,8 @@ class Version20160911214952 extends AbstractMigration implements ContainerAwareI
      */
     public function up(Schema $schema)
     {
-        $this->addSql('INSERT INTO "'.$this->getTable('craue_config_setting').'" (name, value, section) VALUES (\'import_with_redis\', \'0\', \'import\')');
-        $this->addSql('INSERT INTO "'.$this->getTable('craue_config_setting').'" (name, value, section) VALUES (\'import_with_rabbitmq\', \'0\', \'import\')');
+        $this->addSql('INSERT INTO '.$this->getTable('craue_config_setting')." (name, value, section) VALUES ('import_with_redis', 0, 'import')");
+        $this->addSql('INSERT INTO '.$this->getTable('craue_config_setting')." (name, value, section) VALUES ('import_with_rabbitmq', 0, 'import')");
     }
 
     /**
@@ -38,5 +38,7 @@ class Version20160911214952 extends AbstractMigration implements ContainerAwareI
      */
     public function down(Schema $schema)
     {
+        $this->addSql('DELETE FROM '.$this->getTable('craue_config_setting')." WHERE name = 'import_with_redis';");
+        $this->addSql('DELETE FROM '.$this->getTable('craue_config_setting')." WHERE name = 'import_with_rabbitmq';");
     }
 }
index 0d2edf9ef47069b664eaacaf11c46530c6709315..9390755ea0ee526655268224e4c4d56c599146b8 100644 (file)
@@ -21,7 +21,7 @@ class Version20160916201049 extends AbstractMigration implements ContainerAwareI
 
     private function getTable($tableName)
     {
-        return $this->container->getParameter('database_table_prefix') . $tableName;
+        return $this->container->getParameter('database_table_prefix').$tableName;
     }
 
     /**
@@ -29,8 +29,12 @@ class Version20160916201049 extends AbstractMigration implements ContainerAwareI
      */
     public function up(Schema $schema)
     {
-        $this->addSql('ALTER TABLE "'.$this->getTable('config').'" ADD pocket_consumer_key VARCHAR(255) DEFAULT NULL');
-        $this->addSql("DELETE FROM \"".$this->getTable('craue_config_setting')."\" WHERE name = 'pocket_consumer_key';");
+        $configTable = $schema->getTable($this->getTable('config'));
+
+        $this->skipIf($configTable->hasColumn('pocket_consumer_key'), 'It seems that you already played this migration.');
+
+        $configTable->addColumn('pocket_consumer_key', 'string');
+        $this->addSql('DELETE FROM '.$this->getTable('craue_config_setting')." WHERE name = 'pocket_consumer_key';");
     }
 
     /**
@@ -38,9 +42,8 @@ class Version20160916201049 extends AbstractMigration implements ContainerAwareI
      */
     public function down(Schema $schema)
     {
-        $this->abortIf($this->connection->getDatabasePlatform()->getName() == 'sqlite', 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.');
-
-        $this->addSql('ALTER TABLE "'.$this->getTable('config').'" DROP pocket_consumer_key');
-        $this->addSql("INSERT INTO \"".$this->getTable('craue_config_setting')."\" (name, value, section) VALUES ('pocket_consumer_key', NULL, 'import')");
+        $configTable = $schema->getTable($this->getTable('config'));
+        $configTable->dropColumn('pocket_consumer_key');
+        $this->addSql('INSERT INTO '.$this->getTable('craue_config_setting')." (name, value, section) VALUES ('pocket_consumer_key', NULL, 'import')");
     }
 }
index 237db93206d45bbba72c4357d3425a7275aa0a6c..5ab88555c2bc3225ab4c31245ea141215533f8e4 100644 (file)
@@ -21,7 +21,7 @@ class Version20161001072726 extends AbstractMigration implements ContainerAwareI
 
     private function getTable($tableName)
     {
-        return $this->container->getParameter('database_table_prefix') . $tableName;
+        return $this->container->getParameter('database_table_prefix').$tableName;
     }
 
     /**
index 5cce55a5eca39e4169040ca3bb933efe86348e1e..b3d02b407ace5c4b6bc5d732208d71e4208dec0c 100644 (file)
@@ -21,7 +21,7 @@ class Version20161022134138 extends AbstractMigration implements ContainerAwareI
 
     private function getTable($tableName)
     {
-        return $this->container->getParameter('database_table_prefix') . $tableName;
+        return $this->container->getParameter('database_table_prefix').$tableName;
     }
 
     /**
@@ -72,6 +72,5 @@ class Version20161022134138 extends AbstractMigration implements ContainerAwareI
         $this->addSql('ALTER TABLE '.$this->getTable('tag').' CHANGE `label` `label` longtext CHARACTER SET utf8 COLLATE utf8_unicode_ci;');
 
         $this->addSql('ALTER TABLE '.$this->getTable('user').' CHANGE `name` `name` longtext CHARACTER SET utf8 COLLATE utf8_unicode_ci;');
-
     }
 }
index f8e927e478d3276251a1230572cd52e6f1b130bf..75ff86f1fa40602870e851d1ab72985fc21240f1 100644 (file)
@@ -21,7 +21,7 @@ class Version20161024212538 extends AbstractMigration implements ContainerAwareI
 
     private function getTable($tableName)
     {
-        return $this->container->getParameter('database_table_prefix') . $tableName;
+        return $this->container->getParameter('database_table_prefix').$tableName;
     }
 
     /**
@@ -29,10 +29,18 @@ class Version20161024212538 extends AbstractMigration implements ContainerAwareI
      */
     public function up(Schema $schema)
     {
-        $this->skipIf($this->connection->getDatabasePlatform()->getName() == 'sqlite', 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.');
+        $clientsTable = $schema->getTable($this->getTable('oauth2_clients'));
 
-        $this->addSql('ALTER TABLE '.$this->getTable('oauth2_clients').' ADD user_id INT(11) DEFAULT NULL');
-        $this->addSql('ALTER TABLE '.$this->getTable('oauth2_clients').' ADD CONSTRAINT FK_clients_user_clients FOREIGN KEY (user_id) REFERENCES '.$this->getTable('user').' (id) ON DELETE CASCADE');
+        $this->skipIf($clientsTable->hasColumn('user_id'), 'It seems that you already played this migration.');
+
+        $clientsTable->addColumn('user_id', 'integer');
+
+        $clientsTable->addForeignKeyConstraint(
+            $this->getTable('user'),
+            ['user_id'],
+            ['id'],
+            ['onDelete' => 'CASCADE']
+        );
     }
 
     /**
@@ -40,6 +48,5 @@ class Version20161024212538 extends AbstractMigration implements ContainerAwareI
      */
     public function down(Schema $schema)
     {
-
     }
 }
index c73644288e6b009e3ea46636f46ca8cf00d52fc6..39b85ea9759f979a913ea0fb84271ebe46914762 100644 (file)
@@ -21,7 +21,7 @@ class Version20161031132655 extends AbstractMigration implements ContainerAwareI
 
     private function getTable($tableName)
     {
-        return $this->container->getParameter('database_table_prefix') . $tableName;
+        return $this->container->getParameter('database_table_prefix').$tableName;
     }
 
     /**
@@ -29,7 +29,7 @@ class Version20161031132655 extends AbstractMigration implements ContainerAwareI
      */
     public function up(Schema $schema)
     {
-        $this->addSql("INSERT INTO \"".$this->getTable('craue_config_setting')."\" (name, value, section) VALUES ('download_images_enabled', 0, 'misc')");
+        $this->addSql('INSERT INTO "'.$this->getTable('craue_config_setting')."\" (name, value, section) VALUES ('download_images_enabled', 0, 'misc')");
     }
 
     /**
@@ -37,8 +37,6 @@ class Version20161031132655 extends AbstractMigration implements ContainerAwareI
      */
     public function down(Schema $schema)
     {
-        $this->abortIf($this->connection->getDatabasePlatform()->getName() == 'sqlite', 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.');
-
-        $this->addSql("DELETE FROM \"".$this->getTable('craue_config_setting')."\" WHERE name = 'download_images_enabled';");
+        $this->addSql('DELETE FROM "'.$this->getTable('craue_config_setting')."\" WHERE name = 'download_images_enabled';");
     }
 }
index 16503b4b05d9ce6bbc655020d7f192fe4d2315d9..4721426a406aa093b0142eb2ae0888699de5ec76 100644 (file)
@@ -14,6 +14,8 @@ class Version20161104073720 extends AbstractMigration implements ContainerAwareI
      */
     private $container;
 
+    private $indexName = 'IDX_entry_created_at';
+
     public function setContainer(ContainerInterface $container = null)
     {
         $this->container = $container;
@@ -21,7 +23,7 @@ class Version20161104073720 extends AbstractMigration implements ContainerAwareI
 
     private function getTable($tableName)
     {
-        return $this->container->getParameter('database_table_prefix') . $tableName;
+        return $this->container->getParameter('database_table_prefix').$tableName;
     }
 
     /**
@@ -29,18 +31,10 @@ class Version20161104073720 extends AbstractMigration implements ContainerAwareI
      */
     public function up(Schema $schema)
     {
-        switch ($this->connection->getDatabasePlatform()->getName()) {
-            case 'sqlite':
-                $this->addSql('CREATE INDEX `created_at` ON `'.$this->getTable('entry').'` (`created_at` DESC)');
-                break;
-
-            case 'mysql':
-                $this->addSql('ALTER TABLE '.$this->getTable('entry').' ADD INDEX created_at (created_at);');
-                break;
-
-            case 'postgresql':
-                $this->addSql('CREATE INDEX created_at ON '.$this->getTable('entry').' (created_at DESC)');
-        }
+        $entryTable = $schema->getTable($this->getTable('entry'));
+        $this->skipIf($entryTable->hasIndex($this->indexName), 'It seems that you already played this migration.');
+
+        $entryTable->addIndex(['created_at'], $this->indexName);
     }
 
     /**
@@ -48,6 +42,9 @@ class Version20161104073720 extends AbstractMigration implements ContainerAwareI
      */
     public function down(Schema $schema)
     {
+        $entryTable = $schema->getTable($this->getTable('entry'));
+        $this->skipIf(false === $entryTable->hasIndex($this->indexName), 'It seems that you already played this migration.');
 
+        $entryTable->dropIndex($this->indexName);
     }
 }
index edca54f5d732348dfb277362fffc22da52adadcf..5032a8f0563e3cfbe229e5e75dcdeadd9612194f 100644 (file)
@@ -21,7 +21,7 @@ class Version20161106113822 extends AbstractMigration implements ContainerAwareI
 
     private function getTable($tableName)
     {
-        return $this->container->getParameter('database_table_prefix') . $tableName;
+        return $this->container->getParameter('database_table_prefix').$tableName;
     }
 
     /**
@@ -29,7 +29,13 @@ class Version20161106113822 extends AbstractMigration implements ContainerAwareI
      */
     public function up(Schema $schema)
     {
-        $this->addSql('ALTER TABLE '.$this->getTable('config').' ADD action_mark_as_read INT DEFAULT 0');
+        $configTable = $schema->getTable($this->getTable('config'));
+
+        $this->skipIf($configTable->hasColumn('action_mark_as_read'), 'It seems that you already played this migration.');
+
+        $configTable->addColumn('action_mark_as_read', 'integer', [
+            'default' => 0,
+        ]);
     }
 
     /**
@@ -37,8 +43,7 @@ class Version20161106113822 extends AbstractMigration implements ContainerAwareI
      */
     public function down(Schema $schema)
     {
-        $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'sqlite', 'This down migration can\'t be executed on SQLite databases, because SQLite don\'t support DROP COLUMN.');
-
-        $this->addSql('ALTER TABLE '.$this->getTable('config').' DROP action_mark_as_read');
+        $configTable = $schema->getTable($this->getTable('config'));
+        $userTable->dropColumn('action_mark_as_read');
     }
 }
index 9ae55b5f3dda8577e77a5326dfd26cf27aa9b561..33f5707ebe070a9b81684516e87a95ece9f03258 100644 (file)
@@ -21,7 +21,7 @@ class Version20161117071626 extends AbstractMigration implements ContainerAwareI
 
     private function getTable($tableName)
     {
-        return $this->container->getParameter('database_table_prefix') . $tableName;
+        return $this->container->getParameter('database_table_prefix').$tableName;
     }
 
     /**
@@ -29,8 +29,8 @@ class Version20161117071626 extends AbstractMigration implements ContainerAwareI
      */
     public function up(Schema $schema)
     {
-        $this->addSql("INSERT INTO ".$this->getTable('craue_config_setting')." (name, value, section) VALUES ('share_unmark', 0, 'entry')");
-        $this->addSql("INSERT INTO ".$this->getTable('craue_config_setting')." (name, value, section) VALUES ('unmark_url', 'https://unmark.it', 'entry')");
+        $this->addSql('INSERT INTO '.$this->getTable('craue_config_setting')." (name, value, section) VALUES ('share_unmark', 0, 'entry')");
+        $this->addSql('INSERT INTO '.$this->getTable('craue_config_setting')." (name, value, section) VALUES ('unmark_url', 'https://unmark.it', 'entry')");
     }
 
     /**
@@ -38,7 +38,7 @@ class Version20161117071626 extends AbstractMigration implements ContainerAwareI
      */
     public function down(Schema $schema)
     {
-        $this->addSql("DELETE FROM ".$this->getTable('craue_config_setting')." WHERE name = 'share_unmark';");
-        $this->addSql("DELETE FROM ".$this->getTable('craue_config_setting')." WHERE name = 'unmark_url';");
+        $this->addSql('DELETE FROM '.$this->getTable('craue_config_setting')." WHERE name = 'share_unmark';");
+        $this->addSql('DELETE FROM '.$this->getTable('craue_config_setting')." WHERE name = 'unmark_url';");
     }
 }
index 390e89ce610256d9377252089846bd923f997c7a..f168cb53c813a601b19607b29c3f58d78b547953 100644 (file)
@@ -8,7 +8,7 @@ use Symfony\Component\DependencyInjection\ContainerAwareInterface;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
- * Add http_status in `entry_table`
+ * Add http_status in `entry_table`.
  */
 class Version20161118134328 extends AbstractMigration implements ContainerAwareInterface
 {
@@ -24,7 +24,7 @@ class Version20161118134328 extends AbstractMigration implements ContainerAwareI
 
     private function getTable($tableName)
     {
-        return $this->container->getParameter('database_table_prefix') . $tableName;
+        return $this->container->getParameter('database_table_prefix').$tableName;
     }
 
     /**
@@ -32,7 +32,14 @@ class Version20161118134328 extends AbstractMigration implements ContainerAwareI
      */
     public function up(Schema $schema)
     {
-        $this->addSql('ALTER TABLE '.$this->getTable('entry').' ADD http_status VARCHAR(3) DEFAULT NULL');
+        $entryTable = $schema->getTable($this->getTable('entry'));
+
+        $this->skipIf($entryTable->hasColumn('http_status'), 'It seems that you already played this migration.');
+
+        $entryTable->addColumn('http_status', 'string', [
+            'length' => 3,
+            'notnull' => false,
+        ]);
     }
 
     /**
@@ -40,8 +47,7 @@ class Version20161118134328 extends AbstractMigration implements ContainerAwareI
      */
     public function down(Schema $schema)
     {
-        $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'sqlite', 'This down migration can\'t be executed on SQLite databases, because SQLite don\'t support DROP COLUMN.');
-
-        $this->addSql('ALTER TABLE '.$this->getTable('entry').' DROP http_status');
+        $userTable = $schema->getTable($this->getTable('entry'));
+        $userTable->dropColumn('http_status');
     }
 }
index ec80c48e5d8d92cc44dccdd8e73c3ae39e4da734..536b833993539f2f3755c529042d8016dd15c2e8 100644 (file)
@@ -8,7 +8,7 @@ use Symfony\Component\DependencyInjection\ContainerAwareInterface;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
- * Add the restricted_access internal setting for articles with paywall
+ * Add the restricted_access internal setting for articles with paywall.
  */
 class Version20161122144743 extends AbstractMigration implements ContainerAwareInterface
 {
@@ -24,7 +24,7 @@ class Version20161122144743 extends AbstractMigration implements ContainerAwareI
 
     private function getTable($tableName)
     {
-        return $this->container->getParameter('database_table_prefix') . $tableName;
+        return $this->container->getParameter('database_table_prefix').$tableName;
     }
 
     /**
@@ -32,7 +32,7 @@ class Version20161122144743 extends AbstractMigration implements ContainerAwareI
      */
     public function up(Schema $schema)
     {
-        $this->addSql("INSERT INTO ".$this->getTable('craue_config_setting')." (name, value, section) VALUES ('restricted_access', 0, 'entry')");
+        $this->addSql('INSERT INTO '.$this->getTable('craue_config_setting')." (name, value, section) VALUES ('restricted_access', 0, 'entry')");
     }
 
     /**
@@ -40,6 +40,6 @@ class Version20161122144743 extends AbstractMigration implements ContainerAwareI
      */
     public function down(Schema $schema)
     {
-        $this->addSql("DELETE FROM ".$this->getTable('craue_config_setting')." WHERE name = 'restricted_access';");
+        $this->addSql('DELETE FROM '.$this->getTable('craue_config_setting')." WHERE name = 'restricted_access';");
     }
 }
index ea2703b6b1f99c3447e9a05c7dfcbbb1a2ec73eb..94197193cdc3d6c277749330128b17eb467e35cc 100644 (file)
@@ -8,7 +8,7 @@ use Symfony\Component\DependencyInjection\ContainerAwareInterface;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
- * Methods and properties removed from `FOS\UserBundle\Model\User`
+ * Methods and properties removed from `FOS\UserBundle\Model\User`.
  *
  * - `$expired`
  * - `$credentialsExpired`
@@ -32,7 +32,7 @@ class Version20161122203647 extends AbstractMigration implements ContainerAwareI
 
     private function getTable($tableName)
     {
-        return $this->container->getParameter('database_table_prefix') . $tableName;
+        return $this->container->getParameter('database_table_prefix').$tableName;
     }
 
     /**
@@ -40,10 +40,12 @@ class Version20161122203647 extends AbstractMigration implements ContainerAwareI
      */
     public function up(Schema $schema)
     {
-        $this->abortIf($this->connection->getDatabasePlatform()->getName() === 'sqlite', 'This up migration can\'t be executed on SQLite databases, because SQLite don\'t support DROP COLUMN.');
+        $userTable = $schema->getTable($this->getTable('user'));
 
-        $this->addSql('ALTER TABLE '.$this->getTable('user').' DROP expired');
-        $this->addSql('ALTER TABLE '.$this->getTable('user').' DROP credentials_expired');
+        $this->skipIf(false === $userTable->hasColumn('expired') || false === $userTable->hasColumn('credentials_expired'), 'It seems that you already played this migration.');
+
+        $userTable->dropColumn('expired');
+        $userTable->dropColumn('credentials_expired');
     }
 
     /**
@@ -51,7 +53,8 @@ class Version20161122203647 extends AbstractMigration implements ContainerAwareI
      */
     public function down(Schema $schema)
     {
-        $this->addSql('ALTER TABLE '.$this->getTable('user').' ADD expired tinyint(1) NULL DEFAULT 0');
-        $this->addSql('ALTER TABLE '.$this->getTable('user').' ADD credentials_expired tinyint(1) NULL DEFAULT 0');
+        $userTable = $schema->getTable($this->getTable('user'));
+        $userTable->addColumn('expired', 'smallint');
+        $userTable->addColumn('credentials_expired', 'smallint');
     }
 }