0

I'm reseeding a fairly large database with updated static data and updated values which users engage with. However, I've noticed that reseeding the database clears all join tables for Has_and_belongs_to_many tables (all other user data, and tables remains unchanged).

Has anyone worked out a way around this where the data will be preserved when reseeding?

I'm using Rails & Postgresql

Stephen
  • 187
  • 12
  • If you're inserting new data as a part of your reseeding, you'll have to build those associations as well. Any associations left over from before seeding are conceptually suspect: incomplete, incorrect, etc. Also, when you say reseed are you talking about `rake db:drop db:create db:migrate db:seed`? or some manual db load? – jaydel Sep 29 '16 at 18:45
  • @jaydel I actually don't drop the tables. I simply write over the data with `rake db:seed`. And my seed file for each table looks like this: EG: `Industry.destroy_all`, `ActiveRecord::Base.connection.execute("TRUNCATE TABLE industries RESTART IDENTITY")`. `Industry.create(name: 'Accounting')` etc – Stephen Sep 30 '16 at 07:29

1 Answers1

1

As mentioned above you will need to recreate the associations. You can do this fairly straight forward in your seed file.

You might also look into the seed dump gem. This will allow you to snapshot your HABTM relationships and then export them into your db/seeds.rb (or whatever) file.

Brian
  • 120
  • 9