]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Added dropColumn for SQLite and some enhancements
authorNicolas Lœuillet <nicolas@loeuillet.org>
Sat, 26 Nov 2016 14:40:42 +0000 (15:40 +0100)
committerNicolas Lœuillet <nicolas@loeuillet.org>
Mon, 28 Nov 2016 13:28:35 +0000 (14:28 +0100)
app/DoctrineMigrations/Version20161024212538.php
app/DoctrineMigrations/Version20161031132655.php
app/DoctrineMigrations/Version20161104073720.php
app/DoctrineMigrations/Version20161106113822.php
app/DoctrineMigrations/Version20161118134328.php
app/DoctrineMigrations/Version20161122203647.php

index ced3a80218046831566b573dcd70295eb40d4305..7e79cbdec04fac95d54e164ab23ca99f2f22fe13 100644 (file)
@@ -29,12 +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->skipIf($schema->getTable($this->getTable('oauth2_clients'))->hasColumn('user_id'), 'It seems that you already played this migration.');
+        $this->skipIf($clientsTable->hasColumn('user_id'), 'It seems that you already played this migration.');
 
-        $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');
+        $clientsTable->addColumn('user_id', 'integer');
+
+        $clientsTable->addForeignKeyConstraint(
+            $this->getTable('user'),
+            array('user_id'),
+            array('id'),
+            array('onDelete' => 'CASCADE')
+        );
     }
 
     /**
index 80163c0b223bd29ce06a11cae38f18bd79a4e928..39b85ea9759f979a913ea0fb84271ebe46914762 100644 (file)
@@ -37,8 +37,6 @@ class Version20161031132655 extends AbstractMigration implements ContainerAwareI
      */
     public function down(Schema $schema)
     {
-        $this->skipIf($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';");
     }
 }
index 7a0361f80176a806b1bf27c465ec6cb77138b3c9..cd2029cb301f91c941fd53ff1063f966bdab26c6 100644 (file)
@@ -29,18 +29,8 @@ 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'));
+        $entryTable->addIndex(['created_at']);
     }
 
     /**
index 5e3fd5626599fba53f472e1c6453db2224425158..5032a8f0563e3cfbe229e5e75dcdeadd9612194f 100644 (file)
@@ -29,9 +29,13 @@ class Version20161106113822 extends AbstractMigration implements ContainerAwareI
      */
     public function up(Schema $schema)
     {
-        $this->skipIf($schema->getTable($this->getTable('config'))->hasColumn('action_mark_as_read'), 'It seems that you already played this migration.');
+        $configTable = $schema->getTable($this->getTable('config'));
 
-        $this->addSql('ALTER TABLE '.$this->getTable('config').' ADD action_mark_as_read INT DEFAULT 0');
+        $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,
+        ]);
     }
 
     /**
@@ -39,8 +43,7 @@ class Version20161106113822 extends AbstractMigration implements ContainerAwareI
      */
     public function down(Schema $schema)
     {
-        $this->skipIf($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 69eae5a5030530157e987206bd4c46e7a91f282b..f168cb53c813a601b19607b29c3f58d78b547953 100644 (file)
@@ -32,9 +32,14 @@ class Version20161118134328 extends AbstractMigration implements ContainerAwareI
      */
     public function up(Schema $schema)
     {
-        $this->skipIf($schema->getTable($this->getTable('entry'))->hasColumn('http_status'), 'It seems that you already played this migration.');
+        $entryTable = $schema->getTable($this->getTable('entry'));
 
-        $this->addSql('ALTER TABLE '.$this->getTable('entry').' ADD http_status VARCHAR(3) DEFAULT NULL');
+        $this->skipIf($entryTable->hasColumn('http_status'), 'It seems that you already played this migration.');
+
+        $entryTable->addColumn('http_status', 'string', [
+            'length' => 3,
+            'notnull' => false,
+        ]);
     }
 
     /**
@@ -42,8 +47,7 @@ class Version20161118134328 extends AbstractMigration implements ContainerAwareI
      */
     public function down(Schema $schema)
     {
-        $this->skipIf($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 354a10e80d6fe245ea7ec7daed21fdcb00719867..9c1557ebc3a54f922b0de8b88da6ec8dd73a6149 100644 (file)
@@ -40,15 +40,15 @@ class Version20161122203647 extends AbstractMigration implements ContainerAwareI
      */
     public function up(Schema $schema)
     {
-        $this->skipIf($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->skipIf(false === $schema->getTable($this->getTable('user'))->hasColumn('expired'), 'It seems that you already played this migration.');
+        $this->skipIf(false === $userTable->hasColumn('expired'), 'It seems that you already played this migration.');
 
-        $this->addSql('ALTER TABLE '.$this->getTable('user').' DROP expired');
+        $userTable->dropColumn('expired');
 
-        $this->skipIf(false === $schema->getTable($this->getTable('user'))->hasColumn('credentials_expired'), 'It seems that you already played this migration.');
+        $this->skipIf(false === $userTable->hasColumn('credentials_expired'), 'It seems that you already played this migration.');
 
-        $this->addSql('ALTER TABLE '.$this->getTable('user').' DROP credentials_expired');
+        $userTable->dropColumn('credentials_expired');
     }
 
     /**
@@ -56,7 +56,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');
     }
 }