Robert Gabaree
2006-Sep-10 00:11 UTC
Where''s the correct place to put files to parse/add to a database?
Hi, If I have some files, say FOOD_DESCRIPTIONS and FOOD_GROUPS that I need to parse and add their values to a database, where''s the best place to put them if I am doing it via migrations? Is it bad to put them in the db/migrate folder along with the *.rb files? Thanks, Rob --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Gareth Adams
2006-Sep-10 00:49 UTC
Re: Where''s the correct place to put files to parse/add to a database?
Robert Gabaree <lists@...> writes:> If I have some files, say FOOD_DESCRIPTIONS and FOOD_GROUPS that I > need to parse and add their values to a database, where''s the best > place to put them if I am doing it via migrations? > > Is it bad to put them in the db/migrate folder along with the *.rb > files?Migrations don''t have to be to do with data structure. Any code can go into a migration, including MyModel.create( {...} ) statements The point is that you want these values to be inserted into the database at a particular time, so you don''t want them in a file that''s loaded every time rails starts, for example. Use that as a starting point.. Gareth --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Aaron Baldwin
2006-Sep-10 04:20 UTC
Re: Where''s the correct place to put files to parse/add to a database?
I usually create a folder in db called data_import and put my data import files and scripts there. You can use script/runner to execute your load programs within the Rails environment. ruby script/runner ''load "db/data_import/my_script.rb"'' Another way to run your data load program is with a custom rake task. In lib/tasks create a file with a .rake extension and then create a task: desc ''Load my data.'' task :load_my_data => :environment do load "#{RAILS_ROOT}/db/data_import/my_script.rb" end Then run it: rake load_my_data The money line here is "task :load_standards => :environment do". The => :environment says that this task requires the Rails environment to be loaded before its run. With either of these methods you can run your data load multiple times without mucking up your migrations. Aaron On Sep 9, 2006, at 6:11 PM, Robert Gabaree wrote:> > Hi, > > If I have some files, say FOOD_DESCRIPTIONS and FOOD_GROUPS that I > need to parse and add their values to a database, where''s the best > place to put them if I am doing it via migrations? > > Is it bad to put them in the db/migrate folder along with the *.rb > files? > > Thanks, > Rob > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---