Skip to content

Instantly share code, notes, and snippets.

@tasugim
Created March 5, 2015 08:47
Show Gist options
  • Select an option

  • Save tasugim/423d68af2668daeeb903 to your computer and use it in GitHub Desktop.

Select an option

Save tasugim/423d68af2668daeeb903 to your computer and use it in GitHub Desktop.
非Rails環境でActiveRecordのマイグレーションを利用するRakefileのひな形
require 'active_record'
require 'logger'
task :default => 'db:migrate'
namespace :db do
MIGRATIONS_DIR = "db/migrate"
desc "Migrate the database"
task :migrate => :environment do
ActiveRecord::Migrator.migrate(MIGRATIONS_DIR, ENV["VERSION"] ? ENV["VERSION"] : nil)
end
desc "Roll back the database schema to the previous version"
task :rollback => :environment do
ActiveRecord::Migrator.rollback(MIGRATIONS_DIR, ENV["STEP"] ? ENV["STEP"] : 1)
end
task :environment do
ActiveRecord::Base.establish_connection(YAML.load(File.open('config/database.yml')))
ActiveRecord::Base.logger = Logger.new(File.open('log/migration.log', 'a'))
end
end
@tasugim

tasugim commented Mar 5, 2015

Copy link
Copy Markdown
Author

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