mirror of
https://github.com/supabase/supabase.git
synced 2026-09-22 13:37:53 +08:00
c5cffb6afb
`getHighAvailabilityRegionCode` had `staging` and `local` cases but no `prod` case, so it returned `undefined` in production and the High Availability region filtering never applied — the creation flow offered every AWS region while HA Alpha is only live in `us-east-1`. Adds the `prod` case returning `us-east-1`, matching staging. The region filter and the "High Availability projects are currently limited to…" banner both key off this value, so no other changes are needed. This keeps the accepted hardcoded-per-environment pattern for Alpha; the API/entitlement-driven enabled-regions design stays open on the ticket for when the rollout expands. **Changed:** - `ProjectCreation.utils.ts` — `prod` → `us-east-1` - `ProjectCreation.utils.test.ts` — the two env tables previously pinned prod as unrestricted; now expect `us-east-1` Addresses [FE-3716](https://linear.app/supabase/issue/FE-3716/show-enabled-regions) (and the folded-in MUL-1337). ## To test - `pnpm --filter studio exec vitest run components/interfaces/ProjectCreation/ProjectCreation.utils.test.ts` - In prod after deploy: new project → toggle High Availability → region select offers only East US (North Virginia) and shows the "limited to" notice; staging/local behavior unchanged (only the `prod` env branch changed) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - High-availability project creation now correctly uses the `us-east-1` region for production environments. - Region selection is now properly restricted to `us-east-1` when creating production projects. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
106 lines
3.6 KiB
TypeScript
106 lines
3.6 KiB
TypeScript
import type { CloudProvider, Region } from 'shared-data'
|
|
import { AWS_REGIONS } from 'shared-data'
|
|
import { SMART_REGION_TO_EXACT_REGION_MAP } from 'shared-data/regions'
|
|
|
|
import { DesiredInstanceSize, instanceSizeSpecs } from '@/data/projects/new-project.constants'
|
|
|
|
export function smartRegionToExactRegion(smartOrExactRegion: string) {
|
|
return SMART_REGION_TO_EXACT_REGION_MAP.get(smartOrExactRegion) ?? smartOrExactRegion
|
|
}
|
|
|
|
export function getAvailableRegions(
|
|
cloudProvider: CloudProvider,
|
|
environment = process.env.NEXT_PUBLIC_ENVIRONMENT
|
|
): Region {
|
|
switch (cloudProvider) {
|
|
case 'AWS':
|
|
case 'AWS_K8S':
|
|
return AWS_REGIONS
|
|
case 'AWS_NIMBUS':
|
|
if (environment !== 'prod') {
|
|
// Only allow Southeast Asia for Nimbus (local/staging)
|
|
return {
|
|
SOUTHEAST_ASIA: AWS_REGIONS.SOUTHEAST_ASIA,
|
|
}
|
|
}
|
|
|
|
// Only allow US East for Nimbus (prod)
|
|
return {
|
|
EAST_US: AWS_REGIONS.EAST_US,
|
|
}
|
|
default:
|
|
throw new Error('Invalid cloud provider')
|
|
}
|
|
}
|
|
|
|
type ResolveDefaultDbRegionArgs = {
|
|
cloudProvider: CloudProvider
|
|
isHighAvailabilityRestricted: boolean
|
|
highAvailabilityRegionName: string | undefined
|
|
isSmartRegionEnabled: boolean
|
|
recommendedSmartRegion: string | undefined
|
|
autoDefaultRegion: string | undefined
|
|
fixedDefaultRegion: string
|
|
environment?: string
|
|
}
|
|
|
|
export function resolveDefaultDbRegion({
|
|
cloudProvider,
|
|
isHighAvailabilityRestricted,
|
|
highAvailabilityRegionName,
|
|
isSmartRegionEnabled,
|
|
recommendedSmartRegion,
|
|
autoDefaultRegion,
|
|
fixedDefaultRegion,
|
|
environment = process.env.NEXT_PUBLIC_ENVIRONMENT,
|
|
}: ResolveDefaultDbRegionArgs): string | undefined {
|
|
if (isHighAvailabilityRestricted) return highAvailabilityRegionName
|
|
if (isSmartRegionEnabled) return recommendedSmartRegion
|
|
|
|
// The geolocated default is only usable if the provider actually offers that region
|
|
// (e.g. AWS_NIMBUS is restricted to a single region)
|
|
const isAutoDefaultRegionAvailable = Object.entries(
|
|
getAvailableRegions(cloudProvider, environment)
|
|
).some(([, region]) => region.displayName === autoDefaultRegion)
|
|
|
|
return isAutoDefaultRegionAvailable && autoDefaultRegion !== undefined
|
|
? autoDefaultRegion
|
|
: fixedDefaultRegion
|
|
}
|
|
|
|
/**
|
|
* When launching new projects, they only get assigned a compute size once successfully launched,
|
|
* this might assume wrong compute size, but only for projects being rapidly launched after one another on non-default compute sizes.
|
|
*
|
|
* Needs to be in the API in the future [kevin]
|
|
*/
|
|
export const monthlyInstancePrice = (instance: string | undefined): number => {
|
|
return instanceSizeSpecs[instance as DesiredInstanceSize]?.priceMonthly || 10
|
|
}
|
|
|
|
export const instanceLabel = (instance: string | undefined): string => {
|
|
return instanceSizeSpecs[instance as DesiredInstanceSize]?.label || 'Micro'
|
|
}
|
|
|
|
export const getHighAvailabilityRegionCode = (
|
|
environment = process.env.NEXT_PUBLIC_ENVIRONMENT
|
|
) => {
|
|
// Local dev stacks can run in any of the supported regions, so they're left unrestricted
|
|
if (environment === 'prod') return 'us-east-1'
|
|
if (environment === 'staging') return 'us-east-1'
|
|
if (environment === 'local') return 'eu-central-1'
|
|
return undefined
|
|
}
|
|
|
|
export const filterHighAvailabilityRegions = <T extends { code: string }>(
|
|
regions: T[],
|
|
highAvailability: boolean,
|
|
environment = process.env.NEXT_PUBLIC_ENVIRONMENT
|
|
) => {
|
|
const isLocal = environment === 'local'
|
|
const regionCode = getHighAvailabilityRegionCode(environment)
|
|
return highAvailability && !isLocal && regionCode !== undefined
|
|
? regions.filter((region) => region.code === regionCode)
|
|
: regions
|
|
}
|