A Dry Run for Migrations 4 comments

posted Friday, June 30, 2006 by topfunky

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) ==================================

See also

At RailsConf, Glenn Vanderburg talked about how to test your migrations.

Carson Rails Workshop, Two Days, London August

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…

4 comments

Leave a response

  • topfunky

    UPDATE: Now works with basic data-cleaning migrations as well.

  • Nice idea, i’ll have to give this a go

  • zerohalo

    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.

  • topfunky

    I don’t think Rake tasks take arguments like that, but I’ll look into it. That would be more natural.

Your Comment

Nuby on Rails

Geoffrey Grosenbach / Ruby / Code / Graphics / Design / Rails / Merb / Javascript / CSS

Manufactured with

Subscribe

Subscribe (RSS)