Skip to content

Instantly share code, notes, and snippets.

@revathskumar
Last active August 19, 2019 14:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save revathskumar/4662272 to your computer and use it in GitHub Desktop.
Save revathskumar/4662272 to your computer and use it in GitHub Desktop.
Simple Migration for cuba and sinatra
rake db:create
rake db:migrate
rake db:create RACK_ENV=production
rake db:migrate VERSION=10
require 'active_record'
task(:environment) do
env = ENV["RACK_ENV"] ? ENV["RACK_ENV"] : "development"
ActiveRecord::Base.establish_connection(YAML::load_file('config.yml')['database'][env])
end
namespace :db do
task(:create => :environment) do
env = ENV["RACK_ENV"] ? ENV["RACK_ENV"] : "development"
config = YAML::load_file('config.yml')['database'][env]
ActiveRecord::Base.establish_connection(config.merge('database' => nil))
ActiveRecord::Base.connection.create_database config['database']
end
task(:migrate => :environment) do
ActiveRecord::Migrator.migrate('db/migrate', ENV['VERSION'] ? ENV['VERSION'].to_i : nil)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment