Skip to content

Instantly share code, notes, and snippets.

@alexdreher
Created December 30, 2010 11:24
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 alexdreher/759688 to your computer and use it in GitHub Desktop.
Save alexdreher/759688 to your computer and use it in GitHub Desktop.
old rails 2 rake task to dump db data into YAML files
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