Created
May 23, 2011 20:35
-
-
Save lukemelia/987543 to your computer and use it in GitHub Desktop.
Our replacement for schema.rb dump/load
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 :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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?