Created
April 8, 2014 19:48
-
-
Save pahagon/10179936 to your computer and use it in GitHub Desktop.
Migrate Rails 4
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 'active_record' | |
require 'foreigner' | |
require 'yaml' | |
require 'logger' | |
require 'pathname' | |
task :environment do | |
end | |
namespace :db do | |
task :load_config do | |
unless ActiveRecord::Tasks::DatabaseTasks.root | |
environment = ENV['RACK_ENV'] || 'development' | |
project_dir = Pathname.new File.join(__dir__, '..', '..') | |
config_file = Pathname.new File.join(project_dir, 'config', 'settings.yml') | |
config = YAML::load(config_file.open) | |
ActiveRecord::Tasks::DatabaseTasks.root = project_dir | |
ActiveRecord::Tasks::DatabaseTasks.migrations_paths = project_dir.join('db', 'migrations') | |
ActiveRecord::Tasks::DatabaseTasks.db_dir = 'db' | |
ActiveRecord::Tasks::DatabaseTasks.database_configuration = config | |
ActiveRecord::Tasks::DatabaseTasks.env = environment | |
ActiveRecord::Base.establish_connection ActiveRecord::Tasks::DatabaseTasks.database_configuration[environment] | |
ActiveRecord::Base.logger = Logger.new STDOUT | |
Foreigner.load | |
end | |
end | |
end | |
load "active_record/railties/databases.rake" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment