I'd like to be able to:
- Clear out one table, including resetting the primary key(s)
- Use db:seed to refill that table with new data
- Keep all other tables the same, with data intact
I understand this is possible by having a migration that drops the table and recreates it on rollback (like this blog post); however, that could be annoying to keep updated if I change the table schema in a later migration.
Is there a better way than the solution above to achieve the 3 effects I'm looking for, ideally one that dynamically adapts to the existing structure of the dropped table, either directly or through the collective impact of all applicable migrations? Thanks!
Edit: two things that may help other new people when using the answer below:
- In create_fixtures, my first argument ended up as "#{Rails.root}/test/fixtures" - I didn't know before hand about Rails.root
- For how to do basic custom rake tasks, there's a Railscast.