Skip to content

Instantly share code, notes, and snippets.

@thiagoramos23
Forked from drogus/Rakefile.rb
Created August 23, 2017 23:24
Show Gist options
  • Save thiagoramos23/323362d64db75da4106a6939d8fde808 to your computer and use it in GitHub Desktop.
Save thiagoramos23/323362d64db75da4106a6939d8fde808 to your computer and use it in GitHub Desktop.
This is the example contents of the Rakefile, which you would use to run active record tasks without using Rails. It assumes using the same directories as rails uses: `db/migrate`, `config/database.yml`.
require 'bundler/setup'
require 'active_record'
include ActiveRecord::Tasks
db_dir = File.expand_path('../db', __FILE__)
config_dir = File.expand_path('../config', __FILE__)
DatabaseTasks.env = ENV['ENV'] || 'development'
DatabaseTasks.db_dir = db_dir
DatabaseTasks.database_configuration = YAML.load(File.read(File.join(config_dir, 'database.yml')))
DatabaseTasks.migrations_paths = File.join(db_dir, 'migrate')
task :environment do
ActiveRecord::Base.configurations = DatabaseTasks.database_configuration
ActiveRecord::Base.establish_connection DatabaseTasks.env
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