11import fs from 'node:fs' ;
22import path from 'node:path' ;
3+ import { CliError } from '../cli-error' ;
34import { execPackage } from '../utils/exec-utils' ;
45import { generateTempPrismaSchema , getSchemaFile } from './action-utils' ;
56
@@ -21,6 +22,11 @@ type DeployOptions = CommonOptions;
2122
2223type StatusOptions = CommonOptions ;
2324
25+ type ResolveOptions = CommonOptions & {
26+ applied ?: string ;
27+ rolledBack ?: string ;
28+ } ;
29+
2430/**
2531 * CLI action for migration-related commands
2632 */
@@ -46,6 +52,10 @@ export async function run(command: string, options: CommonOptions) {
4652 case 'status' :
4753 await runStatus ( prismaSchemaFile , options as StatusOptions ) ;
4854 break ;
55+
56+ case 'resolve' :
57+ await runResolve ( prismaSchemaFile , options as ResolveOptions ) ;
58+ break ;
4959 }
5060 } finally {
5161 if ( fs . existsSync ( prismaSchemaFile ) ) {
@@ -100,6 +110,25 @@ async function runStatus(prismaSchemaFile: string, _options: StatusOptions) {
100110 }
101111}
102112
113+ async function runResolve ( prismaSchemaFile : string , options : ResolveOptions ) {
114+ if ( ! options . applied && ! options . rolledBack ) {
115+ throw new CliError ( 'Either --applied or --rolled-back option must be provided' ) ;
116+ }
117+
118+ try {
119+ const cmd = [
120+ 'prisma migrate resolve' ,
121+ ` --schema "${ prismaSchemaFile } "` ,
122+ options . applied ? ` --applied ${ options . applied } ` : '' ,
123+ options . rolledBack ? ` --rolled-back ${ options . rolledBack } ` : '' ,
124+ ] . join ( '' ) ;
125+
126+ await execPackage ( cmd ) ;
127+ } catch ( err ) {
128+ handleSubProcessError ( err ) ;
129+ }
130+ }
131+
103132function handleSubProcessError ( err : unknown ) {
104133 if ( err instanceof Error && 'status' in err && typeof err . status === 'number' ) {
105134 process . exit ( err . status ) ;
0 commit comments