mirror of
https://github.com/supabase/supabase.git
synced 2026-09-08 10:59:38 +08:00
## What kind of change does this PR introduce? Studio data-layer migration. ## What is the current behavior? Studio loads complete publication details through the original bulk endpoint and creates publications by executing SQL against the source database. Publication and source-table data use names where stable table IDs are available. ## What is the new behavior? Uses the v2 publication-name, publication-detail, publication mutation, and source-table endpoints. The existing creation sheet continues to behave the same, including publishing partition changes through the parent table by default. Initial-sync selection and Analytics Bucket associations now consume the selected publication detail. Generated platform API types and their required nullability updates are included. The generated Platform contract accounts for roughly 10,000 changed lines in this PR. ## Dependency Depends on the v2 source table, table column, and publication endpoints from [supabase/platform#37505](https://github.com/supabase/platform/pull/37505), which are deployed to production. ## To test 1. Open the pipeline creation sheet and select an existing publication. 2. Create a publication with mixed-case schema and table names, then confirm the table names are shown while stable IDs are submitted. 3. Exercise all four initial-sync policies, including selecting individual tables. 4. Reopen the publication and table selectors and confirm they refresh without replacing populated options. 5. Edit and delete a publication. 6. Open an Analytics Bucket associated with a pipeline and confirm its publication tables resolve correctly. 7. Confirm unlimited WAL retention renders as Unlimited on pipeline status. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Improved replication publication setup with on-demand table loading, refresh controls, clearer table labels, and streamlined publication selection. - Publication creation and updates now use the latest replication API and table-based configurations. - Added clearer handling for tables removed from publications, including stale-selection warnings. - **Bug Fixes** - Prevented table selections from carrying over when switching publications. - Improved replication status displays when lag or WAL metrics are unavailable. - Updated replication deletion and table management for the latest API behavior. - **Tests** - Expanded coverage for publication creation, table selection, stale tables, loading states, and replication metrics. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
51 lines
1.9 KiB
TypeScript
51 lines
1.9 KiB
TypeScript
import { queryOptions, useQuery } from '@tanstack/react-query'
|
|
|
|
import { REPLICATION_METADATA_FRESHNESS_MS } from './constants'
|
|
import { replicationKeys } from './keys'
|
|
import { get, handleError } from '@/data/fetchers'
|
|
import type { ResponseError, UseCustomQueryOptions } from '@/types'
|
|
|
|
type ReplicationTablesParams = { projectRef?: string; sourceId?: number }
|
|
|
|
async function fetchReplicationTables(
|
|
{ projectRef, sourceId }: ReplicationTablesParams,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (!projectRef) throw new Error('projectRef is required')
|
|
if (!sourceId) throw new Error('sourceId is required')
|
|
|
|
const { data, error } = await get('/platform/replication/v2/{ref}/sources/{source_id}/tables', {
|
|
params: { path: { ref: projectRef, source_id: sourceId } },
|
|
signal,
|
|
})
|
|
if (error) {
|
|
handleError(error)
|
|
}
|
|
|
|
return data.tables
|
|
}
|
|
|
|
export type ReplicationTablesData = Awaited<ReturnType<typeof fetchReplicationTables>>
|
|
|
|
type ReplicationTablesQueryOptions<TData> = Omit<
|
|
UseCustomQueryOptions<ReplicationTablesData, ResponseError, TData>,
|
|
'enabled'
|
|
> & { enabled?: boolean }
|
|
|
|
export const replicationTablesQueryOptions = <TData = ReplicationTablesData>(
|
|
{ projectRef, sourceId }: ReplicationTablesParams,
|
|
{ enabled = true, ...options }: ReplicationTablesQueryOptions<TData> = {}
|
|
) =>
|
|
queryOptions<ReplicationTablesData, ResponseError, TData>({
|
|
queryKey: replicationKeys.tables(projectRef, sourceId),
|
|
queryFn: ({ signal }) => fetchReplicationTables({ projectRef, sourceId }, signal),
|
|
enabled: enabled && typeof projectRef !== 'undefined' && typeof sourceId !== 'undefined',
|
|
staleTime: REPLICATION_METADATA_FRESHNESS_MS,
|
|
...options,
|
|
})
|
|
|
|
export const useReplicationTablesQuery = <TData = ReplicationTablesData>(
|
|
{ projectRef, sourceId }: ReplicationTablesParams,
|
|
options: ReplicationTablesQueryOptions<TData> = {}
|
|
) => useQuery(replicationTablesQueryOptions({ projectRef, sourceId }, options))
|