From 18d7bc3a353d8737c64a0f9e1c9fdcb7a756c3e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 25 Nov 2016 17:43:28 +0100 Subject: Added checks on migrations --- app/DoctrineMigrations/Version20160916201049.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'app/DoctrineMigrations/Version20160916201049.php') diff --git a/app/DoctrineMigrations/Version20160916201049.php b/app/DoctrineMigrations/Version20160916201049.php index 0d2edf9e..5db00108 100644 --- a/app/DoctrineMigrations/Version20160916201049.php +++ b/app/DoctrineMigrations/Version20160916201049.php @@ -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,10 @@ class Version20160916201049 extends AbstractMigration implements ContainerAwareI */ public function up(Schema $schema) { + $this->skipIf($schema->getTable($this->getTable('config'))->hasColumn('pocket_consumer_key'), 'It seems that you already played this migration.'); + $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';"); + $this->addSql('DELETE FROM "'.$this->getTable('craue_config_setting')."\" WHERE name = 'pocket_consumer_key';"); } /** @@ -41,6 +43,6 @@ class Version20160916201049 extends AbstractMigration implements ContainerAwareI $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')"); + $this->addSql('INSERT INTO "'.$this->getTable('craue_config_setting')."\" (name, value, section) VALUES ('pocket_consumer_key', NULL, 'import')"); } } -- cgit v1.2.3 From a4d55a9161144f7e0daafff8da13dabc9e090ae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sat, 26 Nov 2016 13:34:36 +0100 Subject: Replaced abortIf with skipIf --- app/DoctrineMigrations/Version20160916201049.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/DoctrineMigrations/Version20160916201049.php') diff --git a/app/DoctrineMigrations/Version20160916201049.php b/app/DoctrineMigrations/Version20160916201049.php index 5db00108..83ed6b61 100644 --- a/app/DoctrineMigrations/Version20160916201049.php +++ b/app/DoctrineMigrations/Version20160916201049.php @@ -40,7 +40,7 @@ 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->skipIf($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')"); -- cgit v1.2.3 From 597755b8c7f45310df072d2185fc7bd406f9a39e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sat, 26 Nov 2016 16:06:14 +0100 Subject: Cleaned old migrations --- app/DoctrineMigrations/Version20160916201049.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'app/DoctrineMigrations/Version20160916201049.php') diff --git a/app/DoctrineMigrations/Version20160916201049.php b/app/DoctrineMigrations/Version20160916201049.php index 83ed6b61..09c05f4b 100644 --- a/app/DoctrineMigrations/Version20160916201049.php +++ b/app/DoctrineMigrations/Version20160916201049.php @@ -29,10 +29,12 @@ class Version20160916201049 extends AbstractMigration implements ContainerAwareI */ public function up(Schema $schema) { - $this->skipIf($schema->getTable($this->getTable('config'))->hasColumn('pocket_consumer_key'), 'It seems that you already played this migration.'); + $configTable = $schema->getTable($this->getTable('config')); - $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';"); + $this->skipIf($configTable->hasColumn('pocket_consumer_key'), 'It seems that you already played this migration.'); + + $userTable->addColumn('pocket_consumer_key', 'string'); + $this->addSql('DELETE FROM '.$this->getTable('craue_config_setting')." WHERE name = 'pocket_consumer_key';"); } /** @@ -40,9 +42,8 @@ class Version20160916201049 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('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')); + $clientsTable->dropColumn('pocket_consumer_key'); + $this->addSql('INSERT INTO '.$this->getTable('craue_config_setting')." (name, value, section) VALUES ('pocket_consumer_key', NULL, 'import')"); } } -- cgit v1.2.3 From d79b3adbed4c2c1fd8d35e9475af734d443b564a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 28 Nov 2016 08:55:03 +0100 Subject: Fixed typo --- app/DoctrineMigrations/Version20160916201049.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/DoctrineMigrations/Version20160916201049.php') diff --git a/app/DoctrineMigrations/Version20160916201049.php b/app/DoctrineMigrations/Version20160916201049.php index 09c05f4b..9390755e 100644 --- a/app/DoctrineMigrations/Version20160916201049.php +++ b/app/DoctrineMigrations/Version20160916201049.php @@ -33,7 +33,7 @@ class Version20160916201049 extends AbstractMigration implements ContainerAwareI $this->skipIf($configTable->hasColumn('pocket_consumer_key'), 'It seems that you already played this migration.'); - $userTable->addColumn('pocket_consumer_key', 'string'); + $configTable->addColumn('pocket_consumer_key', 'string'); $this->addSql('DELETE FROM '.$this->getTable('craue_config_setting')." WHERE name = 'pocket_consumer_key';"); } @@ -43,7 +43,7 @@ class Version20160916201049 extends AbstractMigration implements ContainerAwareI public function down(Schema $schema) { $configTable = $schema->getTable($this->getTable('config')); - $clientsTable->dropColumn('pocket_consumer_key'); + $configTable->dropColumn('pocket_consumer_key'); $this->addSql('INSERT INTO '.$this->getTable('craue_config_setting')." (name, value, section) VALUES ('pocket_consumer_key', NULL, 'import')"); } } -- cgit v1.2.3