mirror of
https://github.com/supabase/supabase.git
synced 2026-10-07 10:25:06 +03:00
## Context
Realised that we were calling both `useDefaultRegionQuery` and
`useOrganizationAvailableRegionsQuery` in the new project page.
`smartRegionEnabled` defaults to `false` at the beginning while the
flags are still being loaded, to this calls `useDefaultRegionQuery`. But
once the flags are loaded and `smartRegionEnabled` becomes `true`, then
the other hook is called
## Changes involved
- Checks that the flags are loaded first before calling either hooks to
prevent unnecessarily triggering both
- Adjust `defaultRegion` to remove hardcode
- Check smart region first, then default back to default specific region
- Renamed variables to be clearer:
- `autoDefaultRegion` (check based on location)
- `fixedDefaultRegion` (hardcoded in repo)
- Update `useEffect` on `regionError` to only reset the region value if
the default value is not undefined
- Also just a tiny nit to re-arrange to group the `useEffects` together
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Region selection now waits for feature flags to load before fetching
default and “smart” region options, preventing premature or incorrect
region choices.
* New project setup now updates the database region and smart
recommendations more consistently, with improved fallback behavior when
region lookup fails.
* AWS Nimbus default region is now environment-aware: non-prod uses
Southeast Asia, while prod uses East US.
* Default privilege settings now stay in sync more reliably during
setup, updating only when appropriate.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
158 lines
3.7 KiB
TypeScript
158 lines
3.7 KiB
TypeScript
import { AWS_REGIONS, FLY_REGIONS } from 'shared-data'
|
|
|
|
import type { components } from '@/data/api'
|
|
import { useCustomContent } from '@/hooks/custom-content/useCustomContent'
|
|
|
|
export const AWS_REGIONS_DEFAULT =
|
|
process.env.NEXT_PUBLIC_ENVIRONMENT !== 'prod'
|
|
? AWS_REGIONS.SOUTHEAST_ASIA
|
|
: AWS_REGIONS.EAST_US_2
|
|
|
|
// TO DO, change default to US region for prod
|
|
export const FLY_REGIONS_DEFAULT = FLY_REGIONS.SOUTHEAST_ASIA
|
|
|
|
export const MANAGED_BY = {
|
|
VERCEL_MARKETPLACE: 'vercel-marketplace',
|
|
AWS_MARKETPLACE: 'aws-marketplace',
|
|
STRIPE_PROJECTS: 'stripe-projects',
|
|
SUPABASE: 'supabase',
|
|
}
|
|
|
|
export type ManagedBy = (typeof MANAGED_BY)[keyof typeof MANAGED_BY]
|
|
|
|
export const PRICING_TIER_LABELS_ORG = {
|
|
FREE: 'Free - $0/month',
|
|
PRO: 'Pro - $25/month',
|
|
TEAM: 'Team - $599/month',
|
|
}
|
|
|
|
export const PRICING_TIER_PRODUCT_IDS = {
|
|
FREE: 'tier_free',
|
|
PRO: 'tier_pro',
|
|
PAYG: 'tier_payg',
|
|
TEAM: 'tier_team',
|
|
ENTERPRISE: 'tier_enterprise',
|
|
}
|
|
|
|
export function useDefaultProvider() {
|
|
const defaultProvider = 'AWS'
|
|
|
|
const { infraCloudProviders: validCloudProviders } = useCustomContent(['infra:cloud_providers'])
|
|
|
|
if (validCloudProviders?.includes(defaultProvider)) {
|
|
return defaultProvider
|
|
}
|
|
|
|
return validCloudProviders?.[0] ?? 'AWS'
|
|
}
|
|
|
|
export const PROVIDERS = {
|
|
FLY: {
|
|
id: 'FLY',
|
|
name: 'Fly.io',
|
|
default_region: FLY_REGIONS_DEFAULT,
|
|
regions: { ...FLY_REGIONS },
|
|
},
|
|
AWS: {
|
|
id: 'AWS',
|
|
name: 'AWS',
|
|
DEFAULT_SSH_KEY: 'supabase-app-instance',
|
|
default_region: AWS_REGIONS_DEFAULT,
|
|
regions: { ...AWS_REGIONS },
|
|
},
|
|
AWS_K8S: {
|
|
id: 'AWS_K8S',
|
|
name: 'AWS (Revamped)',
|
|
DEFAULT_SSH_KEY: 'supabase-app-instance',
|
|
default_region: AWS_REGIONS_DEFAULT,
|
|
regions: { ...AWS_REGIONS },
|
|
},
|
|
AWS_NIMBUS: {
|
|
id: 'AWS_NIMBUS',
|
|
name: 'AWS (Nimbus)',
|
|
default_region:
|
|
process.env.NEXT_PUBLIC_ENVIRONMENT !== 'prod'
|
|
? AWS_REGIONS.SOUTHEAST_ASIA
|
|
: AWS_REGIONS.EAST_US,
|
|
regions: { ...AWS_REGIONS },
|
|
},
|
|
} as const
|
|
|
|
export const PROJECT_STATUS: {
|
|
[key: string]: components['schemas']['ProjectDetailResponse']['status']
|
|
} = {
|
|
INACTIVE: 'INACTIVE',
|
|
ACTIVE_HEALTHY: 'ACTIVE_HEALTHY',
|
|
ACTIVE_UNHEALTHY: 'ACTIVE_UNHEALTHY',
|
|
COMING_UP: 'COMING_UP',
|
|
UNKNOWN: 'UNKNOWN',
|
|
GOING_DOWN: 'GOING_DOWN',
|
|
INIT_FAILED: 'INIT_FAILED',
|
|
REMOVED: 'REMOVED',
|
|
RESTARTING: 'RESTARTING',
|
|
RESTORING: 'RESTORING',
|
|
RESTORE_FAILED: 'RESTORE_FAILED',
|
|
UPGRADING: 'UPGRADING',
|
|
PAUSING: 'PAUSING',
|
|
PAUSE_FAILED: 'PAUSE_FAILED',
|
|
RESIZING: 'RESIZING',
|
|
}
|
|
|
|
export const DEFAULT_MINIMUM_PASSWORD_STRENGTH = 4
|
|
|
|
export const PASSWORD_STRENGTH = {
|
|
0: 'This password is not acceptable.',
|
|
1: 'This password is not secure enough.',
|
|
2: 'This password is not secure enough.',
|
|
3: 'Not bad, but your password must be harder to guess.',
|
|
4: 'This password is strong.',
|
|
}
|
|
|
|
export const PASSWORD_STRENGTH_COLOR = {
|
|
0: 'bg-red-900',
|
|
1: 'bg-red-900',
|
|
2: 'bg-yellow-900',
|
|
3: 'bg-yellow-900',
|
|
4: 'bg-green-900',
|
|
}
|
|
|
|
export const PASSWORD_STRENGTH_PERCENTAGE = {
|
|
0: 10,
|
|
1: 30,
|
|
2: 50,
|
|
3: 80,
|
|
4: 100,
|
|
}
|
|
|
|
export const DEFAULT_PROJECT_API_SERVICE_ID = 1
|
|
|
|
export type InstanceSpecs = {
|
|
baseline_disk_io_mbs: number
|
|
connections_direct: number
|
|
connections_pooler: number
|
|
cpu_cores: number | 'Shared'
|
|
cpu_dedicated: boolean
|
|
max_disk_io_mbs: number
|
|
memory_gb: number
|
|
}
|
|
|
|
export const INSTANCE_NANO_SPECS: InstanceSpecs = {
|
|
baseline_disk_io_mbs: 43,
|
|
connections_direct: 30,
|
|
connections_pooler: 200,
|
|
cpu_cores: 'Shared',
|
|
cpu_dedicated: false,
|
|
max_disk_io_mbs: 2085,
|
|
memory_gb: 0.5,
|
|
}
|
|
|
|
export const INSTANCE_MICRO_SPECS: InstanceSpecs = {
|
|
baseline_disk_io_mbs: 87,
|
|
connections_direct: 60,
|
|
connections_pooler: 200,
|
|
cpu_cores: 2,
|
|
cpu_dedicated: false,
|
|
max_disk_io_mbs: 2085,
|
|
memory_gb: 1,
|
|
}
|