As mentioned earlier, the ar_fixtures plugin is ideal for this type of
need.   You can find out more about it here:

http://nubyonrails.com/articles/2005/12/27/dump-or-slurp-yaml-reference-data

Basically you get the table to look the way you want in your
development DB, and than dump to a file.  From than on you can load
from that file.  Pretty slick.  You can also generate fixtures for
your tests using this plugin.  Should be as easy as script/plugin
install ar_fixtures.

Chris

P.S.  You should try and learn some SQL it comes in extremely handy
and is often times necessary for the real fun stuff.

On 1/15/07, Scott Hodson <[EMAIL PROTECTED]> wrote:
One tool I use to generate lots of similar-looking statements is Excel or
any other spreadsheet program.  See the attached XLS file.  Just cut and
past the columns that repeat, and separate out the User.create data into a
separate column.  Then copy and paste the worksheet into a text editor and
remove all of the \t characters that usually gets pasted in.

The more elegant way would be to create a collection of the values that
change, iterate through them (like :name) and call User.create.

The nice thing about the spreadsheet is that you can easily make changes en
masse to your scripts and re-use them as needed.  As a person with lots of
DBA experience creating SQL scripts like this has come in handy many times.
I don't see why you couldn't use the same approach with migrations code
either.


On 1/15/07, Kevin Burk <[EMAIL PROTECTED]> wrote:
> This may be another basic question, but I can't find a coherent
> answer anywhere in either Rails or SQL books.
>
> I need to load a chunk of data into my SQL database. I'd like to do
> this using a data migration in Rails.
> Until now, I've created the migration, and edited the migration file
> with the full code:
>
> User.create(:name => 'Kevin Burk',
>           :city => 'San Diego')
>
> User.create(:name => 'Someone Else',
>           :city => 'San Diego')
>
> and so forth. This is rather tedious, especially when I have a great
> deal of data I want to incorporate. However, it does allow me to add
> and drop all of the development data as needed, which is what I want.
>
> In AWR2, in the migrations chapter, they talk about loading data from
> fixtures, using a YAML file. The form and syntax of the YAML file is
> never discussed, and I can't get a straight answer from the author
> telling me how to structure the YAML file. He's talking about row
> labels, which I don't understand-and they don't seem to relate to the
> "id" field for the row that is automatically generated when I run the
> User.create() function in the migration file.
>
> I have no SQL experience, and no desire to go under the hood with
> SQL. However, there must be a way that I can create an external data
> file (as YAML, text, or whatever) that involves less typing, easier
> syntax, and keeps my data_migration.rb files reasonably small.
>
> Using the User.create() approach in the rails migration is already a
> vast improvement over the raw SQL INSERT code. I'd just like to know
> if there's an easier way-and if there is, to have it described in
> great detail because I lack the programming background to make some
> very fundamental connections about how certain things are done.
>
> Thanks for your help!
>
> Kevin Burk
> --
> ***************************************
> BURK DESIGN GROUP
> http://www.BurkDesignGroup.com
> mailto: [EMAIL PROTECTED]
> 6161 El Cajon Blvd #306
> San Diego, CA 92115
> PHONE (619) 583-2311
> FAX (619) 583-5801
> ***************************************
> _______________________________________________
> Sdruby mailing list
> [email protected]
> http://lists.sdruby.com/mailman/listinfo/sdruby
>


_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby




_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby

Reply via email to