Skip to content

Commit 57bf965

Browse files
committed
Wrap each migration into its own transaction
1 parent e7a4cb1 commit 57bf965

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

index.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,19 @@ export default async function({
2828
const current = await getCurrentMigration()
2929
const needed = migrations.slice(current ? current.id : 0)
3030

31-
return sql.begin(next)
31+
return next()
3232

33-
async function next(sql) {
33+
async function next() {
3434
const current = needed.shift()
3535
if (!current)
3636
return
3737

38-
before && before(current)
39-
await run(sql, current)
40-
after && after(current)
41-
await next(sql)
38+
await sql.begin(async (sql) => {
39+
before && before(current)
40+
await run(sql, current)
41+
after && after(current)
42+
})
43+
await next()
4244
}
4345

4446
async function run(sql, {

0 commit comments

Comments
 (0)