Skip to content

Instantly share code, notes, and snippets.

@jpemberthy
Created August 26, 2009 22:08
Show Gist options
  • Save jpemberthy/175882 to your computer and use it in GitHub Desktop.
Save jpemberthy/175882 to your computer and use it in GitHub Desktop.
config = Rails::Configuration.new
database = config.database_configuration[RAILS_ENV]["database"]
username = config.database_configuration[RAILS_ENV]["username"]
password = config.database_configuration[RAILS_ENV]["password"]
namespace :db do
#rake db:dump
desc "dumps the database to a sql file"
task :dump => :environment do
puts "Creating #{database}_dump.sql file."
`mysqldump -u "#{username}" --password="#{password}" "#{database}" > "#{database}"_dump.sql`
end
#rake db:dumpimport - Resets the DB.
desc "imports the #{database}_dump.sql file to the current db"
task :dumpimport => [:environment, :reset] do
`mysql -u root --password="#{password}" "#{database}" < "#{database}"_dump.sql`
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment