# YAML - How to load data directly

**URL:** <https://www.ruby-forum.com/t/yaml-how-to-load-data-directly/48895>\
**Category:** Rails\
**Created:** [November 26, 2005, 11:52am UTC](https://www.ruby-forum.com/t/yaml-how-to-load-data-directly/48895 "2005-11-26T11:52:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![etienne.durand](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ee59a6/32.png) [@etienne.durand](https://www.ruby-forum.com/u/etienne.durand)\
**Post date:** [November 26, 2005, 11:52am UTC](https://www.ruby-forum.com/t/yaml-how-to-load-data-directly/48895/1 "2005-11-26T11:52:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![etienne.durand](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ee59a6/32.png) [@etienne.durand](https://www.ruby-forum.com/u/etienne.durand)\
**Post date:** [November 26, 2005, 1:25pm UTC](https://www.ruby-forum.com/t/yaml-how-to-load-data-directly/48895/2 "2005-11-26T13:25:10Z")

</div>

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\<\> \<\<database\_name\>\> goes here  
\< \<\<path\_tp\_yaml\_file\_goes\_here\>\>

bruce

---

<div class="post-metadata">

**Author:** ![etienne.durand](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ee59a6/32.png) [@etienne.durand](https://www.ruby-forum.com/u/etienne.durand)\
**Post date:** [November 26, 2005, 3:33pm UTC](https://www.ruby-forum.com/t/yaml-how-to-load-data-directly/48895/3 "2005-11-26T15:33:43Z")

</div>

On 26-nov-2005, at 13:24, Bruce B. 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\<\> \<\<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

---

<div class="post-metadata">

**Author:** ![etienne.durand](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ee59a6/32.png) [@etienne.durand](https://www.ruby-forum.com/u/etienne.durand)\
**Post date:** [November 26, 2005, 4:26pm UTC](https://www.ruby-forum.com/t/yaml-how-to-load-data-directly/48895/4 "2005-11-26T16:26:06Z")

</div>

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.
