Created
March 5, 2015 08:47
-
-
Save tasugim/423d68af2668daeeb903 to your computer and use it in GitHub Desktop.
非Rails環境でActiveRecordのマイグレーションを利用するRakefileのひな形
This file contains hidden or 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 '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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
参考情報