Created
December 30, 2010 11:24
-
-
Save alexdreher/759688 to your computer and use it in GitHub Desktop.
old rails 2 rake task to dump db data into YAML files
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
namespace :generate do | |
desc "Overwrite all fixture files with the contents of all existing tables" | |
task :all => :environment do | |
tables = ActiveRecord::Base.connection.tables | |
tables.each do |table_name| | |
if not table_name == "schema_migrations" | |
File.open("db/seed_fixtures/#{table_name}.yml", 'w') do |file| | |
data = ActiveRecord::Base.connection.select_all("SELECT * FROM #{table_name}") | |
rows = {} | |
data.each do |record| | |
fixture_name = record['symbolic_name'].blank? ? | |
"#{table_name}_#{record['id']}" : | |
record['symbolic_name'].downcase | |
rows[fixture_name] = record | |
end | |
file.write rows.to_yaml | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment