aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/DoctrineMigrations/Version20161104073720.php
diff options
context:
space:
mode:
authorJeremy Benoist <j0k3r@users.noreply.github.com>2016-11-30 14:17:40 +0100
committerGitHub <noreply@github.com>2016-11-30 14:17:40 +0100
commit9abac9651fd0af4586245364657dc9455ba5c73c (patch)
treefb8f3e1c5ac43d1f08d4197af7026eb1cd27eb00 /app/DoctrineMigrations/Version20161104073720.php
parentad51d77146494f04466c288b05b57b0d96113fd5 (diff)
parent067ae472cc50a6047d6197f1a042ce239153407d (diff)
downloadwallabag-9abac9651fd0af4586245364657dc9455ba5c73c.tar.gz
wallabag-9abac9651fd0af4586245364657dc9455ba5c73c.tar.zst
wallabag-9abac9651fd0af4586245364657dc9455ba5c73c.zip
Merge pull request #2650 from wallabag/add-hascolumn
Added hasColumn() in migration to check column existence
Diffstat (limited to 'app/DoctrineMigrations/Version20161104073720.php')
-rw-r--r--app/DoctrineMigrations/Version20161104073720.php23
1 files changed, 10 insertions, 13 deletions
diff --git a/app/DoctrineMigrations/Version20161104073720.php b/app/DoctrineMigrations/Version20161104073720.php
index 16503b4b..4721426a 100644
--- a/app/DoctrineMigrations/Version20161104073720.php
+++ b/app/DoctrineMigrations/Version20161104073720.php
@@ -14,6 +14,8 @@ class Version20161104073720 extends AbstractMigration implements ContainerAwareI
14 */ 14 */
15 private $container; 15 private $container;
16 16
17 private $indexName = 'IDX_entry_created_at';
18
17 public function setContainer(ContainerInterface $container = null) 19 public function setContainer(ContainerInterface $container = null)
18 { 20 {
19 $this->container = $container; 21 $this->container = $container;
@@ -21,7 +23,7 @@ class Version20161104073720 extends AbstractMigration implements ContainerAwareI
21 23
22 private function getTable($tableName) 24 private function getTable($tableName)
23 { 25 {
24 return $this->container->getParameter('database_table_prefix') . $tableName; 26 return $this->container->getParameter('database_table_prefix').$tableName;
25 } 27 }
26 28
27 /** 29 /**
@@ -29,18 +31,10 @@ class Version20161104073720 extends AbstractMigration implements ContainerAwareI
29 */ 31 */
30 public function up(Schema $schema) 32 public function up(Schema $schema)
31 { 33 {
32 switch ($this->connection->getDatabasePlatform()->getName()) { 34 $entryTable = $schema->getTable($this->getTable('entry'));
33 case 'sqlite': 35 $this->skipIf($entryTable->hasIndex($this->indexName), 'It seems that you already played this migration.');
34 $this->addSql('CREATE INDEX `created_at` ON `'.$this->getTable('entry').'` (`created_at` DESC)'); 36
35 break; 37 $entryTable->addIndex(['created_at'], $this->indexName);
36
37 case 'mysql':
38 $this->addSql('ALTER TABLE '.$this->getTable('entry').' ADD INDEX created_at (created_at);');
39 break;
40
41 case 'postgresql':
42 $this->addSql('CREATE INDEX created_at ON '.$this->getTable('entry').' (created_at DESC)');
43 }
44 } 38 }
45 39
46 /** 40 /**
@@ -48,6 +42,9 @@ class Version20161104073720 extends AbstractMigration implements ContainerAwareI
48 */ 42 */
49 public function down(Schema $schema) 43 public function down(Schema $schema)
50 { 44 {
45 $entryTable = $schema->getTable($this->getTable('entry'));
46 $this->skipIf(false === $entryTable->hasIndex($this->indexName), 'It seems that you already played this migration.');
51 47
48 $entryTable->dropIndex($this->indexName);
52 } 49 }
53} 50}