@@ -23,8 +23,9 @@ class PrismaScripts {
2323
2424 deployForce ( project : Project ) : string {
2525 const dirPath = getDatabaseDirPath ( project ) ;
26+ // `prisma migrate reset` sometimes fails if the existing database schema, so we remove it first.
2627 // Don't skip "migrate deploy" because restored database may be older than the current schema.
27- return `PRISMA migrate reset --force --skip-seed && rm -Rf ${ dirPath } /prod.sqlite3*
28+ return `rm -Rf ${ dirPath } /prod.sqlite3*; PRISMA migrate reset --force --skip-seed && rm -Rf ${ dirPath } /prod.sqlite3*
2829 && litestream restore -config litestream.yml -o ${ dirPath } /prod.sqlite3 ${ dirPath } /prod.sqlite3 && ls -ahl ${ dirPath } /prod.sqlite3 && ALLOW_TO_SKIP_SEED=0 PRISMA migrate deploy` ;
2930 }
3031
@@ -43,18 +44,16 @@ class PrismaScripts {
4344
4445 reset ( project : Project , additionalOptions = '' ) : string {
4546 // cf. https://www.prisma.io/docs/guides/database/seed-database#integrated-seeding-with-prisma-migrate
46- const resetOptions = additionalOptions . trim ( ) ;
47- const baseReset = `PRISMA migrate reset --force ${ resetOptions } ` ;
48- const resetCommand = project . packageJson . dependencies ?. blitz ? `${ baseReset } && ${ this . seed ( project ) } ` : baseReset ;
49- const resetCommandForTest = project . packageJson . dependencies ?. blitz
50- ? String . raw `find db \( -name "test.db*" -o -name "test.sqlite*" \) -delete`
51- : String . raw `find prisma \( -name "test.db*" -o -name "test.sqlite*" \) -delete` ;
52- return `${ resetCommand } && ${ resetCommandForTest } ` ;
47+ if ( project . packageJson . dependencies ?. blitz ) {
48+ // Blitz does not trigger seed automatically, so we need to run it manually.
49+ return `PRISMA migrate reset --force ${ additionalOptions } && ${ this . seed ( project ) } ` ;
50+ }
51+ return `PRISMA migrate reset --force ${ additionalOptions } ` ;
5352 }
5453
5554 restore ( project : Project , outputPath : string ) : string {
5655 const dirPath = getDatabaseDirPath ( project ) ;
57- return `${ this . removeSqliteArtifacts ( outputPath ) } ; litestream restore -config litestream.yml -o ${ outputPath } ${ dirPath } /prod.sqlite3` ;
56+ return `rm -Rf ${ outputPath } * ; litestream restore -config litestream.yml -o ${ outputPath } ${ dirPath } /prod.sqlite3` ;
5857 }
5958
6059 seed ( project : Project , scriptPath ?: string ) : string {
@@ -117,11 +116,6 @@ const prisma = new PrismaClient();
117116 }
118117 return `${ prefix } PRISMA studio ${ additionalOptions } ` ;
119118 }
120-
121- private removeSqliteArtifacts ( sqlitePath : string ) : string {
122- // Litestream requires removing WAL/SHM and Litestream sidecar files when recreating databases.
123- return `rm -Rf ${ sqlitePath } ${ sqlitePath } -shm ${ sqlitePath } -wal ${ sqlitePath } -litestream` ;
124- }
125119}
126120
127121function getDatabaseDirPath ( project : Project ) : string {
0 commit comments