@@ -43,39 +43,39 @@ export async function runMigrations(
4343
4444 // Execute the migrations sql
4545 const path = `${ migrationsPath } /${ migration } /migration.sql` ;
46+ let statements = "" ; // Used to create the checksum
47+ // Execute the migrations line by line
48+ await prisma . $transaction ( async ( tx ) => {
49+ const fileStream = fs . createReadStream ( path ) ;
50+ const rl = readline . createInterface ( {
51+ input : fileStream ,
52+ crlfDelay : Infinity ,
53+ } ) ;
4654
47- // @TODO : Make this safer/ better
48- // Read file line by line
49- const fileStream = fs . createReadStream ( path ) ;
50- const rl = readline . createInterface ( {
51- input : fileStream ,
52- crlfDelay : Infinity ,
53- } ) ;
54-
55- let statements = "" ;
56- let statement = "" ;
55+ let statement = "" ;
5756
58- for await ( const line of rl ) {
59- // Skip comments and empty lines
60- if (
61- line . startsWith ( "--" ) ||
62- line . startsWith ( "/*" ) ||
63- line . trim ( ) === ""
64- ) {
65- continue ;
66- }
57+ for await ( const line of rl ) {
58+ // Skip comments and empty lines
59+ if (
60+ line . startsWith ( "--" ) ||
61+ line . startsWith ( "/*" ) ||
62+ line . trim ( ) === ""
63+ ) {
64+ continue ;
65+ }
6766
68- statement += line + " " ;
67+ statement += line + " " ;
6968
70- // If the line ends with a semicolon, execute the statement
71- if ( line . trim ( ) . endsWith ( ";" ) ) {
72- await prisma . $executeRawUnsafe ( statement ) ;
73- statements += statement ;
69+ // If the line ends with a semicolon, execute the statement
70+ if ( line . trim ( ) . endsWith ( ";" ) ) {
71+ await tx . $executeRawUnsafe ( statement ) ;
72+ statements += statement ;
7473
75- // Reset statement
76- statement = "" ;
74+ // Reset statement
75+ statement = "" ;
76+ }
7777 }
78- }
78+ } ) ;
7979
8080 // Update the migration table
8181 const getFinishedDateTime = new Date ( ) ;
0 commit comments