Files
supabase/apps/studio/data/config/project-creation-postgres-versions-query.ts
Manan GuptaandJoshen Lim 6a0518dd86 fix(studio): forward HA flag to project-creation pre-flight checks (#50902)
## Summary

- Fixes MUL-1678: toggling High Availability on in the project-creation
wizard 400'd for orgs that are HA-entitled but not enrolled in the "V3
rollout ramp" feature flag on the backend, because two pre-flight
endpoints Studio calls before project creation didn't know about HA and
hit the ramp check the real create-project call already bypasses.
- Threads `highAvailability` through
`useOrganizationAvailableRegionsQuery` (`GET
/platform/projects/available-regions`, sent as
`high_availability=true|false` on the query string) and
`useProjectCreationPostgresVersionsQuery` /
`useAvailableOrioleImageVersion` (`POST
/platform/organizations/:slug/available-versions`, sent as
`high_availability` in the body), including their query-key cache keys
so HA and non-HA responses for the same org/provider/size don't collide.
- Wires the (already form-tracked) `highAvailability` value into every
call site: `ProjectCreationForm.tsx`, `RegionSelector.tsx`, and a new
`highAvailability` prop on `PostgresVersionSelector.tsx` passed from
`InternalOnlyConfiguration.tsx`.

## Problem

The project-creation wizard's HA toggle is wired into the actual
project-create request, but two pre-flight calls Studio makes before
that (available regions, available Postgres versions) had no way to
signal HA, so the backend's ramp-flag gate rejected them for HA-entitled
orgs outside the ramp.

## Solution

Add an optional `highAvailability` field end-to-end on the Studio side:
query hook variables, cache keys, request serialization, and the
components that already track the toggle via `useWatch`.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* Available regions and database versions in project creation now
reflect the selected high-availability setting.
* The Create button remains disabled while available regions are
loading.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: GuptaManan100 <guptamanan100@gmail.com>
Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2026-09-29 20:39:01 +05:30

101 lines
2.6 KiB
TypeScript

import { useQuery } from '@tanstack/react-query'
import { CloudProvider } from 'shared-data'
import { configKeys } from './keys'
import { handleError, post } from '@/data/fetchers'
import type { ResponseError, UseCustomQueryOptions } from '@/types'
export type ProjectCreationPostgresVersionsVariables = {
cloudProvider: CloudProvider
dbRegion: string
organizationSlug: string | undefined
highAvailability?: boolean
}
export async function getPostgresCreationVersions(
{
cloudProvider,
dbRegion,
organizationSlug,
highAvailability,
}: ProjectCreationPostgresVersionsVariables,
signal?: AbortSignal
) {
if (!organizationSlug) throw new Error('organizationSlug is required')
const { data, error } = await post('/platform/organizations/{slug}/available-versions', {
params: { path: { slug: organizationSlug } },
body: { provider: cloudProvider, region: dbRegion, high_availability: highAvailability },
signal,
})
if (error) handleError(error)
return data
}
export type ProjectCreationPostgresVersionData = Awaited<
ReturnType<typeof getPostgresCreationVersions>
>
export type ProjectCreationPostgresVersionError = ResponseError
export const useProjectCreationPostgresVersionsQuery = <TData = ProjectCreationPostgresVersionData>(
{
cloudProvider,
dbRegion,
organizationSlug,
highAvailability,
}: ProjectCreationPostgresVersionsVariables,
{
enabled = true,
...options
}: UseCustomQueryOptions<
ProjectCreationPostgresVersionData,
ProjectCreationPostgresVersionError,
TData
> = {}
) => {
return useQuery<ProjectCreationPostgresVersionData, ProjectCreationPostgresVersionError, TData>({
queryKey: configKeys.projectCreationPostgresVersions(
organizationSlug,
cloudProvider,
dbRegion,
highAvailability
),
queryFn: ({ signal }) =>
getPostgresCreationVersions(
{ organizationSlug, cloudProvider, dbRegion, highAvailability },
signal
),
enabled:
enabled && typeof organizationSlug !== 'undefined' && organizationSlug !== '_' && !!dbRegion,
...options,
})
}
export const useAvailableOrioleImageVersion = (
{
cloudProvider,
dbRegion,
organizationSlug,
highAvailability,
}: ProjectCreationPostgresVersionsVariables,
{ enabled = true }: { enabled?: boolean } = {}
) => {
const { data } = useProjectCreationPostgresVersionsQuery(
{
cloudProvider,
dbRegion,
organizationSlug,
highAvailability,
},
{
enabled,
select(data) {
return (data?.available_versions ?? []).find((x) => x.postgres_engine === '17-oriole')
},
}
)
return data
}