ANN: Independent migrations plugin
Courtenay : March 27th, 2007
My independent migrations patch has been sitting on the rails trac for 4 months, so I’m releasing it as a plugin.
Code plz thx
ticket: http://dev.rubyonrails.org/ticket/6799
plugin: svn://caboo.se/plugins/court3nay/independent_migrations
I plan to add a generator, one day, if anyone cares.
wtf
In simple terms, here’s what it does. To paraphrase zenspider, if two migrations have the same number, Rails will bitch at you. This plugin removes the bitching. To get it working, install, then edit your migrations so they look like this
class AddProject < ActiveRecord::IndependentMigration
That’s it. Now your migration directory can look something like
002_add_project.rb
002.add_monkeys.rb
003.fix_monkeys.rb
and as long as all 002 are independent, then the migration will run. This patch is only guaranteed for Rails 1.2.3 and may change as ActiveRecord changes as it relies heavily on monkeypatching (or reopening classes, as David Black would have you believe) some private methods.
Why?
If you’re still wondering, “Why?”, the usage came from heavy usage of branches. Basically, if there are two branches being developed in parallel, and both are getting migrations, it can be assumed that those migrations are, in fact, in parallel, and won’t conflict, so can have the same number.
Alternate solutions
There is of course more ways to skin a cat, and the other contender for your migrations is Françoise Beausoleil’s “Timestamped Migrations”, while it isn’t a plugin (yet), numbers your migrations like it says on the box (with timestamps).
http://blog.teksol.info/articles/search?q=migration
7 Responses to “ANN: Independent migrations plugin”
Sorry, comments are closed for this article.
March 27th, 2007 at 01:45 AM
Thanks Courtenay, this will come in handy!
Do all migrations need to subclass IndependentMigration? or can you be selective? Or say only where you have clashes?
March 27th, 2007 at 02:39 AM
Only where you have clashes.
March 27th, 2007 at 07:38 PM
Makes sense. Thank you for the clarification.
March 29th, 2007 at 06:35 AM
What happens if your db is on migration 3 and an independent #2 comes trotting in from someone else’s commit? Does that get noticed and pulled in, or do you still have to dance around to get back to version 1 so you can remigrate back up?
March 29th, 2007 at 06:05 PM
It will raise an error, but only if 2 was a normal migration.
If there are already two independent migrations at 2, you’re at 4, and someone adds another at 2, it won’t run it, just like if someone changes migration 35 and you’re at 60.
March 30th, 2007 at 07:08 AM
We solved it by giving each branch an offset of 100 migrations to play around with… not perfect but it let us not monkeypatch even more :)
April 3rd, 2007 at 01:39 AM
Interesting plugin.
I tried using it with Rails 1.2.2, but alas, it did not work.
The error message was: unitialized constant ActiveRecord::IndependentMigrations