Skip to content

Instantly share code, notes, and snippets.

@nateberkopec
Forked from xaviershay/db.rake
Created November 20, 2012 00:57
Show Gist options
  • Save nateberkopec/4115248 to your computer and use it in GitHub Desktop.
Save nateberkopec/4115248 to your computer and use it in GitHub Desktop.
db:structure:load for Rails 3.1
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