Hi. What is the best way to pre-populate your database with records while developing, not testing? For example, I want to: 1) > [run this command to populate db] 2) > ruby script/server 3) now I can surf to localhost:3000 and my app will already have relevant data I''m hoping to use yaml to suck it in. Is there a way to use the Fixture class to handle this even though this is outside the typical testing methods? Thanks, Zack
That is a great question. I''ll be intersted to see the answers. I use mysql to do this for me. Basically, I create a file called data_load.sql. Rows in it look like this- INSERT INTO table (''field_1'', ''field_2'') VALUES (''value 1'', ''value 2''); Then every time I blow my development db away, I run - mysql -u <<user>> -p<<password>> database_name < data_load.sql I think it would be better to use yml because doing what I describe above is not DRY. I am always setting up the testing yml fixtures, and writting insert commands in my data_load.sql for the same records. To me, that seems like the worst kind of unDRYness. matt On 1/20/06, Zack Chandler <zackchandler@drainpatrol.com> wrote:> > Hi. > > What is the best way to pre-populate your database with records while > developing, not testing? > > For example, I want to: > 1) > [run this command to populate db] > 2) > ruby script/server > 3) now I can surf to localhost:3000 and my app will already have relevant > data > > I''m hoping to use yaml to suck it in. > > Is there a way to use the Fixture class to handle this even though this is > outside the typical testing methods? > > Thanks, > Zack > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060120/0602e2da/attachment.html
Matthew Palmer
2006-Jan-20 21:21 UTC
[Rails] Re: Pre-populate db with yaml outside of testing?
On Fri, Jan 20, 2006 at 12:00:08PM -0800, Zack Chandler wrote:> What is the best way to pre-populate your database with records while > developing, not testing? > > For example, I want to: > 1) > [run this command to populate db] > 2) > ruby script/server > 3) now I can surf to localhost:3000 and my app will already have relevant > data > > I''m hoping to use yaml to suck it in. > > Is there a way to use the Fixture class to handle this even though this is > outside the typical testing methods?As always, rake is your best friend. Run "rake load_fixtures" and all of the data in your fixtures will end up in the current environment''s database (default: development, but I presume that RAILS_ENV=production rake load_fixtures would do the obvious thing). - Matt -- A few minutes ago I attempted to give a flying fsck, but the best I could do was to watch it skitter across the floor. -- Anthony de Boer, ASR
Joshua Susser
2006-Jan-20 23:25 UTC
[Rails] Re: Pre-populate db with yaml outside of testing?
Matthew Palmer wrote:> As always, rake is your best friend. Run "rake load_fixtures" and all of > the data in your fixtures will end up in the current environment''s database > (default: development, but I presume that RAILS_ENV=production rake > load_fixtures would do the obvious thing).That''s all well and good... but is there an easy way to keep a set of fixtures for development that are different from the set you use for testing? thanks, j -- Posted via http://www.ruby-forum.com/.
Carl Fyffe
2006-Jan-21 17:33 UTC
[Rails] Re: Pre-populate db with yaml outside of testing?
I am surprised this has not come up earlier. How do most people pre-populate lookup values in the database? I was hoping there would be a structure similar to mocks (mocks/development and mocks/test) in the fixtures directory. If you build it like this then you are able to satisfy all of the different environments. I definitely don''t want my test data to be pushed into my database. Any suggestions would be great. On 1/20/06, Joshua Susser <joshua@tiralorn.com> wrote:> Matthew Palmer wrote: > > As always, rake is your best friend. Run "rake load_fixtures" and all of > > the data in your fixtures will end up in the current environment''s database > > (default: development, but I presume that RAILS_ENV=production rake > > load_fixtures would do the obvious thing). > > That''s all well and good... but is there an easy way to keep a set of > fixtures for development that are different from the set you use for > testing? > > thanks, > j > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Ezra Zygmuntowicz
2006-Jan-21 20:34 UTC
[Rails] Re: Pre-populate db with yaml outside of testing?
Here is a blog post by topfunky that might do what you are looking for: http://nubyonrails.topfunky.com/articles/2005/12/27/dump-or-slurp- yaml-reference-data Cheers- -Ezra On Jan 21, 2006, at 9:32 AM, Carl Fyffe wrote:> I am surprised this has not come up earlier. How do most people > pre-populate lookup values in the database? I was hoping there would > be a structure similar to mocks (mocks/development and mocks/test) in > the fixtures directory. If you build it like this then you are able to > satisfy all of the different environments. I definitely don''t want my > test data to be pushed into my database. Any suggestions would be > great. > > On 1/20/06, Joshua Susser <joshua@tiralorn.com> wrote: >> Matthew Palmer wrote: >>> As always, rake is your best friend. Run "rake load_fixtures" >>> and all of >>> the data in your fixtures will end up in the current >>> environment''s database >>> (default: development, but I presume that RAILS_ENV=production rake >>> load_fixtures would do the obvious thing). >> >> That''s all well and good... but is there an easy way to keep a set of >> fixtures for development that are different from the set you use for >> testing? >> >> thanks, >> j >> >> -- >> Posted via http://www.ruby-forum.com/. >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-Ezra Zygmuntowicz WebMaster Yakima Herald-Republic Newspaper ezra@yakima-herald.com 509-577-7732
Zack Chandler
2006-Jan-23 06:00 UTC
[Rails] Re: Pre-populate db with yaml outside of testing?
Thanks Ezra - I had looked at this as a possibility.>rake load_fixturesworks great for now. Zack -----Original Message----- From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Ezra Zygmuntowicz Sent: Saturday, January 21, 2006 12:35 PM To: rails@lists.rubyonrails.org Subject: Re: [Rails] Re: Pre-populate db with yaml outside of testing? Here is a blog post by topfunky that might do what you are looking for: http://nubyonrails.topfunky.com/articles/2005/12/27/dump-or-slurp- yaml-reference-data Cheers- -Ezra On Jan 21, 2006, at 9:32 AM, Carl Fyffe wrote:> I am surprised this has not come up earlier. How do most people > pre-populate lookup values in the database? I was hoping there would > be a structure similar to mocks (mocks/development and mocks/test) in > the fixtures directory. If you build it like this then you are able to > satisfy all of the different environments. I definitely don''t want my > test data to be pushed into my database. Any suggestions would be > great. > > On 1/20/06, Joshua Susser <joshua@tiralorn.com> wrote: >> Matthew Palmer wrote: >>> As always, rake is your best friend. Run "rake load_fixtures" >>> and all of >>> the data in your fixtures will end up in the current >>> environment''s database >>> (default: development, but I presume that RAILS_ENV=production rake >>> load_fixtures would do the obvious thing). >> >> That''s all well and good... but is there an easy way to keep a set of >> fixtures for development that are different from the set you use for >> testing? >> >> thanks, >> j >> >> -- >> Posted via http://www.ruby-forum.com/. >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-Ezra Zygmuntowicz WebMaster Yakima Herald-Republic Newspaper ezra@yakima-herald.com 509-577-7732 _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails