Pre-loading the database?

I am sure this has been asked before, but, I can't seem to find an example.

Our app needs a bunch of data pre-loaded into the database. What is the 'accepted' way of doing this?

Do I put the data into a migration? The same migration that I create the table in?

thanks!

it's faster to use the bulk load, like MySQL's LOAD DATA INFILE, or psql COPY. Every DBMS should have something with different names/ switches

Well, we're only talking about 100 rows (10 in one table 90 in another) that won't change. I was just going to put obj = Object.create(:attr => 'blah') in a migration file... It is only happening once, so speed is not a huge issue.

That should work fine if speed is not an issue. You could also put it in a separate ruby scrip and use script/runner to load them. This would allow you a little more flexibility as you could delete and reload data without having to migrate the database back and forth each time.

One thing you can do to dramatically increase speed in the script runner approach is to wrap all of the inserts in on transaction rather than each having it’s own.

Object.transaction do

Object.create(:attr => 'blah')

end

phil wrote:

I should have been a tad more clear on this:

Object.transaction do

Object.create(:attr => 'blah')

Object.create(:attr => 'blah1')

Object.create(:attr => 'blah2')

 ...

end

William Pratt wrote:

The best way I've seen is to create a Rake task of sorts (I was taught to use the task name 'bootstrap' which would let you call "rake bootstrap").

--Jeremy

Technically, this is called "bootstrapping".

I think usually it's done with a rake task.

For example, my app comes with a rake task called db:bootstrap with populates my data base with all the default data it needs to start, e.g. default admin, etc...