Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit 077c1d4

Browse files
committed
Fix the June 2013 migrations on PagodaBox
Signed-off-by: Max Fierke <max@maxfierke.com>
1 parent ad128e5 commit 077c1d4

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

app/DoctrineMigrations/Version20130616122810.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,27 @@ public function up(Schema $schema)
1515
// this up() migration is auto-generated, please modify it to your needs
1616
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql", "Migration can only be executed safely on 'mysql'.");
1717

18-
$this->addSql("ALTER TABLE os_user DROP FOREIGN KEY FK_7BB0CD52BF396750");
19-
$this->addSql("ALTER TABLE os_clock ADD uid INT DEFAULT NULL");
20-
$this->addSql("ALTER TABLE os_clock ADD CONSTRAINT FK_34E85465539B0606 FOREIGN KEY (uid) REFERENCES os_user (id)");
21-
$this->addSql("UPDATE os_clock SET uid = id");
22-
$this->addSql("CREATE UNIQUE INDEX UNIQ_34E85465539B0606 ON os_clock (uid)");
18+
$tables = $schema->getTables();
19+
foreach ($tables as $table) {
20+
if ($table->getName() === "os_user") {
21+
if ($table->hasForeignKey('FK_7BB0CD52BF396750')) {
22+
$this->addSql("ALTER TABLE os_user DROP FOREIGN KEY FK_7BB0CD52BF396750");
23+
}
24+
} else if ($table->getName() === "os_clock") {
25+
if (!$table->hasColumn("uid")) {
26+
$this->addSql("ALTER TABLE os_clock ADD uid INT DEFAULT NULL");
27+
$this->addSql("UPDATE os_clock SET uid = id");
28+
}
29+
30+
if (!$table->hasForeignKey('FK_34E85465539B0606')) {
31+
$this->addSql("ALTER TABLE os_clock ADD CONSTRAINT FK_34E85465539B0606 FOREIGN KEY (uid) REFERENCES os_user (id)");
32+
}
33+
34+
if (!$table->hasIndex('UNIQ_34E85465539B0606')) {
35+
$this->addSql("CREATE UNIQUE INDEX UNIQ_34E85465539B0606 ON os_clock (uid)");
36+
}
37+
}
38+
}
2339
}
2440

2541
public function down(Schema $schema)

app/DoctrineMigrations/Version20130616165301.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,24 @@ public function up(Schema $schema)
1515
// this up() migration is auto-generated, please modify it to your needs
1616
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql", "Migration can only be executed safely on 'mysql'.");
1717

18-
$this->addSql("ALTER TABLE os_settings ADD massEmail VARCHAR(255) DEFAULT NULL");
18+
if ($schema->hasTable('os_settings')) {
19+
$table = $schema->getTable('os_settings');
20+
if (!$table->hasColumn('massEmail')) {
21+
$this->addSql("ALTER TABLE os_settings ADD massEmail VARCHAR(255) DEFAULT NULL");
22+
}
23+
}
1924
}
2025

2126
public function down(Schema $schema)
2227
{
2328
// this down() migration is auto-generated, please modify it to your needs
2429
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql", "Migration can only be executed safely on 'mysql'.");
2530

26-
$this->addSql("ALTER TABLE os_settings DROP massEmail");
31+
if ($schema->hasTable('os_settings')) {
32+
$table = $schema->getTable('os_settings');
33+
if (!$table->hasColumn('massEmail')) {
34+
$this->addSql("ALTER TABLE os_settings DROP massEmail");
35+
}
36+
}
2737
}
2838
}

0 commit comments

Comments
 (0)