Skip to content

Commit

Permalink
ROLLBACK TO does not alter the transaction stack
Browse files Browse the repository at this point in the history
Learned more about ROLLBACK TO here: vlcn-io/js#32

What we really want is to abort all transactions if any of these operations fails. Switching to `ROLLBACK`
  • Loading branch information
tantaman committed Oct 20, 2023
1 parent 2316fc9 commit 64c07d8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion core/rs/core/src/automigrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn automigrate_impl(
let migrate_result = migrate_to(local_db, &mem_db);

if let Err(_) = migrate_result {
local_db.exec_safe("ROLLBACK TO automigrate_tables")?;
local_db.exec_safe("ROLLBACK")?;
let mem_db_err_msg = mem_db.errmsg()?;
ctx.result_error(&mem_db_err_msg);
ctx.result_error_code(mem_db.errcode());
Expand Down
4 changes: 2 additions & 2 deletions core/rs/core/src/backfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ pub fn backfill_table(

if let Err(e) = result {
if !no_tx {
db.exec_safe("ROLLBACK TO backfill")?;
db.exec_safe("ROLLBACK")?;
}

return Err(e);
}

if let Err(e) = backfill_missing_columns(db, table, pk_cols, non_pk_cols, is_commit_alter) {
if !no_tx {
db.exec_safe("ROLLBACK TO backfill")?;
db.exec_safe("ROLLBACK")?;
}

return Err(e);
Expand Down
2 changes: 1 addition & 1 deletion core/rs/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub extern "C" fn crsql_as_table(

if let Err(_) = crsql_as_table_impl(db, table) {
ctx.result_error("failed to downgrade the crr");
if let Err(_) = db.exec_safe("ROLLBACK TO as_table;") {
if let Err(_) = db.exec_safe("ROLLBACK") {
// fine.
}
return;
Expand Down

0 comments on commit 64c07d8

Please sign in to comment.