bookio / server-old

2 stars 0 forks source link

Problem with seeds.rb #5

Closed meg768 closed 10 years ago

meg768 commented 10 years ago

When running "rake db:seed", all the icons get new id:s. This causes problems with existing data since the rentals.icon_id points out an old deleted icon.

Is it possible to override this so the id:s stays the same?

However, I changed the client side code to display a default icon if not found.

mounte commented 10 years ago

Ahh, sorry for not mentioning it. When developing I drop the database then create it, that way the id's start at 0. This is not ok however. So according to: http://stackoverflow.com/questions/2097052/rails-way-to-reset-seed-on-id-field we have solutions for sqlite and postgres.

I dont have time to test it at the moment, can someone implement and test? Otherwise I will do it later tonight.

magnus-engstrom commented 10 years ago

This is a common problem in using the default seeding functionality. Defining unique id:s and using .find_or_create() instead of .create() could make this a bit more manageable from a rails-perspective. Otherwise, as @mounte mentions, this can be handled by different kinds of database grooming.

However, long story short, I would recommend using https://github.com/mbleigh/seed-fu instead of doing any of the above.

mounte commented 10 years ago

Took a quick look at seed-fu since @mageng mentioned it and it looks nice. Gotta love the ecosystem of Ruby. I made a PR https://github.com/bookio/server/pull/6 that now uses seed-fu

meg768 commented 10 years ago

Yes, "rake db:seed_fu" now works and all the icons are inserted into the table with correct id:s. :)

meg768 commented 10 years ago

Thanks!

magnus-engstrom commented 10 years ago

:+1: