1- const { execSync } = require ( ' child_process' ) ;
2- const { format } = require ( ' date-fns' ) ;
3- const path = require ( ' path' ) ;
4- const fs = require ( 'fs' ) ;
1+ const { execSync } = require ( " child_process" ) ;
2+ const { format } = require ( " date-fns" ) ;
3+ const path = require ( " path" ) ;
4+ const fs = require ( "fs" ) ;
55
66try {
7- const timestamp = format ( new Date ( ) , ' yyyyMMdd_HHmmss' ) ;
8- const outputFile = path . join ( ' migrations' , `${ timestamp } _update_schema.sql` ) ;
9- const command = `bunx prisma migrate diff --from-schema-datamodel ./src/prisma/schema.previous.prisma --to-schema-datamodel ./src/prisma/schema.prisma --script --output ${ outputFile } ` ;
7+ const timestamp = format ( new Date ( ) , " yyyyMMdd_HHmmss" ) ;
8+ const outputFile = path . join ( " migrations" , `${ timestamp } _update_schema.sql` ) ;
9+ const command = `bunx prisma migrate diff --from-schema-datamodel ./src/prisma/schema.previous.prisma --to-schema-datamodel ./src/prisma/schema.prisma --script --output ${ outputFile } ` ;
1010
11- execSync ( command , { stdio : ' inherit' } ) ;
12- console . log ( `Generated migration file: ${ outputFile } ` ) ;
13- // copy schema.prisma to schema.previous.prisma
14- const src = path . resolve ( __dirname , ' src/prisma/schema.prisma' ) ;
15- const dest = path . resolve ( __dirname , ' src/prisma/schema.previous.prisma' ) ;
16- fs . copyFileSync ( src , dest ) ;
17- console . log ( ' Updated schema.previous.prisma with the current schema.prisma' ) ;
11+ execSync ( command , { stdio : " inherit" } ) ;
12+ console . log ( `Generated migration file: ${ outputFile } ` ) ;
13+ // copy schema.prisma to schema.previous.prisma
14+ const src = path . resolve ( __dirname , " src/prisma/schema.prisma" ) ;
15+ const dest = path . resolve ( __dirname , " src/prisma/schema.previous.prisma" ) ;
16+ fs . copyFileSync ( src , dest ) ;
17+ console . log ( " Updated schema.previous.prisma with the current schema.prisma" ) ;
1818} catch ( error ) {
19- console . error ( ' Error generating migration:' , error . message ) ;
20- process . exit ( 1 ) ;
21- }
19+ console . error ( " Error generating migration:" , error . message ) ;
20+ process . exit ( 1 ) ;
21+ }
0 commit comments