Skip to content

Instantly share code, notes, and snippets.

@lukemelia
Created May 23, 2011 20:35
Show Gist options
  • Save lukemelia/987543 to your computer and use it in GitHub Desktop.
Save lukemelia/987543 to your computer and use it in GitHub Desktop.
Our replacement for schema.rb dump/load
namespace :db do
namespace :structure do
desc "Dump the database structure to a SQL file"
task :dump => :load_config do
config = ActiveRecord::Base.configurations[Rails.env]
command = "mysqldump -u #{config["username"]} #{config["database"]} --no-data --skip-comments --skip-add-drop-table > db/#{Rails.env}_structure.sql"
puts "Running: #{command}"
system command
command = "mysqldump -u #{config["username"]} #{config["database"]} --skip-extended-insert --no-create-info --skip-comments --tables schema_migrations >> db/#{Rails.env}_structure.sql"
puts "Running: #{command}"
system command
end
end
end
namespace :db do
namespace :test do
desc "Load the test database from a SQL file"
task :prepare => "db:load_config" do
config = ActiveRecord::Base.configurations["test"]
command = "mysqladmin -u #{config["username"]} drop -f #{config["database"]}"
puts "Running: #{command}"
system command
command = "mysqladmin -u #{config["username"]} create #{config["database"]}"
puts "Running: #{command}"
system command
command = "mysql -u #{config["username"]} #{config["database"]} < db/development_structure.sql"
puts "Running: #{command}"
system command
end
end
end
@tispratik
Copy link

For a rails 2.3 project, i have put this file in the lib/tasks directory, but rails is not picking it up. When i run rake db:test:prepare, its running the old one. Can you tell me how you've hooked it up?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment