@@ -29,6 +29,21 @@ type ResolveOptions = CommonOptions & {
2929 rolledBack ?: string ;
3030} ;
3131
32+ type DiffOptions = CommonOptions & {
33+ fromEmpty ?: boolean ;
34+ toEmpty ?: boolean ;
35+ fromSchemaDatamodel ?: boolean ;
36+ toSchemaDatamodel ?: boolean ;
37+ fromMigrationsDirectory ?: string ;
38+ toMigrationsDirectory ?: string ;
39+ fromUrl ?: string ;
40+ toUrl ?: string ;
41+ shadowDatabaseUrl ?: string ;
42+ script ?: boolean ;
43+ exitCode ?: boolean ;
44+ extraArgs ?: string [ ] ;
45+ } ;
46+
3247/**
3348 * CLI action for migration-related commands
3449 */
@@ -62,6 +77,10 @@ export async function run(command: string, options: CommonOptions) {
6277 case 'resolve' :
6378 await runResolve ( prismaSchemaFile , options as ResolveOptions ) ;
6479 break ;
80+
81+ case 'diff' :
82+ runDiff ( prismaSchemaFile , options as DiffOptions ) ;
83+ break ;
6584 }
6685 } finally {
6786 if ( fs . existsSync ( prismaSchemaFile ) ) {
@@ -140,6 +159,55 @@ function runResolve(prismaSchemaFile: string, options: ResolveOptions) {
140159 }
141160}
142161
162+ function runDiff ( prismaSchemaFile : string , options : DiffOptions ) {
163+ try {
164+ const parts = [ 'migrate diff' ] ;
165+
166+ if ( options . fromEmpty ) {
167+ parts . push ( '--from-empty' ) ;
168+ }
169+ if ( options . toEmpty ) {
170+ parts . push ( '--to-empty' ) ;
171+ }
172+ if ( options . fromSchemaDatamodel ) {
173+ parts . push ( `--from-schema-datamodel "${ prismaSchemaFile } "` ) ;
174+ }
175+ if ( options . toSchemaDatamodel ) {
176+ parts . push ( `--to-schema-datamodel "${ prismaSchemaFile } "` ) ;
177+ }
178+ if ( options . fromMigrationsDirectory ) {
179+ parts . push ( `--from-migrations-directory "${ options . fromMigrationsDirectory } "` ) ;
180+ }
181+ if ( options . toMigrationsDirectory ) {
182+ parts . push ( `--to-migrations-directory "${ options . toMigrationsDirectory } "` ) ;
183+ }
184+ if ( options . fromUrl ) {
185+ parts . push ( `--from-url "${ options . fromUrl } "` ) ;
186+ }
187+ if ( options . toUrl ) {
188+ parts . push ( `--to-url "${ options . toUrl } "` ) ;
189+ }
190+ if ( options . shadowDatabaseUrl ) {
191+ parts . push ( `--shadow-database-url "${ options . shadowDatabaseUrl } "` ) ;
192+ }
193+ if ( options . script ) {
194+ parts . push ( '--script' ) ;
195+ }
196+ if ( options . exitCode ) {
197+ parts . push ( '--exit-code' ) ;
198+ }
199+
200+ // pass through any extra args
201+ if ( options . extraArgs ?. length ) {
202+ parts . push ( ...options . extraArgs ) ;
203+ }
204+
205+ execPrisma ( parts . join ( ' ' ) ) ;
206+ } catch ( err ) {
207+ handleSubProcessError ( err ) ;
208+ }
209+ }
210+
143211function handleSubProcessError ( err : unknown ) {
144212 if ( err instanceof Error && 'status' in err && typeof err . status === 'number' ) {
145213 process . exit ( err . status ) ;
0 commit comments