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({
7
7
sql,
8
8
path = join ( process . cwd ( ) , 'migrations' ) ,
9
9
before = null ,
10
- after = null
10
+ after = null ,
11
+ transactionPerEachMigration = false
11
12
} ) {
12
13
const migrations = fs . readdirSync ( path )
13
14
. filter ( x => fs . statSync ( join ( path , x ) ) . isDirectory ( ) && x . match ( / ^ [ 0 - 9 ] { 5 } _ / ) )
@@ -28,17 +29,27 @@ export default async function({
28
29
const current = await getCurrentMigration ( )
29
30
const needed = migrations . slice ( current ? current . id : 0 )
30
31
31
- return sql . begin ( next )
32
+ return transactionPerEachMigration ? next ( sql ) : sql . begin ( next )
32
33
33
34
async function next ( sql ) {
34
35
const current = needed . shift ( )
35
36
if ( ! current )
36
37
return
37
38
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 ) {
38
50
before && before ( current )
39
51
await run ( sql , current )
40
52
after && after ( current )
41
- await next ( sql )
42
53
}
43
54
44
55
async function run ( sql , {
You can’t perform that action at this time.
0 commit comments