Skip to content

Commit

Permalink
migrate: fix order of foreign_keys :-/
Browse files Browse the repository at this point in the history
  • Loading branch information
cztomsik committed Sep 4, 2024
1 parent 5b9f9e1 commit 1390b95
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/migrate.zig
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ pub fn migrate(allocator: std.mem.Allocator, filename: [:0]const u8, ddl: []cons
try db.conn.execAll("PRAGMA journal_mode = WAL");
try db.conn.execAll("PRAGMA synchronous = FULL");

// Start a transaction and disable foreign key checks
try db.conn.execAll("BEGIN");
try db.conn.execAll("PRAGMA foreign_keys = OFF");
// Disable foreign key checks (needs to be first!) and start a transaction
try db.conn.execAll("PRAGMA foreign_keys = OFF"); // TODO: can we at least lock the file?
try db.conn.execAll("BEGIN EXCLUSIVE");

// Migrate each object type
inline for (.{ "table", "view", "trigger", "index" }) |kind| {
try migrateObjects(&db, &pristine, kind);
}

// Re-enable foreign key checks and commit
try db.conn.execAll("PRAGMA foreign_keys = ON");
// Commit and re-enable foreign key checks
try db.conn.execAll("COMMIT");
try db.conn.execAll("PRAGMA foreign_keys = ON");
}

fn migrateObjects(db: *Session, pristine: *Session, kind: []const u8) !void {
Expand Down

0 comments on commit 1390b95

Please sign in to comment.