I just came across this cool tip from Tom Preston-Werner of rubyisawesome.com. Basically, if you end a mysql commandline query with \G instead of a semicolon, you’ll get a nicely formatted query that is suitable for pasting into a YAML file.
But what if you are not using mysql? We have a project with postgres. There’s probably a psql command to do something similar, but there is also a database agnostic way: Just use the rails console! :)
>> puts User.find(:all).to_yaml
---
- !ruby/object:User
attributes:
status: unverified
salt: L52b2pxGCL
can_invite: "0"
hashed_password: L50/yIQjPCBiU
is_admin: "0"
id: "478674008"
first_name: Mickey
last_name: Mouse
watchlist_by_email: "0"
created_at: 2008-01-30 15:34:26
email: mickey@mouse.com


Leave a Reply