File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,8 @@ export default async function({
77 sql,
88 path = join ( process . cwd ( ) , 'migrations' ) ,
99 before = null ,
10- after = null
10+ after = null ,
11+ transactionPerEachMigration = false
1112} ) {
1213 const migrations = fs . readdirSync ( path )
1314 . filter ( x => fs . statSync ( join ( path , x ) ) . isDirectory ( ) && x . match ( / ^ [ 0 - 9 ] { 5 } _ / ) )
@@ -28,17 +29,27 @@ export default async function({
2829 const current = await getCurrentMigration ( )
2930 const needed = migrations . slice ( current ? current . id : 0 )
3031
31- return sql . begin ( next )
32+ return transactionPerEachMigration ? next ( sql ) : sql . begin ( next )
3233
3334 async function next ( sql ) {
3435 const current = needed . shift ( )
3536 if ( ! current )
3637 return
3738
39+ if ( transactionPerEachMigration ) {
40+ await sql . begin ( async ( sql ) => {
41+ await step ( sql , current ) ;
42+ } )
43+ } else {
44+ await step ( sql , current ) ;
45+ }
46+ await next ( sql )
47+ }
48+
49+ async function step ( sql , current ) {
3850 before && before ( current )
3951 await run ( sql , current )
4052 after && after ( current )
41- await next ( sql )
4253 }
4354
4455 async function run ( sql , {
You can’t perform that action at this time.
0 commit comments