Skip to content

Instantly share code, notes, and snippets.

@andreimaxim
Created May 19, 2010 22:57
Show Gist options
  • Save andreimaxim/406962 to your computer and use it in GitHub Desktop.
Save andreimaxim/406962 to your computer and use it in GitHub Desktop.
APP_ROOT = File.dirname(File.expand_path(__FILE__))
CONFIG_FILE = File.join(APP_ROOT, "db", "config.yml")
MIGRATIONS_DIR = File.join(APP_ROOT, "db", "migrate")
namespace :db do
require "activerecord"
task :environment do
config = YAML.load_file(CONFIG_FILE)
environment = ENV["env"] ? ENV["env"] : "development"
ActiveRecord::Base.establish_connection(config[environment])
ActiveRecord::Base.logger = Logger.new(STDOUT)
end
desc "Migrate the database"
task :migrate => :environment do
version = ENV["v"].to_i if ENV["v"]
ActiveRecord::Migrator.migrate(MIGRATIONS_DIR, version)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment