Run migrations with immediate foreign key checks

This fixes an issue where unrelated foreign key violations may cause
migrations to fail.
This commit is contained in:
Max Radermacher 2022-06-21 14:52:32 -07:00 committed by GitHub
parent a1eb9e3042
commit ea627259fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -241,7 +241,10 @@ public class GRDBSchemaMigrator: NSObject {
var migrator = DatabaseMigrator()
func registerMigration(_ identifier: MigrationId, migrate: @escaping (Database) -> Void) {
migrator.registerMigration(identifier.rawValue) { (database: Database) in
// Run with immediate foreign key checks so that pre-existing dangling rows
// don't cause unrelated migrations to fail. We also don't perform schema
// alterations that would necessitate disabling foreign key checks.
migrator.registerMigration(identifier.rawValue, foreignKeyChecks: .immediate) { (database: Database) in
let startTime = CACurrentMediaTime()
Logger.info("Running migration: \(identifier)")
migrate(database)