I have to prepare a rather large amount of seed data for a Rails application. Based on my limited experience, I know of two ways to do it but want to know which offers the most flexibility.
One, I could do it with Rails and just prepare the seed data the way it’s used in the seeds.rb file
User.create!( name: "John" )
Or, I could create a json document of the data. For example, I know that Mongodb lets you import json documents directly into the database. I’m not sure about other databases…
It occurred to me that a json document might be the most flexible, because I suppose you could also use a regular expression script to turn the json into something like this User.create!( name: "John" )
However, I’m wondering if there’s any other issues I should consider…
One issue to consider is that you can’t always pass all the parameters through the constructor. Consider this:
If you have something like
User.create({name: 'John', role: 'admin'}), then your seed will fail because role will not be able to be assigned.