Skip to content

Commit

Permalink
[keyserver] only wrap migration in transaction if specified in migrat…
Browse files Browse the repository at this point in the history
…ionType

Summary:
If the migration type is `wrap_in_transaction_and_block_requests`, we wrap the migration in a transaction. Only if it was wrapped in transaction do we run rollback if the query failed.

Depends on D13209

Test Plan: I console logged and made sure that transaction and rollback queries were only being run if the migration in `migrations` specified wrapping in a transaction.

Reviewers: varun, ashoat

Reviewed By: ashoat

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D13212
  • Loading branch information
wyilio committed Sep 9, 2024
1 parent 23ad15f commit 13bc558
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions keyserver/src/database/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,39 @@ async function migrate(): Promise<boolean> {
for (const {
version: idx,
migrationPromise: migration,
migrationType,
} of migrations.values()) {
if (idx <= dbVersion) {
continue;
}

try {
await startTransaction();
if (
!migrationType ||
migrationType === 'wrap_in_transaction_and_block_requests'
) {
await startTransaction();
}
await migration();
await updateDBVersion(idx);
await commitTransaction();
if (
!migrationType ||
migrationType === 'wrap_in_transaction_and_block_requests'
) {
await commitTransaction();
}
console.log(`(node:${process.pid}) migration ${idx} succeeded.`);
} catch (e) {
const transactionExceptionMessage = String(getMessageForException(e));
console.error(`(node:${process.pid}) migration ${idx} failed.`);
console.error(transactionExceptionMessage);
await rollbackTransaction();

if (
!migrationType ||
migrationType === 'wrap_in_transaction_and_block_requests'
) {
await rollbackTransaction();
}
return false;
}
}
Expand Down

0 comments on commit 13bc558

Please sign in to comment.