Last active
November 18, 2024 16:59
-
-
Save chrisbloom7/10330 to your computer and use it in GitHub Desktop.
I honestly don't remember what I was attempting to accomplish with this, but it was important enough at the time to be my second Gist
This file contains hidden or 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
task :write => :environment do | |
dir = RAILS_ROOT + '/db/backup' | |
FileUtils.mkdir_p(dir) | |
FileUtils.chdir(dir) | |
interesting_tables.each do |tbl| | |
sql ||= ActiveRecord::Base.connection() | |
if (records = sql.execute("SELECT * FROM " + tbl) rescue false) | |
puts "Writing #{tbl}..." | |
collection = Array.new; records.each_hash(){|rec| collection.push rec } | |
File.open("#{tbl}.yml", 'w+') { |f| YAML.dump collection, f } | |
else | |
puts "Skipping #{tbl}..." | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment