You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(api): make database seeding idempotent and preserve IDs
Corrects the `DatabaseSeedingService` to ensure the seeding process is
idempotent and correctly preserves the relationships between fixture
documents.
The previous implementation had two critical bugs:
1. It generated a new, random `ObjectId` on every run, which broke all
predefined relationships between entities.
2. It used an empty filter `{}` in its `replaceOne` operation, causing
it to overwrite existing documents incorrectly on subsequent runs.
This fix addresses these issues by:
- Using the predefined hex string ID from each fixture item to create a
deterministic `ObjectId`.
- Using `updateOne` with a specific `_id` in the filter, ensuring that
the correct document is targeted.
- Using the `$set` operator with `upsert: true` to safely insert or
update the document, making the entire process idempotent.
0 commit comments