By default, tasks like rake db:migrate are available in Rails but not in a Ruby project that includes ActiveRecord. Fortunately, with a couple of lines added to your Rakefile this issue can be fixed.
// Rakefile
DatabaseTasks.env = ENV['YOUR_ENV_VAR'] || 'development'
DatabaseTasks.db_dir = 'db'
DatabaseTasks.database_configuration = YAML.load_file('config/database.yml')
DatabaseTasks.migrations_paths = "#{DatabaseTasks.db_dir}/migrate"
task :environment do
ActiveRecord::Base.configurations = DatabaseTasks.database_configuration
ActiveRecord::Base.establish_connection DatabaseTasks.env.to_sym
end
load 'active_record/railties/databases.rake'
And voila. Now, you can use create, migrate, and all of the other rake db tasks you're used to in a Rails project.
No comments:
Post a Comment