feat: per-environment default region#3878
Conversation
Adds a nullable FK for per-environment default region selection. Resolution will fall back to the project default, then the global default.
Optional per-environment default region, mapped from the Prisma row in toAuthenticated(). Read in the trigger path to route runs.
getDefaultWorkerGroupForProject now checks the environment default before the project default. Adds resolveEffectiveDefaultWorkerGroupId as the shared fallback chain (env -> project -> global).
SetDefaultRegionService now sets RuntimeEnvironment.defaultWorkerGroupId (allowlist checks stay project-scoped). Regions route resolves the env in its loader and action.
RegionsPresenter marks the effective default (env -> project -> global) and all callers pass the current environment id.
Preview branches copy the parent env's defaultWorkerGroupId. Adds a unit test for the env -> project -> global fallback order.
Prisma's checked create input rejects a raw FK scalar alongside relation connects; use defaultWorkerGroup.connect instead.
🦋 Changeset detectedLatest commit: 1267e48 The changes in this PR will be included in the next version bump. This PR includes changesets to release 25 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughThis pull request implements per-environment default worker group selection. The change adds an optional 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 |
- Scope RegionsPresenter env lookup to the resolved project (+ archivedAt: null) so a mismatched env id can't surface a default from another project. - Index RuntimeEnvironment.defaultWorkerGroupId via a separate CONCURRENTLY migration to keep FK checks off a seq scan.
The org layout caches regions for useRegions(); the set-default action redirects to the same URL, so add a shouldRevalidate hook (mirroring the pause/resume pattern) to refresh the default shown in Test/Replay.
…e templates Two callers still read the project-level default directly, which the UI no longer updates. Use resolveEffectiveDefaultWorkerGroupId (env -> project -> global) in: - api.v1.workers isDefault flag - computeTemplateCreation.resolveMode (MICROVM template decision)
…lver - RuntimeEnvironment.defaultWorkerGroupId is now a plain nullable column (no FK, no relation, no index): a deleted region is tolerated and resolution falls back to project -> global. Avoids Prisma drift and FK-check overhead on a cold table. - api.v1.workers and computeTemplateCreation.resolveMode now reuse getDefaultWorkerGroupForProject instead of re-reading the global flag, so their isDefault / MICROVM decisions match exactly where runs route (and resolve the global default the same way as the trigger path).
RegionsPresenter now resolves the effective default through getDefaultWorkerGroupForProject (existence-checked env -> project -> global), so the UI default always matches where runs route and never points at a deleted region. Removes the id-only resolveEffectiveDefaultWorkerGroupId helper (and its test) now that all four sites share one resolver.
Moves the default region selection from the project to the environment level. Resolution now follows env default → project default → global default, so existing projects keep working with no backfill. The region allowlist stays project-scoped; only the default moves. Preview branches inherit their parent's region, and DEV stays disabled.