Skip to content

Instantly share code, notes, and snippets.

@ggaglani
Last active March 1, 2016 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ggaglani/ba49fd6d1932f8a116af to your computer and use it in GitHub Desktop.
Save ggaglani/ba49fd6d1932f8a116af to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'bundler/gem_tasks'
require 'rake'
require 'yaml'
require 'logger'
require 'active_record'
require 'mysql2'
#ActiveRecord database tasks.
include ActiveRecord::Tasks
class Seeder
def initialize(seed_file)
@seed_file = seed_file
end
def load_seed
raise "Seed file '#{@seed_file}' does not exist" unless File.file?(@seed_file)
load @seed_file
end
end
root = File.expand_path '..', __FILE__
DatabaseTasks.env = ENV['ENV'] || 'development'
DatabaseTasks.database_configuration = YAML.load(File.read(File.join(root, 'config/database.yml')))
DatabaseTasks.db_dir = File.join root, 'db'
DatabaseTasks.fixtures_path = File.join root, 'test/fixtures'
DatabaseTasks.migrations_paths = [File.join(root, 'db/migrate')]
DatabaseTasks.seed_loader = Seeder.new File.join root, 'db/seeds.rb'
DatabaseTasks.root = root
task :environment do
ActiveRecord::Base.configurations = DatabaseTasks.database_configuration
ActiveRecord::Base.establish_connection DatabaseTasks.env.to_sym
ActiveRecord::Base.logger = ActiveSupport::Logger.new("#{root}/log/scp_data_store.log")
end
load 'active_record/railties/databases.rake'
Dir.glob("#{Dir.pwd}/lib/tasks/*.rake") do |rakee|
load rakee
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment