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! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sep 14, 7:47 am, phil <p...-o0Q4Q1ys/oVBDgjK7y7TUQ@public.gmane.org> 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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, 5:22 pm, gene tani <gene.t...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sep 14, 7:47 am, phil <p...-o0Q4Q1ys/oVBDgjK7y7TUQ@public.gmane.org> 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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:> 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, 5:22 pm, gene tani <gene.t...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> On Sep 14, 7:47 am, phil <p...-o0Q4Q1ys/oVBDgjK7y7TUQ@public.gmane.org> 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 >> > > > > >-- Sincerely, William Pratt --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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:> 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: >> 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, 5:22 pm, gene tani <gene.t...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> On Sep 14, 7:47 am, phil <p...-o0Q4Q1ys/oVBDgjK7y7TUQ@public.gmane.org> 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 >>> >> >> >> >> > > -- > Sincerely, > > William Pratt > > > >-- Sincerely, William Pratt --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 <phil-o0Q4Q1ys/oVBDgjK7y7TUQ@public.gmane.org> 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! > > > > >-- http://www.jeremymcanally.com/ My free Ruby e-book: http://www.humblelittlerubybook.com/book/ My blogs: http://www.mrneighborly.com/ http://www.rubyinpractice.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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... On Sep 14, 7:47 am, phil <p...-o0Q4Q1ys/oVBDgjK7y7TUQ@public.gmane.org> 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!--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---