Hi, I would like to fill up a development database with some data (YAML files). YAML is ready, but I don''t have any clue to load them into AR objects, and persist them to the database (files are utf-8). Any help? Jean-Etienne
Jean-Etienne: I may have missed your point, but in case I didn''t and this saves you some time. Open terminal and type something like this: mysql - u root -p<<password goes here>> <<database_name>> goes here < <<path_tp_yaml_file_goes_here>> bruce On 25-Nov-05, at 3:48 PM, Jean-Etienne Durand wrote:> Hi, > > I would like to fill up a development database with some data (YAML > files). YAML is ready, but I don''t have any clue to load them into > AR objects, and persist them to the database (files are utf-8). > Any help? > > Jean-Etienne > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
On 26-nov-2005, at 13:24, Bruce Balmer wrote:> Jean-Etienne: > > I may have missed your point, but in case I didn''t and this saves > you some time. > > Open terminal and type something like this: > > mysql - u root -p<<password goes here>> <<database_name>> goes > here < <<path_tp_yaml_file_goes_here>>Since when MySQL directly supports YAML dumps, may I ask? -- Julian ''Julik'' Tarkhanov me at julik.nl
If you want to load your test fixtures to the development database, just run "rake load_fixtures". If you want to have separate fixtures for dev and test, put your dev fixtures in another directory (say, "db/fixtures") and copy this to lib/tasks/fixtures.rake or your Rakefile: desc "Load fixtures into the current environment''s database" task :load_dev_fixtures => :environment do require ''active_record/fixtures'' ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym) Dir.glob(File.join(RAILS_ROOT, ''db'', ''fixtures'', ''*.yml'')).each do |fixture_file| Fixtures.create_fixtures(''db/fixtures'', File.basename (fixture_file, ''.*'')) end end Which is just a copy of the original load_fixtures tasks from rails/ railties/lib/tasks/database.rake with the paths changed. On Nov 26, 2005, at 8:55 AM, Julian ''Julik'' Tarkhanov wrote:> > On 26-nov-2005, at 13:24, Bruce Balmer wrote: > >> Jean-Etienne: >> >> I may have missed your point, but in case I didn''t and this saves >> you some time. >> >> Open terminal and type something like this: >> >> mysql - u root -p<<password goes here>> <<database_name>> goes >> here < <<path_tp_yaml_file_goes_here>> > > Since when MySQL directly supports YAML dumps, may I ask? > > -- > Julian ''Julik'' Tarkhanov > me at julik.nl > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
OK, let me explain what i want to do: I am grabbing some info on a web site, and using my AR model to create objects, but I don''t persist them, i prefer saving them to an YAML file (obviously, i don''t have to parse only html files all the time, with a cache mechanism, i first look up if exists in the YAML files). Here is the problem: I create some AR objects, and i to_yaml to a file. Then, i just copy/paste to a fixture. The problem is that the format is a bit different (one level deeper) and i got some error when executing the yaml file. Has anyone experiences on this field? Thank you again :) Jean-Etienne
"rake --tasks" or "rake -T" will give you a list of all available tasks. Most of them are undocumented. You can also learn a lot by browsing the Rails source. Rake tasks are defined inside "railties/lib/tasks". Either download it locally or use the dev browser at http://dev.rubyonrails.org/browser/ On Dec 11, 2005, at 9:26 AM, Thibaut Barrère wrote:> > If you want to load your test fixtures to the development database, > > just run "rake load_fixtures". > > I''ve been looking for that! Thanks a lot. > > Where did you learn that ? Is it somewhere in the faq or the > documentation ? > > regards > > Thibaut_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails