diff options
Diffstat (limited to 'app/DoctrineMigrations/Version20160916201049.php')
-rw-r--r-- | app/DoctrineMigrations/Version20160916201049.php | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/app/DoctrineMigrations/Version20160916201049.php b/app/DoctrineMigrations/Version20160916201049.php index 0d2edf9e..9f8e77e7 100644 --- a/app/DoctrineMigrations/Version20160916201049.php +++ b/app/DoctrineMigrations/Version20160916201049.php | |||
@@ -7,6 +7,9 @@ use Doctrine\DBAL\Schema\Schema; | |||
7 | use Symfony\Component\DependencyInjection\ContainerAwareInterface; | 7 | use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
8 | use Symfony\Component\DependencyInjection\ContainerInterface; | 8 | use Symfony\Component\DependencyInjection\ContainerInterface; |
9 | 9 | ||
10 | /** | ||
11 | * Added pocket_consumer_key field on wallabag_config | ||
12 | */ | ||
10 | class Version20160916201049 extends AbstractMigration implements ContainerAwareInterface | 13 | class Version20160916201049 extends AbstractMigration implements ContainerAwareInterface |
11 | { | 14 | { |
12 | /** | 15 | /** |
@@ -21,7 +24,7 @@ class Version20160916201049 extends AbstractMigration implements ContainerAwareI | |||
21 | 24 | ||
22 | private function getTable($tableName) | 25 | private function getTable($tableName) |
23 | { | 26 | { |
24 | return $this->container->getParameter('database_table_prefix') . $tableName; | 27 | return $this->container->getParameter('database_table_prefix').$tableName; |
25 | } | 28 | } |
26 | 29 | ||
27 | /** | 30 | /** |
@@ -29,8 +32,12 @@ class Version20160916201049 extends AbstractMigration implements ContainerAwareI | |||
29 | */ | 32 | */ |
30 | public function up(Schema $schema) | 33 | public function up(Schema $schema) |
31 | { | 34 | { |
32 | $this->addSql('ALTER TABLE "'.$this->getTable('config').'" ADD pocket_consumer_key VARCHAR(255) DEFAULT NULL'); | 35 | $configTable = $schema->getTable($this->getTable('config')); |
33 | $this->addSql("DELETE FROM \"".$this->getTable('craue_config_setting')."\" WHERE name = 'pocket_consumer_key';"); | 36 | |
37 | $this->skipIf($configTable->hasColumn('pocket_consumer_key'), 'It seems that you already played this migration.'); | ||
38 | |||
39 | $configTable->addColumn('pocket_consumer_key', 'string', ['notnull' => false]); | ||
40 | $this->addSql('DELETE FROM '.$this->getTable('craue_config_setting')." WHERE name = 'pocket_consumer_key';"); | ||
34 | } | 41 | } |
35 | 42 | ||
36 | /** | 43 | /** |
@@ -38,9 +45,8 @@ class Version20160916201049 extends AbstractMigration implements ContainerAwareI | |||
38 | */ | 45 | */ |
39 | public function down(Schema $schema) | 46 | public function down(Schema $schema) |
40 | { | 47 | { |
41 | $this->abortIf($this->connection->getDatabasePlatform()->getName() == 'sqlite', 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.'); | 48 | $configTable = $schema->getTable($this->getTable('config')); |
42 | 49 | $configTable->dropColumn('pocket_consumer_key'); | |
43 | $this->addSql('ALTER TABLE "'.$this->getTable('config').'" DROP pocket_consumer_key'); | 50 | $this->addSql('INSERT INTO '.$this->getTable('craue_config_setting')." (name, value, section) VALUES ('pocket_consumer_key', NULL, 'import')"); |
44 | $this->addSql("INSERT INTO \"".$this->getTable('craue_config_setting')."\" (name, value, section) VALUES ('pocket_consumer_key', NULL, 'import')"); | ||
45 | } | 51 | } |
46 | } | 52 | } |