OK.
God Save the YAML
Ik heb YAML-dumping in een bestand gebruikt vanaf de ontwikkeling en dit in mijn productie geladen. Er was een hack met id, die is gewijzigd, omdat het auto_increament is.
ontwikkeling
user = User.find X
posts = user.posts
comments = user.comments
...
File.open("user.yml", "w") { |f| f << YAML::dump(user) }
File.open("comments.yml", "w"){ |f| f << YAML::dump(comments) }
File.open("posts.yml", "w") { |f| f << YAML::dump(posts) }
...
productie
user = YAML::load_file("user.yml")
posts = YAML::load_file("posts.yml")
comments = YAML::load_file("comments.yml")
new_user = user.clone.save # we should clone our object, because it isn't exist
posts.each do |p|
post = p.clone
post.user = new_user
post.save
end
...