File tree Expand file tree Collapse file tree 3 files changed +14
-3
lines changed Expand file tree Collapse file tree 3 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -53,10 +53,13 @@ export function handleSubProcessError(err: unknown) {
5353 }
5454}
5555
56- export async function generateTempPrismaSchema ( zmodelPath : string ) {
56+ export async function generateTempPrismaSchema ( zmodelPath : string , folder ?: string ) {
5757 const model = await loadSchemaDocument ( zmodelPath ) ;
5858 const prismaSchema = await new PrismaSchemaGenerator ( model ) . generate ( ) ;
59- const prismaSchemaFile = path . resolve ( path . dirname ( zmodelPath ) , '~schema.prisma' ) ;
59+ if ( ! folder ) {
60+ folder = path . dirname ( zmodelPath ) ;
61+ }
62+ const prismaSchemaFile = path . resolve ( folder , '~schema.prisma' ) ;
6063 fs . writeFileSync ( prismaSchemaFile , prismaSchema ) ;
6164 return prismaSchemaFile ;
6265}
Original file line number Diff line number Diff line change 11import fs from 'node:fs' ;
2+ import path from 'node:path' ;
23import { execPackage } from '../utils/exec-utils' ;
34import { generateTempPrismaSchema , getSchemaFile } from './action-utils' ;
45
56type CommonOptions = {
67 schema ?: string ;
8+ migrations ?: string ;
79} ;
810
911type DevOptions = CommonOptions & {
@@ -24,7 +26,8 @@ type StatusOptions = CommonOptions;
2426 */
2527export async function run ( command : string , options : CommonOptions ) {
2628 const schemaFile = getSchemaFile ( options . schema ) ;
27- const prismaSchemaFile = await generateTempPrismaSchema ( schemaFile ) ;
29+ const prismaSchemaDir = options . migrations ? path . dirname ( options . migrations ) : undefined ;
30+ const prismaSchemaFile = await generateTempPrismaSchema ( schemaFile , prismaSchemaDir ) ;
2831
2932 try {
3033 switch ( command ) {
Original file line number Diff line number Diff line change @@ -60,31 +60,36 @@ export function createProgram() {
6060 . action ( generateAction ) ;
6161
6262 const migrateCommand = program . command ( 'migrate' ) . description ( 'Update the database schema with migrations.' ) ;
63+ const migrationsOption = new Option ( '--migrations <path>' , 'path for migrations' ) ;
6364
6465 migrateCommand
6566 . command ( 'dev' )
6667 . addOption ( schemaOption )
6768 . addOption ( new Option ( '-n, --name <name>' , 'migration name' ) )
6869 . addOption ( new Option ( '--create-only' , 'only create migration, do not apply' ) )
70+ . addOption ( migrationsOption )
6971 . description ( 'Create a migration from changes in schema and apply it to the database.' )
7072 . action ( ( options ) => migrateAction ( 'dev' , options ) ) ;
7173
7274 migrateCommand
7375 . command ( 'reset' )
7476 . addOption ( schemaOption )
7577 . addOption ( new Option ( '--force' , 'skip the confirmation prompt' ) )
78+ . addOption ( migrationsOption )
7679 . description ( 'Reset your database and apply all migrations, all data will be lost.' )
7780 . action ( ( options ) => migrateAction ( 'reset' , options ) ) ;
7881
7982 migrateCommand
8083 . command ( 'deploy' )
8184 . addOption ( schemaOption )
85+ . addOption ( migrationsOption )
8286 . description ( 'Deploy your pending migrations to your production/staging database.' )
8387 . action ( ( options ) => migrateAction ( 'deploy' , options ) ) ;
8488
8589 migrateCommand
8690 . command ( 'status' )
8791 . addOption ( schemaOption )
92+ . addOption ( migrationsOption )
8893 . description ( 'check the status of your database migrations.' )
8994 . action ( ( options ) => migrateAction ( 'status' , options ) ) ;
9095
You can’t perform that action at this time.
0 commit comments