-
-
Save nateberkopec/4115248 to your computer and use it in GitHub Desktop.
db:structure:load for Rails 3.1
This file contains 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
namespace :db do | |
namespace :test do |schema| | |
schema[:clone_structure].abandon | |
desc "OVERWRITTEN - load the development_structure file using psql shell" | |
task :clone_structure => ["db:structure:dump", "db:test:purge"] do | |
config = ActiveRecord::Base.configurations['test'] | |
cmd = "psql #{psql_options} < db/development_structure.sql" | |
system cmd | |
end | |
end | |
namespace :structure do |schema| | |
desc "load the development_structure file using psql shell" | |
task :load => :environment do | |
config = ActiveRecord::Base.configurations[Rails.env] | |
cmd = "psql #{psql_options} < db/development_structure.sql" | |
system cmd | |
end | |
end | |
def psql_options | |
config = ActiveRecord::Base.configurations[Rails.env] | |
pwd = "-W #{config['password']} " if config['password'].to_s.length > 0 | |
user = "-U #{config['username'] || config['user']}" | |
[pwd, user, config['database']].join(" ") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment