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!

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…

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

On 9/14/07, phil [email protected] wrote:

thanks!


http://www.jeremymcanally.com/

My free Ruby e-book:
http://www.humblelittlerubybook.com/book/

My blogs:
http://www.mrneighborly.com/
http://www.rubyinpractice.com/

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.

On Sep 14, 7:47 am, phil [email protected] wrote:

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

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 P. wrote:

Object.transaction do

Our app needs a bunch of data pre-loaded into the database. What is


Sincerely,

William P.

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:

the table in?


Sincerely,

William P.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs