Skip to content

Instantly share code, notes, and snippets.

@dcalixto
Forked from revathskumar/dbcreate.sh
Created August 19, 2019 14:55
Show Gist options
  • Save dcalixto/c3f946da2c95a875565413bacbb1f0e0 to your computer and use it in GitHub Desktop.
Save dcalixto/c3f946da2c95a875565413bacbb1f0e0 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