Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat(studio): configure publication partition handling (#49845)

Danny White3418975b701a
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/NewPublicationPanel.test.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/NewPublicationPanel.test.tsx
index 0268d7180cb..239d87c29a7 100644
--- a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/NewPublicationPanel.test.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/NewPublicationPanel.test.tsx
@@ -115,4 +115,37 @@ describe('NewPublicationPanel', () => {
})
)
})
+
+ it('sends publish_via_partition_root as false when the option is turned off', async () => {
+ mockQueries()
+ let requestBody: unknown
+ addAPIMock({
+ method: 'put',
+ path: '/platform/replication/v2/:ref/sources/:source_id/publications/:publication_name',
+ response: async ({ request }) => {
+ requestBody = await request.json()
+ return HttpResponse.json<PublicationDetailsResponse>(mockPublication)
+ },
+ })
+
+ customRender(<NewPublicationPanel visible onClose={vi.fn()} />)
+
+ const trigger = screen.getAllByRole('combobox').find((element) => element.tagName === 'BUTTON')!
+ fireEvent.click(trigger)
+ fireEvent.click(await screen.findByText('CamelSchema.MixedCaseTable'))
+ fireEvent.change(screen.getByPlaceholderText('Name'), {
+ target: { value: 'MixedCasePublication' },
+ })
+ fireEvent.click(
+ screen.getByRole('checkbox', { name: 'Publish partitions as the parent table' })
+ )
+ fireEvent.click(screen.getByRole('button', { name: 'Create publication' }))
+
+ await waitFor(() =>
+ expect(requestBody).toMatchObject({
+ tables: [{ id: 17487 }],
+ publish_via_partition_root: false,
+ })
+ )
+ })
})
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/NewPublicationPanel.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/NewPublicationPanel.tsx
index 5d2335cbe2f..93467642768 100644
--- a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/NewPublicationPanel.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/NewPublicationPanel.tsx
@@ -5,6 +5,7 @@ import { useForm } from 'react-hook-form'
import { toast } from 'sonner'
import {
Button,
+ Checkbox,
Form,
FormControl,
FormField,
@@ -42,12 +43,14 @@ const FORM_ID = 'publication-editor'
const FormSchema = z.object({
name: z.string().min(1, 'Name is required'),
tableIds: z.array(z.string()).min(1, 'At least one table is required'),
+ publishViaPartitionRoot: z.boolean(),
})
type FormValues = z.infer<typeof FormSchema>
const defaultValues: FormValues = {
name: '',
tableIds: [],
+ publishViaPartitionRoot: true,
}
export const NewPublicationPanel = ({ visible, onClose }: NewPublicationPanelProps) => {
@@ -110,6 +113,7 @@ export const NewPublicationPanel = ({ visible, onClose }: NewPublicationPanelPro
sourceId,
name: data.name,
tableIds: data.tableIds.map(Number),
+ publishViaPartitionRoot: data.publishViaPartitionRoot,
})
}
@@ -192,6 +196,26 @@ export const NewPublicationPanel = ({ visible, onClose }: NewPublicationPanelPro
</FormItemLayout>
)}
/>
+ <FormField
+ control={form.control}
+ name="publishViaPartitionRoot"
+ render={({ field }) => (
+ <FormItemLayout
+ hideMessage
+ label="Publish partitions as the parent table"
+ description="Changes from partitioned tables appear in one destination table. Turn off to create a table for each partition."
+ layout="flex"
+ >
+ <FormControl>
+ <Checkbox
+ checked={field.value}
+ aria-label="Publish partitions as the parent table"
+ onCheckedChange={(checked) => field.onChange(checked === true)}
+ />
+ </FormControl>
+ </FormItemLayout>
+ )}
+ />
</form>
</Form>
</SheetSection>
diff --git a/apps/studio/data/replication/publication-create-mutation.ts b/apps/studio/data/replication/publication-create-mutation.ts
index 8095d2382c8..bba8eab6d24 100644
--- a/apps/studio/data/replication/publication-create-mutation.ts
+++ b/apps/studio/data/replication/publication-create-mutation.ts
@@ -10,10 +10,11 @@ export type CreatePublicationParams = {
sourceId: number
name: string
tableIds: number[]
+ publishViaPartitionRoot?: boolean
}
async function createPublication(
- { projectRef, sourceId, name, tableIds }: CreatePublicationParams,
+ { projectRef, sourceId, name, tableIds, publishViaPartitionRoot = true }: CreatePublicationParams,
signal?: AbortSignal
) {
if (!projectRef) throw new Error('projectRef is required')
@@ -26,7 +27,7 @@ async function createPublication(
type: 'tables',
tables: tableIds.map((id) => ({ id })),
operations: ['insert', 'update', 'delete', 'truncate'],
- publish_via_partition_root: true,
+ publish_via_partition_root: publishViaPartitionRoot,
},
signal,
}