aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/DoctrineMigrations/Version20161001072726.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/DoctrineMigrations/Version20161001072726.php')
-rw-r--r--app/DoctrineMigrations/Version20161001072726.php37
1 files changed, 23 insertions, 14 deletions
diff --git a/app/DoctrineMigrations/Version20161001072726.php b/app/DoctrineMigrations/Version20161001072726.php
index 2e112949..237db932 100644
--- a/app/DoctrineMigrations/Version20161001072726.php
+++ b/app/DoctrineMigrations/Version20161001072726.php
@@ -29,12 +29,28 @@ class Version20161001072726 extends AbstractMigration implements ContainerAwareI
29 */ 29 */
30 public function up(Schema $schema) 30 public function up(Schema $schema)
31 { 31 {
32 $this->addSql('ALTER TABLE '.$this->getTable('entry_tag').' DROP FOREIGN KEY FK_F035C9E5BA364942'); 32 $this->skipIf($this->connection->getDatabasePlatform()->getName() == 'sqlite', 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.');
33 $this->addSql('ALTER TABLE '.$this->getTable('entry_tag').' DROP FOREIGN KEY FK_F035C9E5BAD26311'); 33
34 $this->addSql('ALTER TABLE '.$this->getTable('entry_tag').' ADD CONSTRAINT FK_F035C9E5BA364942 FOREIGN KEY (entry_id) REFERENCES `entry` (id) ON DELETE CASCADE'); 34 // remove all FK from entry_tag
35 $this->addSql('ALTER TABLE '.$this->getTable('entry_tag').' ADD CONSTRAINT FK_F035C9E5BAD26311 FOREIGN KEY (tag_id) REFERENCES `tag` (id) ON DELETE CASCADE'); 35 $query = $this->connection->query("SELECT CONSTRAINT_NAME FROM information_schema.key_column_usage WHERE TABLE_NAME = '".$this->getTable('entry_tag')."' AND CONSTRAINT_NAME LIKE 'FK_%' AND TABLE_SCHEMA = '".$this->connection->getDatabase()."'");
36 $this->addSql('ALTER TABLE '.$this->getTable('annotation').' DROP FOREIGN KEY FK_2E443EF2BA364942'); 36 $query->execute();
37 $this->addSql('ALTER TABLE '.$this->getTable('annotation').' ADD CONSTRAINT FK_2E443EF2BA364942 FOREIGN KEY (entry_id) REFERENCES `entry` (id) ON DELETE CASCADE'); 37
38 foreach ($query->fetchAll() as $fk) {
39 $this->addSql('ALTER TABLE '.$this->getTable('entry_tag').' DROP FOREIGN KEY '.$fk['CONSTRAINT_NAME']);
40 }
41
42 $this->addSql('ALTER TABLE '.$this->getTable('entry_tag').' ADD CONSTRAINT FK_entry_tag_entry FOREIGN KEY (entry_id) REFERENCES '.$this->getTable('entry').' (id) ON DELETE CASCADE');
43 $this->addSql('ALTER TABLE '.$this->getTable('entry_tag').' ADD CONSTRAINT FK_entry_tag_tag FOREIGN KEY (tag_id) REFERENCES '.$this->getTable('tag').' (id) ON DELETE CASCADE');
44
45 // remove entry FK from annotation
46 $query = $this->connection->query("SELECT CONSTRAINT_NAME FROM information_schema.key_column_usage WHERE TABLE_NAME = '".$this->getTable('annotation')."' AND CONSTRAINT_NAME LIKE 'FK_%' and COLUMN_NAME = 'entry_id' AND TABLE_SCHEMA = '".$this->connection->getDatabase()."'");
47 $query->execute();
48
49 foreach ($query->fetchAll() as $fk) {
50 $this->addSql('ALTER TABLE '.$this->getTable('annotation').' DROP FOREIGN KEY '.$fk['CONSTRAINT_NAME']);
51 }
52
53 $this->addSql('ALTER TABLE '.$this->getTable('annotation').' ADD CONSTRAINT FK_annotation_entry FOREIGN KEY (entry_id) REFERENCES '.$this->getTable('entry').' (id) ON DELETE CASCADE');
38 } 54 }
39 55
40 /** 56 /**
@@ -42,13 +58,6 @@ class Version20161001072726 extends AbstractMigration implements ContainerAwareI
42 */ 58 */
43 public function down(Schema $schema) 59 public function down(Schema $schema)
44 { 60 {
45 $this->abortIf($this->connection->getDatabasePlatform()->getName() == 'sqlite', 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.'); 61 throw new SkipMigrationException('Too complex ...');
46
47 $this->addSql('ALTER TABLE '.$this->getTable('annotation').' DROP FOREIGN KEY FK_2E443EF2BA364942');
48 $this->addSql('ALTER TABLE '.$this->getTable('annotation').' ADD CONSTRAINT FK_2E443EF2BA364942 FOREIGN KEY (entry_id) REFERENCES entry (id)');
49 $this->addSql('ALTER TABLE '.$this->getTable('entry_tag').' DROP FOREIGN KEY FK_F035C9E5BA364942');
50 $this->addSql('ALTER TABLE '.$this->getTable('entry_tag').' DROP FOREIGN KEY FK_F035C9E5BAD26311');
51 $this->addSql('ALTER TABLE '.$this->getTable('entry_tag').' ADD CONSTRAINT FK_F035C9E5BA364942 FOREIGN KEY (entry_id) REFERENCES entry (id)');
52 $this->addSql('ALTER TABLE '.$this->getTable('entry_tag').' ADD CONSTRAINT FK_F035C9E5BAD26311 FOREIGN KEY (tag_id) REFERENCES tag (id)');
53 } 62 }
54} 63}