Skip to content

Instantly share code, notes, and snippets.

@jugyo
Created May 6, 2012 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jugyo/2624944 to your computer and use it in GitHub Desktop.
Save jugyo/2624944 to your computer and use it in GitHub Desktop.
the db:migrate task using ActiveRecord without Rails
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
@r7kamura
Copy link

r7kamura commented May 6, 2012

ActiveSupport使ってそうなので ENV["VERSION"].try(:to_i) がいいかもですね

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment