Skip to content

Instantly share code, notes, and snippets.

@priceflex
Created January 17, 2012 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save priceflex/1625638 to your computer and use it in GitHub Desktop.
Save priceflex/1625638 to your computer and use it in GitHub Desktop.
Rake task to dump and load databases in rails
namespace :db do
desc "create db copy file"
task :sgl_dump => :environment do
system "cp #{Rails.root}/db/development.sqlite3 #{Rails.root}/db/#{Date.today.to_s.split('-').join}-devdb"
end
desc "load latest db file"
task :sgl_load => :environment do
puts "Are you sure you want over write your database? YES/NO"
yn = STDIN.gets
if yn.chomp == "YES"
filename = Dir.glob("#{Rails.root}/db/*-devdb").map{ |file| file.scan(/\d/).join('') }.max
system "cp #{Rails.root}/db/#{filename}-devdb #{Rails.root}/db/development.sqlite3"
puts "Many bits where harmed during this operation. Shame on you!"
else
puts "No bits were harmed during this operation. You so nice!"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment