You can send the --dry-run argument to any rake task to see what it will do.
topfunky$ rake rails:update --dry-run ** Invoke rails:update (first_time) ** Invoke rails:update:scripts (first_time) ** Execute (dry run) rails:update:scripts ** Invoke rails:update:javascripts (first_time) ** Execute (dry run) rails:update:javascripts ** Invoke rails:update:configs (first_time) ** Execute (dry run) rails:update:configs ** Execute (dry run) rails:update
Wouldn’t it be nice to have a similar feature for migrations so you can see what will happen without actually changing the database? This is experimental right now, but I’ve added a migrate_dry task to the topfunky_power_tools plugin.
It works both up and down for the built-in commands (add_column, remove_column, etc.). It will fail for other arbitrary data changes, but I hope to come up with a solution for that.
topfunky$ rake migrate_dry VERSION=6
** DRY RUN (Non-destructive) **
== AddAuthenticatedTable: reverting ===========================================
-- drop_table("users")
-> 0.0005s
== AddAuthenticatedTable: reverted (0.0019s) ==================================
At RailsConf, Glenn Vanderburg talked about how to test your migrations.
My next workshop is in London and will be a two day hands-on workshop. Come learn about the basics of Rails, Test-Driven Development, plugin development, and more. → More Details
I’ll also be at the London Ruby Users Group on Aug 8. More details soon…
UPDATE: Now works with basic data-cleaning migrations as well.
Nice idea, i’ll have to give this a go
Nice idea, and very useful.
Any way of modifying migrate task to take a —dry-run option? Would be a more natural command for people to remember and in line with the task options.
I don’t think Rake tasks take arguments like that, but I’ll look into it. That would be more natural.