Created
May 6, 2012 23:17
-
-
Save jugyo/2624944 to your computer and use it in GitHub Desktop.
the db:migrate task using ActiveRecord without Rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bundler/setup' | |
require 'active_record' | |
require 'logger' | |
namespace :db do | |
desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x" | |
task :migrate => :environment do | |
ActiveRecord::Migrator.migrate('db/migrate', ENV["VERSION"] ? ENV["VERSION"].to_i : nil ) | |
end | |
task :environment do | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
require_relative './config/db' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ActiveSupport使ってそうなので
ENV["VERSION"].try(:to_i)
がいいかもですね