File tree Expand file tree Collapse file tree 1 file changed +18
-14
lines changed
Expand file tree Collapse file tree 1 file changed +18
-14
lines changed Original file line number Diff line number Diff line change @@ -24,24 +24,28 @@ async function seed() {
2424 . map ( ( f ) => path . join ( folder_path , f . name ) )
2525 . sort ( )
2626
27- for ( const file of files ) {
28- const base = path . basename ( file )
29- const is_valid = base ?. match ( / ^ [ A - Z a - z 0 - 9 _ . , \- ( ) ] + $ / )
30- if ( ! is_valid ) {
31- throw new Error ( `Invalid file name: ${ base } ` )
32- }
33- const sql = await fs . readFile ( file , 'utf8' )
34- const tx = await db . transaction ( )
35- try {
27+ const tx = await db . transaction ( )
28+
29+ try {
30+ for ( const file of files ) {
31+ const base = path . basename ( file )
32+ const is_valid = base ?. match ( / ^ [ A - Z a - z 0 - 9 _ . , \- ( ) ] + $ / )
33+ if ( ! is_valid ) {
34+ throw new Error ( `Invalid file name: ${ base } ` )
35+ }
36+ const sql = await fs . readFile ( file , 'utf8' )
37+
3638 await tx . executeMultiple ( sql )
37- await tx . commit ( )
39+
3840 const operation = file . includes ( 'clear' ) ? 'Clear data' : 'Insert data'
3941 console . info ( `${ operation } : ${ base } ` )
40- } catch ( err ) {
41- console . error ( `Failed to process ${ file } ` , err )
42- await tx . rollback ( )
43- process . exit ( 1 )
4442 }
43+
44+ await tx . commit ( )
45+ } catch ( err ) {
46+ console . error ( `Failed to seed ${ folder } ` , err )
47+ await tx . rollback ( )
48+ process . exit ( 1 )
4549 }
4650 }
4751
You can’t perform that action at this time.
0 commit comments