@@ -30,6 +30,9 @@ impl CallArgs {
3030 }
3131
3232 match & self . command {
33+ | Command :: Migration ( Migration { command : MigrationCommand :: Diff , .. } ) => anyhow:: bail!( "diff is experimental" ) ,
34+ | Command :: Migration ( Migration { command : MigrationCommand :: Up { diff : true , .. } , .. } ) => anyhow:: bail!( "diff is experimental" ) ,
35+ | Command :: Migration ( Migration { command : MigrationCommand :: Down { diff : true , .. } , .. } ) => anyhow:: bail!( "diff is experimental" ) ,
3336 | _ => ( ) ,
3437 }
3538
@@ -57,16 +60,19 @@ pub(crate) enum MigrationCommand {
5760 Up {
5861 timeout : Option < u64 > ,
5962 count : Option < usize > ,
63+ diff : bool ,
6064 } ,
6165 Down {
6266 timeout : Option < u64 > ,
6367 count : Option < usize > ,
6468 remote : bool ,
69+ diff : bool ,
6570 } ,
6671 Apply ( MigrationApply ) ,
6772 List ,
6873 Sync ,
6974 Fix ,
75+ Diff ,
7076}
7177
7278#[ derive( Debug ) ]
@@ -161,14 +167,16 @@ impl ClapArgumentLoader {
161167 clap:: Command :: new ( "up" )
162168 . about ( "Runs the migrations." )
163169 . arg ( clap:: Arg :: new ( "timeout" ) . short ( 't' ) . long ( "timeout" ) . required ( false ) )
164- . arg ( clap:: Arg :: new ( "count" ) . short ( 'c' ) . long ( "count" ) . required ( false ) ) ,
170+ . arg ( clap:: Arg :: new ( "count" ) . short ( 'c' ) . long ( "count" ) . required ( false ) )
171+ . arg ( clap:: Arg :: new ( "diff" ) . short ( 'd' ) . long ( "diff" ) . required ( false ) . num_args ( 0 ) . help ( "Show migration diff before applying" ) ) ,
165172 )
166173 . subcommand (
167174 clap:: Command :: new ( "down" )
168175 . about ( "Rolls back the migrations." )
169176 . arg ( clap:: Arg :: new ( "timeout" ) . short ( 't' ) . long ( "timeout" ) . required ( false ) )
170177 . arg ( clap:: Arg :: new ( "remote" ) . short ( 'r' ) . long ( "remote" ) . required ( false ) . num_args ( 0 ) )
171- . arg ( clap:: Arg :: new ( "count" ) . short ( 'c' ) . long ( "count" ) . required ( false ) ) ,
178+ . arg ( clap:: Arg :: new ( "count" ) . short ( 'c' ) . long ( "count" ) . required ( false ) )
179+ . arg ( clap:: Arg :: new ( "diff" ) . short ( 'd' ) . long ( "diff" ) . required ( false ) . num_args ( 0 ) . help ( "Show migration diff before applying" ) ) ,
172180 )
173181 . subcommand (
174182 clap:: Command :: new ( "list" )
@@ -182,6 +190,10 @@ impl ClapArgumentLoader {
182190 clap:: Command :: new ( "fix" )
183191 . about ( "Shuffles all non-run local migrations to the end of the chain." ) ,
184192 )
193+ . subcommand (
194+ clap:: Command :: new ( "diff" )
195+ . about ( "Shows pending migration operations without applying them." ) ,
196+ )
185197 . subcommand (
186198 clap:: Command :: new ( "apply" )
187199 . about ( "Applies or reverts a specific migration by ID." )
@@ -240,19 +252,23 @@ impl ClapArgumentLoader {
240252 MigrationCommand :: Up {
241253 timeout : up_subc. get_one :: < String > ( "timeout" ) . map ( |s| s. parse :: < u64 > ( ) . unwrap ( ) ) ,
242254 count : up_subc. get_one :: < String > ( "count" ) . map ( |s| s. parse :: < usize > ( ) . unwrap ( ) ) ,
255+ diff : up_subc. get_flag ( "diff" ) ,
243256 }
244257 } else if let Some ( down_subc) = subc. subcommand_matches ( "down" ) {
245258 MigrationCommand :: Down {
246259 timeout : down_subc. get_one :: < String > ( "timeout" ) . map ( |s| s. parse :: < u64 > ( ) . unwrap ( ) ) ,
247260 count : down_subc. get_one :: < String > ( "count" ) . map ( |s| s. parse :: < usize > ( ) . unwrap ( ) ) ,
248261 remote : down_subc. get_flag ( "remote" ) ,
262+ diff : down_subc. get_flag ( "diff" ) ,
249263 }
250264 } else if let Some ( _) = subc. subcommand_matches ( "list" ) {
251265 MigrationCommand :: List
252266 } else if let Some ( _) = subc. subcommand_matches ( "sync" ) {
253267 MigrationCommand :: Sync
254268 } else if let Some ( _) = subc. subcommand_matches ( "fix" ) {
255269 MigrationCommand :: Fix
270+ } else if let Some ( _) = subc. subcommand_matches ( "diff" ) {
271+ MigrationCommand :: Diff
256272 } else if let Some ( apply_subc) = subc. subcommand_matches ( "apply" ) {
257273 if let Some ( up_subc) = apply_subc. subcommand_matches ( "up" ) {
258274 MigrationCommand :: Apply ( MigrationApply :: Up {
0 commit comments