#!/usr/bin/env ruby
USAGE = 'migrate path_to_migration [up|down]'
require File.dirname(__FILE__) + '/../config/environment'
path = ARGV.shift
direction = ARGV.shift || 'up'
abort('migrate path_to_migration') unless
path and %w[ up down ].include?(direction)
migrations = []
singleton_class =
class << ActiveRecord::Migration
self
end
singleton_class.module_eval do
define_method(:inherited) do |other|
migrations << other
super if defined? super
end
end
Kernel.load path
migrations.each{|migration| migration.migrate(direction.to_sym)}