fix(webapp): prevent duplicate envs from provision race#4261
Conversation
|
WalkthroughAdds a partial unique index enforcing one root Staging or Preview environment per project and runtime type. Updates environment upsert logic to identify root environments, handle Prisma unique-constraint conflicts from overlapping creation requests, re-query the existing environment, and update its concurrency limits. Adds schema documentation and a server-changes entry. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| @@ -0,0 +1,4 @@ | |||
| CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS "RuntimeEnvironment_projectId_type_staging_preview_root_key" | |||
There was a problem hiding this comment.
Do not merge until this has been backfilled.
Fixes TRI-12078
Summary
Prevents concurrent environment setup requests from creating duplicate Staging and Preview environments.
Fix
Adds database-enforced uniqueness for root Staging and Preview environments.
If two requests race, the losing request loads the environment created by the winner and continues successfully instead of creating a duplicate or returning an error.