public
Description: Rake tasks for working with migrations in a typical git branching workflow.
Clone URL: git://github.com/technoweenie/rails_migration_buddy.git
technoweenie (author)
Sun Mar 23 23:55:43 -0700 2008
commit  0bda7052dd7fcf6756c6d16189ad8eb10bad5f2d
tree    cf4d2e6bd770d62bf016f84e7f8fd61d0203a742
parent  e05caa285b9a26f820c2e6bc3040ef763c9c4a0f
name age message
file .gitignore Sun Mar 23 22:51:21 -0700 2008 update gitignore [technoweenie]
file README Sun Mar 23 23:55:43 -0700 2008 remove last references to old task name [technoweenie]
directory tasks/ Sun Mar 23 23:55:43 -0700 2008 remove last references to old task name [technoweenie]
README
Migration Buddy
==============

Or, "the inevitable renumbering and conflict-resolution of miggy tardust"

This is a tool to help merge rails branches with conflicting migrations.  The basic
idea goes like this:

* First you migrate down to the migration you were at when you branched.
* Renumber any new migrations you created that conflict with any new migrations in
  the target branch.
* Commit the renames.
* Merge to the target branch (usually 'master').
* Migrate back up.

Wow, what a pain, right?  Instead, make sure your new branch has a clean working copy:

(These examples use the included example app)

  $ git checkout example
  $ rake git:rebase_migrations BRANCH=example MASTER=example
  (in /Users/rick/migration_buddy)
  No new migrations in "example"
  No new migrations in "example" either, you're clear!

If you have no new migrations, rock on!  (So what, that was a contrived example)

  $ git checkout posting-with-comments
  $ rake git:rebase_migrations MASTER=posting
  (in /Users/rick/migration_buddy)
  No new migrations in "posting"
  1 new migration(s) in "posting-with-comments": ["004_add_comments.rb"].
  You should 'rake db:migrate VERSION=3' before merging with "posting

There were no new migrations in the master branch, so no rebasing needed.  Notice
how it guessed the BRANCH var from the current branch.  It defaults MASTER to 'master',
but the plugin itself is in the example's master branch.

  $ git checkout posting
  $ rake git:rebase_migrations MASTER=example
  (in /Users/rick/migration_buddy)
  1 new migration(s) in "master": ["002_modify_users.rb"].
  2 new migration(s) in "posting": ["002_add_posts.rb", "003_make_posts_whatever.rb"].

  Suggested Renumbering...
  git mv db/migrate/002_add_posts.rb db/migrate/003_add_posts.rb
  git mv db/migrate/003_make_posts_whatever.rb db/migrate/004_make_posts_whatever.rb

  Run with RUN=1 to actually rename the files.

Finally, something interesting!  It suggests the 'git mv' commands for you, but doesn't 
actually do anything.

  $ rake git:rebase_migrations MASTER=example RUN=1
  (in /Users/rick/migration_buddy)
  1 new migration(s) in "example": ["002_modify_users.rb"].
  2 new migration(s) in "posting": ["002_add_posts.rb", "003_make_posts_whatever.rb"].

  Renumbering...
  git mv db/migrate/002_add_posts.rb db/migrate/003_add_posts.rb
  git mv db/migrate/003_make_posts_whatever.rb db/migrate/004_make_posts_whatever.rb

  Migrations rebased!  Next actions:
   rake db:migrate VERSION=1
   git commit -m '...'
   git checkout example
   git merge posting
   rake db:migrate

License
=======

This is licensed under the WTFPL License

http://sam.zoy.org/wtfpl/

It'll probably be included in Rails.  Until then:

  http://github.com/technoweenie/rails_migration_buddy/tree

Happy rebasing!