https://sonarly.com/issue/7468?type=bug
The `upsertWorkspaceFeatureFlag` method uses a non-atomic find-then-save pattern instead of a database-level upsert, causing duplicate key violations under concurrent requests.
Fix: Replaced the non-atomic find-then-save pattern in `upsertWorkspaceFeatureFlag` with a database-level `upsert` using `conflictPaths: ['workspaceId', 'key']`, followed by `findOneOrFail` to retrieve the full entity for the return value.
**Why this approach:** The original commit `9883472d55c` deliberately switched from `upsert` to find/save because TypeORM's `upsert` doesn't reliably return all entity fields. The fix preserves the intent (returning a complete entity) while restoring atomicity by splitting into two steps: an atomic upsert (handles the race condition), then a find (returns the full entity).
This is the same pattern already used by `enableFeatureFlags` (line 66) in the same file, making it consistent with existing code.
**Changes:**
1. **`feature-flag.service.ts`** — Replaced `findOne` → conditional build → `save` with `upsert` → `findOneOrFail`
2. **`feature-flag.service.spec.ts`** — Updated mock repository to include `findOneOrFail`, updated test assertions to verify `upsert` and `findOneOrFail` calls instead of `save`