daily-code
daily-code copied to clipboard
optimised seed.ts to avoid seeding of DB problem while setting up the project
#313 #221 Addresses the first point in issue #248 (Improve the package management and make sure that seeding and migration don't fail.)
PR Fixes:
- 1 During setting up the project when seed command is executed sometimes it seeds and sometimes it fails and gives unique constraint problem. (The screenshot attached below of the problem).
screenshot:
- The reason for this being that the stopped container needs to be removed if not removed and restarted then, data is persisted which results in error during seed (failed to seed due to unique constraint)
- There are 2 open PR #221 #313 as per suggestions in comments of it, I tried resetting DB and skipping the seed during migrate process but, the issue persisted. Also in comments there was suggestion to use upsert instead of create. So using upsert I refactored the code. Since then, I have never faced issues during seeding process across multiple restarts of the container.
- The code is refactored in seed.ts to avoid DRY of the code.
Resolves #221 , #313 , Addresses the first point in issue #248
Checklist before requesting a review
- [x] I have performed a self-review of my code
@hkirat , Can you review this.