Skip to content

Commit

Permalink
feat: execute migrations in transaction and lock table
Browse files Browse the repository at this point in the history
  • Loading branch information
gabts committed Jun 30, 2021
1 parent f21b4a3 commit 0899a39
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,11 @@ export async function migratorosaurus(
}
}

await client.query(`BEGIN; LOCK TABLE ${table} IN EXCLUSIVE MODE;`);
targetFile && targetFile.index <= lastIndex
? await downMigration(client, log, table, files, lastIndex, targetFile)
: await upMigration(client, log, table, files, lastIndex, targetFile);
await client.query('COMMIT;');

await client.end();
log('🌋 migratorosaurus completed!');
Expand Down

0 comments on commit 0899a39

Please sign in to comment.