Skip to content
This repository has been archived by the owner on Feb 9, 2020. It is now read-only.

Commit

Permalink
Wrap db schema changes in a transacion.
Browse files Browse the repository at this point in the history
  • Loading branch information
rogersm committed Apr 17, 2018
1 parent 96442c4 commit b28d669
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,22 @@ void db_migrate()
}
}

db_execute("BEGIN EXCLUSIVE TRANSACTION");
while(command[i].schema != -1) {
if (command[i].schema > db_schema) {
if ( !db_execute(command[i].action) ) {
db_execute("ROLLBACK TRANSACTION");
abort();
}
}
if( !db_execute("UPDATE DB_SCHEMA SET db_version = %i", command[i].schema) ) {
db_execute("ROLLBACK TRANSACTION");
abort();
}
i++;
}
db_execute("COMMIT TRANSACTION");


if(command[i-1].schema > db_schema ) {
log_string("db_schema updated to version %d", command[i-1].schema);
Expand Down

0 comments on commit b28d669

Please sign in to comment.