mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 18:05:11 +03: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>
293 lines
9.0 KiB
TypeScript
293 lines
9.0 KiB
TypeScript
import { screen } from '@testing-library/react'
|
|
import { platformComponents as components } from 'api-types'
|
|
import { mockAnimationsApi } from 'jsdom-testing-mocks'
|
|
import { HttpResponse } from 'msw'
|
|
import { describe, expect, test, vi } from 'vitest'
|
|
|
|
import { DestinationRow } from './DestinationRow'
|
|
import { customRender } from '@/tests/lib/custom-render'
|
|
import { addAPIMock, type APIErrorBody } from '@/tests/lib/msw'
|
|
|
|
type ReplicationPipelinesResponse = components['schemas']['PipelinesResponse_Output']
|
|
type ReplicationDestinationResponse = components['schemas']['DestinationResponse_Output']
|
|
type ReplicationSourcesResponse = components['schemas']['SourcesResponse_Output']
|
|
type ReplicationPipelineStatusResponse = components['schemas']['PipelineStatusResponse_Output']
|
|
type ReplicationPipelineReplicationStatusResponse =
|
|
components['schemas']['PipelineReplicationStatusResponse_Output']
|
|
type ReplicationPipelineVersionResponse = components['schemas']['PipelineVersionResponse_Output']
|
|
|
|
// Tooltip/Popover descendants use Web Animations
|
|
mockAnimationsApi()
|
|
|
|
// Prevent retries on mocked error responses — replication queries override the
|
|
// QueryClient default with checkReplicationFeatureFlagRetry, which retries up to
|
|
// 3 times. Without this mock error tests would time-out.
|
|
vi.mock('@/data/replication/utils', () => ({
|
|
checkReplicationFeatureFlagRetry: () => false,
|
|
}))
|
|
|
|
// DestinationRow requires a PipelineRequestStatusContext provider.
|
|
// Mock the module so tests don't need to wrap with the provider.
|
|
vi.mock('@/state/replication-pipeline-request-status', () => ({
|
|
PipelineStatusRequestStatus: {
|
|
None: 'None',
|
|
StartRequested: 'StartRequested',
|
|
StopRequested: 'StopRequested',
|
|
RestartRequested: 'RestartRequested',
|
|
},
|
|
usePipelineRequestStatus: () => ({
|
|
getRequestStatus: () => 'None',
|
|
updatePipelineStatus: () => {},
|
|
}),
|
|
}))
|
|
|
|
const DESTINATION_ID = 1
|
|
const PIPELINE_ID = 42
|
|
|
|
const addSourcesMock = () =>
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/replication/:ref/sources',
|
|
response: () =>
|
|
HttpResponse.json<ReplicationSourcesResponse>({
|
|
sources: [
|
|
{
|
|
tenant_id: 't',
|
|
id: 1,
|
|
name: 'default',
|
|
config: { host: 'db.internal', port: 5432, name: 'main-db', username: 'etl_user' },
|
|
},
|
|
],
|
|
}),
|
|
})
|
|
|
|
const addDestinationMock = () =>
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/replication/:ref/destinations/:destination_id',
|
|
response: () =>
|
|
HttpResponse.json<ReplicationDestinationResponse>({
|
|
tenant_id: 't',
|
|
id: DESTINATION_ID,
|
|
name: 'My BigQuery Destination',
|
|
config: {
|
|
big_query: {
|
|
project_id: 'gcp-proj',
|
|
dataset_id: 'analytics',
|
|
connection_pool_size: 5,
|
|
},
|
|
},
|
|
}),
|
|
})
|
|
|
|
const addPipelinesMock = () =>
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/replication/:ref/pipelines',
|
|
response: () =>
|
|
HttpResponse.json<ReplicationPipelinesResponse>({
|
|
pipelines: [
|
|
{
|
|
id: PIPELINE_ID,
|
|
tenant_id: 't',
|
|
source_id: 1,
|
|
source_name: 'main-db',
|
|
destination_id: DESTINATION_ID,
|
|
destination_name: 'My BigQuery Destination',
|
|
replicator_id: 9001,
|
|
config: {
|
|
publication_name: 'supabase_realtime',
|
|
table_sync_copy: { type: 'include_all_tables' },
|
|
},
|
|
},
|
|
],
|
|
}),
|
|
})
|
|
|
|
const addPipelineStatusMock = (statusName: ReplicationPipelineStatusResponse['status']['name']) =>
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/replication/:ref/pipelines/:pipeline_id/status',
|
|
response: () =>
|
|
HttpResponse.json<ReplicationPipelineStatusResponse>({
|
|
pipeline_id: PIPELINE_ID,
|
|
status: { name: statusName },
|
|
}),
|
|
})
|
|
|
|
const addReplicationStatusMock = (
|
|
confirmedFlushLsnBytes: number,
|
|
tableStatuses: ReplicationPipelineReplicationStatusResponse['table_statuses'] = []
|
|
) =>
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/replication/:ref/pipelines/:pipeline_id/replication-status',
|
|
response: () =>
|
|
HttpResponse.json<ReplicationPipelineReplicationStatusResponse>({
|
|
pipeline_id: PIPELINE_ID,
|
|
apply_lag: {
|
|
active: true,
|
|
wal_status: 'reserved',
|
|
restart_lsn_bytes: 0,
|
|
confirmed_flush_lsn_bytes: confirmedFlushLsnBytes,
|
|
safe_wal_size_bytes: null,
|
|
},
|
|
table_statuses: tableStatuses,
|
|
}),
|
|
})
|
|
|
|
const addVersionMock = () =>
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/replication/:ref/pipelines/:pipeline_id/version',
|
|
response: () =>
|
|
HttpResponse.json<ReplicationPipelineVersionResponse>({
|
|
pipeline_id: PIPELINE_ID,
|
|
version: { id: 1, name: 'v0.3.0' },
|
|
}),
|
|
})
|
|
|
|
describe('DestinationRow', () => {
|
|
test('shows "Caught up" when confirmed_flush_lsn_bytes is 0', async () => {
|
|
addSourcesMock()
|
|
addDestinationMock()
|
|
addPipelinesMock()
|
|
addPipelineStatusMock('started')
|
|
addReplicationStatusMock(0)
|
|
addVersionMock()
|
|
|
|
customRender(<DestinationRow destinationId={DESTINATION_ID} />)
|
|
|
|
expect(await screen.findByText('Caught up')).toBeInTheDocument()
|
|
})
|
|
|
|
test('shows formatted lag value when confirmed_flush_lsn_bytes is non-zero', async () => {
|
|
addSourcesMock()
|
|
addDestinationMock()
|
|
addPipelinesMock()
|
|
addPipelineStatusMock('started')
|
|
addReplicationStatusMock(2048)
|
|
addVersionMock()
|
|
|
|
customRender(<DestinationRow destinationId={DESTINATION_ID} />)
|
|
|
|
expect(await screen.findByText('2 KB')).toBeInTheDocument()
|
|
})
|
|
|
|
test('shows publication name from pipeline config', async () => {
|
|
addSourcesMock()
|
|
addDestinationMock()
|
|
addPipelinesMock()
|
|
addPipelineStatusMock('started')
|
|
addReplicationStatusMock(0)
|
|
addVersionMock()
|
|
|
|
customRender(<DestinationRow destinationId={DESTINATION_ID} />)
|
|
|
|
expect(await screen.findByText('supabase_realtime')).toBeInTheDocument()
|
|
})
|
|
|
|
test('shows Running badge when pipeline is started', async () => {
|
|
addSourcesMock()
|
|
addDestinationMock()
|
|
addPipelinesMock()
|
|
addPipelineStatusMock('started')
|
|
addReplicationStatusMock(0)
|
|
addVersionMock()
|
|
|
|
customRender(<DestinationRow destinationId={DESTINATION_ID} />)
|
|
|
|
expect(await screen.findByText('Running')).toBeInTheDocument()
|
|
})
|
|
|
|
test('shows Failed badge when pipeline has failed', async () => {
|
|
addSourcesMock()
|
|
addDestinationMock()
|
|
addPipelinesMock()
|
|
addPipelineStatusMock('failed')
|
|
addReplicationStatusMock(0)
|
|
addVersionMock()
|
|
|
|
customRender(<DestinationRow destinationId={DESTINATION_ID} />)
|
|
|
|
expect(await screen.findByText('Failed')).toBeInTheDocument()
|
|
})
|
|
|
|
test('shows Stopped badge when pipeline is stopped', async () => {
|
|
addSourcesMock()
|
|
addDestinationMock()
|
|
addPipelinesMock()
|
|
addPipelineStatusMock('stopped')
|
|
addReplicationStatusMock(0)
|
|
addVersionMock()
|
|
|
|
customRender(<DestinationRow destinationId={DESTINATION_ID} />)
|
|
|
|
expect(await screen.findByText('Stopped')).toBeInTheDocument()
|
|
})
|
|
|
|
test('shows warning icon when tables have replication errors', async () => {
|
|
addSourcesMock()
|
|
addDestinationMock()
|
|
addPipelinesMock()
|
|
addPipelineStatusMock('started')
|
|
addReplicationStatusMock(0, [
|
|
{
|
|
id: 1,
|
|
schema: 'public',
|
|
name: 'orders',
|
|
table_id: 1,
|
|
table_name: 'public.orders',
|
|
state: { name: 'error', reason: 'table not found', retry_policy: { policy: 'no_retry' } },
|
|
},
|
|
])
|
|
addVersionMock()
|
|
|
|
const { container } = customRender(<DestinationRow destinationId={DESTINATION_ID} />)
|
|
|
|
await screen.findByText('Caught up')
|
|
|
|
// WarningIcon renders with bg-warning-600 (from packages/ui/src/components/StatusIcon.tsx)
|
|
expect(container.querySelector('.bg-warning-600')).toBeInTheDocument()
|
|
})
|
|
|
|
test('suppresses warning icon when pipeline is stopped even with table errors', async () => {
|
|
addSourcesMock()
|
|
addDestinationMock()
|
|
addPipelinesMock()
|
|
addPipelineStatusMock('stopped')
|
|
addReplicationStatusMock(0, [
|
|
{
|
|
id: 1,
|
|
schema: 'public',
|
|
name: 'orders',
|
|
table_id: 1,
|
|
table_name: 'public.orders',
|
|
state: { name: 'error', reason: 'table not found', retry_policy: { policy: 'no_retry' } },
|
|
},
|
|
])
|
|
addVersionMock()
|
|
|
|
const { container } = customRender(<DestinationRow destinationId={DESTINATION_ID} />)
|
|
|
|
await screen.findByText('Stopped')
|
|
|
|
expect(container.querySelector('.bg-warning-600')).not.toBeInTheDocument()
|
|
})
|
|
|
|
test('shows error when the pipelines API fails', async () => {
|
|
addSourcesMock()
|
|
addDestinationMock()
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/replication/:ref/pipelines',
|
|
response: () =>
|
|
HttpResponse.json<APIErrorBody>({ message: 'Internal server error' }, { status: 500 }),
|
|
})
|
|
|
|
customRender(<DestinationRow destinationId={DESTINATION_ID} />)
|
|
|
|
expect(await screen.findByText('Failed to retrieve pipeline information')).toBeInTheDocument()
|
|
})
|
|
})
|