From 2a8fe347e0fa91f3c46da751e07328f190914141 Mon Sep 17 00:00:00 2001 From: Eric Peterson Date: Thu, 2 Apr 2026 20:46:14 -0600 Subject: [PATCH 1/2] fix: skip seeds when running in pretend mode Seeds do not support pretend mode, so running them during `migrate up --pretend --seed` would execute real SQL against the database, defeating the purpose of pretend mode. Co-Authored-By: Claude Sonnet 4.6 --- commands/migrate/up.cfc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/migrate/up.cfc b/commands/migrate/up.cfc index 4105f57..6e0c2d7 100644 --- a/commands/migrate/up.cfc +++ b/commands/migrate/up.cfc @@ -120,7 +120,7 @@ component extends="commandbox-migrations.models.BaseMigrationCommand" { } } - if ( arguments.seed ) { + if ( arguments.seed && !arguments.pretend ) { print.line(); command( "migrate seed run" ) .params( argumentCollection = { manager: arguments.manager, verbose: arguments.verbose } ) From 26dd7256874991b9089fc5a04189938e7ed89d3d Mon Sep 17 00:00:00 2001 From: Eric Peterson Date: Thu, 2 Apr 2026 20:55:16 -0600 Subject: [PATCH 2/2] feat: add pretend support to seed run command - Add --pretend and --file flags to `migrate seed run` - Display SQL that would have been run when pretend is true - Pass pretend through to cfmigrations when running seeds via `migrate up --seed --pretend` Co-Authored-By: Claude Sonnet 4.6 --- commands/migrate/seed/run.cfc | 32 +++++++++++++++++++++++++++++--- commands/migrate/up.cfc | 4 ++-- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/commands/migrate/seed/run.cfc b/commands/migrate/seed/run.cfc index 8dd60b5..ec7df8b 100644 --- a/commands/migrate/seed/run.cfc +++ b/commands/migrate/seed/run.cfc @@ -11,8 +11,16 @@ component extends="commandbox-migrations.models.BaseMigrationCommand" { * @manager.hint The Migration Manager to use. * @manager.optionsUDF completeManagers * @verbose.hint If true, errors output a full stack trace. + * @pretend.hint If true, only pretends to run the query. The SQL that would have been run is printed to the console. + * @file.hint If provided, outputs the SQL that would have been run to the file. Only applies when running `pretend`. */ - function run( string name = "", string manager = "default", boolean verbose = false ) { + function run( + string name = "", + string manager = "default", + boolean verbose = false, + boolean pretend = false, + string file + ) { setup( arguments.manager ); if ( getCFMigrationsType() == "boxJSON" ) { @@ -26,16 +34,29 @@ component extends="commandbox-migrations.models.BaseMigrationCommand" { pagePoolClear(); + var statements = []; var currentlyRunningSeeder = "UNKNOWN"; try { migrationService.seed( seedName = arguments.name == "" ? nullValue() : arguments.name, + pretend = arguments.pretend, preProcessHook = ( seeder ) => { currentlyRunningSeeder = seeder; print.yellow( "Seeding: " ).line( seeder ).toConsole(); }, - postProcessHook = ( seeder ) => { - print.green( "Seeded: " ).line( seeder ).toConsole(); + postProcessHook = ( seeder, qb ) => { + if ( !pretend ) { + print.green( "Seeded: " ).line( seeder ).toConsole(); + } else { + print.green( "Pretended to seed: " ).line( seeder ).toConsole(); + print.line(); + for ( var q in qb.getQueryLog() ) { + var inlineSql = qb.getUtils().replaceBindings( q.sql, q.bindings, true ); + statements.append( inlineSql ); + print.line( inlineSql ); + print.line(); + } + } } ); } catch ( any e ) { @@ -66,6 +87,11 @@ component extends="commandbox-migrations.models.BaseMigrationCommand" { if ( currentlyRunningSeeder == "UNKNOWN" ) { print.line( "No seeders to run." ); } + + if ( arguments.pretend && !isNull( arguments.file ) ) { + file action="write" file="#fileSystemUtil.resolvePath( arguments.file )#" mode="666" output="#trim( statements.toList( ";" & chr( 10 ) & chr( 10 ) ) )#"; + print.whiteOnBlueLine( "Wrote SQL to file: #arguments.file#" ); + } } function completeSeedNames( string paramSoFar, struct passedNamedParameters ) { diff --git a/commands/migrate/up.cfc b/commands/migrate/up.cfc index 6e0c2d7..ed9f8ea 100644 --- a/commands/migrate/up.cfc +++ b/commands/migrate/up.cfc @@ -120,10 +120,10 @@ component extends="commandbox-migrations.models.BaseMigrationCommand" { } } - if ( arguments.seed && !arguments.pretend ) { + if ( arguments.seed ) { print.line(); command( "migrate seed run" ) - .params( argumentCollection = { manager: arguments.manager, verbose: arguments.verbose } ) + .params( argumentCollection = { manager: arguments.manager, verbose: arguments.verbose, pretend: arguments.pretend } ) .run(); }