diff --git a/app/DoctrineMigrations/Version20130616122810.php b/app/DoctrineMigrations/Version20130616122810.php index 0f09239..0485ad8 100644 --- a/app/DoctrineMigrations/Version20130616122810.php +++ b/app/DoctrineMigrations/Version20130616122810.php @@ -15,11 +15,27 @@ public function up(Schema $schema) // this up() migration is auto-generated, please modify it to your needs $this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql", "Migration can only be executed safely on 'mysql'."); - $this->addSql("ALTER TABLE os_user DROP FOREIGN KEY FK_7BB0CD52BF396750"); - $this->addSql("ALTER TABLE os_clock ADD uid INT DEFAULT NULL"); - $this->addSql("ALTER TABLE os_clock ADD CONSTRAINT FK_34E85465539B0606 FOREIGN KEY (uid) REFERENCES os_user (id)"); - $this->addSql("UPDATE os_clock SET uid = id"); - $this->addSql("CREATE UNIQUE INDEX UNIQ_34E85465539B0606 ON os_clock (uid)"); + $tables = $schema->getTables(); + foreach ($tables as $table) { + if ($table->getName() === "os_user") { + if ($table->hasForeignKey('FK_7BB0CD52BF396750')) { + $this->addSql("ALTER TABLE os_user DROP FOREIGN KEY FK_7BB0CD52BF396750"); + } + } else if ($table->getName() === "os_clock") { + if (!$table->hasColumn("uid")) { + $this->addSql("ALTER TABLE os_clock ADD uid INT DEFAULT NULL"); + $this->addSql("UPDATE os_clock SET uid = id"); + } + + if (!$table->hasForeignKey('FK_34E85465539B0606')) { + $this->addSql("ALTER TABLE os_clock ADD CONSTRAINT FK_34E85465539B0606 FOREIGN KEY (uid) REFERENCES os_user (id)"); + } + + if (!$table->hasIndex('UNIQ_34E85465539B0606')) { + $this->addSql("CREATE UNIQUE INDEX UNIQ_34E85465539B0606 ON os_clock (uid)"); + } + } + } } public function down(Schema $schema) diff --git a/app/DoctrineMigrations/Version20130616165301.php b/app/DoctrineMigrations/Version20130616165301.php index eaba8b4..cddfff8 100644 --- a/app/DoctrineMigrations/Version20130616165301.php +++ b/app/DoctrineMigrations/Version20130616165301.php @@ -15,7 +15,12 @@ public function up(Schema $schema) // this up() migration is auto-generated, please modify it to your needs $this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql", "Migration can only be executed safely on 'mysql'."); - $this->addSql("ALTER TABLE os_settings ADD massEmail VARCHAR(255) DEFAULT NULL"); + if ($schema->hasTable('os_settings')) { + $table = $schema->getTable('os_settings'); + if (!$table->hasColumn('massEmail')) { + $this->addSql("ALTER TABLE os_settings ADD massEmail VARCHAR(255) DEFAULT NULL"); + } + } } public function down(Schema $schema) @@ -23,6 +28,11 @@ public function down(Schema $schema) // this down() migration is auto-generated, please modify it to your needs $this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql", "Migration can only be executed safely on 'mysql'."); - $this->addSql("ALTER TABLE os_settings DROP massEmail"); + if ($schema->hasTable('os_settings')) { + $table = $schema->getTable('os_settings'); + if (!$table->hasColumn('massEmail')) { + $this->addSql("ALTER TABLE os_settings DROP massEmail"); + } + } } }