Last active
December 22, 2024 15:50
-
-
Save revathskumar/4662272 to your computer and use it in GitHub Desktop.
Simple Migration for cuba and sinatra
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rake db:create |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rake db:migrate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rake db:create RACK_ENV=production | |
rake db:migrate VERSION=10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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