3

I am using Ruby on Rails v3.0.9 and I have a web application running in production mode. I would like to change and add some data in the database (also, I would like to make that these data changes take effect in development mode - that is, for example, that the added data should be present also in development mode when I am running and developing my application on my local machine)...

... what is "the best way"\"the most commonly used approach" to do that? I mean, for example, should I create a migration file with in some User.create(:name => '...', :surname => '...', ...) statements and run those or there are other ways to accomplish what I would like to do?

Note: I do not need to populate the database with initial data (I already made that in the seed.rb file). I just need to update and add database table rows.

3
  • migrations are the cleanest way to proceed. Do you have any problem with it? Aug 23, 2011 at 12:36
  • To make things cleaner, store your migration files in whatever folder you want and create customize your rake task baed on the defaults: github.com/rails/rails/blob/master/activerecord/lib/… Aug 23, 2011 at 14:08
  • @apneadiving - No, I have no problem.
    – Backo
    Aug 23, 2011 at 14:25

2 Answers 2

2

seed.rb should be use only for initial set of values.

rake task should be use only when you want to update data any existing columns.

migration should be use when you need to change the schema of the table.

1
  • I would like to perform a "data migration" (not changing the database schema).
    – Backo
    Aug 23, 2011 at 13:39
0

You should use the file db/seed.rb to accomplish this task

Here is an example on how to use it: http://asciicasts.com/episodes/179-seed-data

1
  • I used that to populate my database with "initial" data by using statements like 'User.find_or_create_by_name(...)'. What I can maje now in that file to accomplish what I would like to do (update and add data)?
    – Backo
    Aug 23, 2011 at 11:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.