Skip to content

Commit ef4a683

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

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

index.js

Lines changed: 11 additions & 9 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) {
34-
const current = needed.shift()
35-
if (!current)
36-
return
33+
async function next() {
34+
await sql.begin(async (sql) => {
35+
const current = needed.shift()
36+
if (!current)
37+
return
3738

38-
before && before(current)
39-
await run(sql, current)
40-
after && after(current)
41-
await next(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)