Created
January 17, 2012 08:25
-
-
Save priceflex/1625638 to your computer and use it in GitHub Desktop.
Rake task to dump and load databases in rails
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 | |
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