parent
a21f3f2bb4
commit
e7176b6371
17 changed files with 189 additions and 25 deletions
|
|
@ -65,14 +65,27 @@ final class Migrations
|
|||
}
|
||||
}
|
||||
|
||||
$relaxesForeignKeys = $name === '093_room_rules_and_care_periods.sql';
|
||||
if ($relaxesForeignKeys) {
|
||||
$db->exec('PRAGMA foreign_keys = OFF');
|
||||
}
|
||||
$db->beginTransaction();
|
||||
try {
|
||||
$db->exec($sql);
|
||||
$ins = $db->prepare("INSERT INTO _migrations(name, applied_at) VALUES(:n, datetime('now'))");
|
||||
$ins->execute([':n' => $name]);
|
||||
if ($relaxesForeignKeys && $db->query('PRAGMA foreign_key_check')->fetchColumn() !== false) {
|
||||
throw new RuntimeException('Foreign key check failed after room migration');
|
||||
}
|
||||
$db->commit();
|
||||
if ($relaxesForeignKeys) {
|
||||
$db->exec('PRAGMA foreign_keys = ON');
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
$db->rollBack();
|
||||
if ($relaxesForeignKeys) {
|
||||
$db->exec('PRAGMA foreign_keys = ON');
|
||||
}
|
||||
throw new RuntimeException('Migration ' . $name . ' : ' . $e->getMessage(), 0, $e);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue