Files
supabase/e2e/studio/features/table-editor-partitions.spec.ts
Joshen Lim 4ed3627d72 Joshenlim/fe 3891 improve handling of partition tables in (#53268)
## Context

The Table Editor doesn't really handle partitioned tables well given the
following issues:
- Partitioned tables are rendered as a flat list in the Table Editor
side menu, so the menu could get very long and noisy - this was the
primary motivation for this PR
- Child partitioned tables are not indicated with a proper icon, they're
treated as regular tables in the Table Editor which is incorrect

## Changes involved
- Table Editor side menu now only lists parent partitioned tables, omits
all child partitioned tables
- Child partitioned tables can be viewed by clicking on the button
tooltip here or drilling down via "View partitions"
<img width="300" alt="image"
src="https://github.com/user-attachments/assets/e3cfbe4b-21ff-47df-8fcd-81d0c9f68d94"
/><br />
<img width="400" alt="image"
src="https://github.com/user-attachments/assets/5d0747cb-fb52-4301-ad9e-c7be504f43c9"
/>

  - Selecting that will then render a nested nav as such
<img width="291" height="323" alt="image"
src="https://github.com/user-attachments/assets/bff0a42b-4265-4317-8299-537d82544388"
/>

- Sub partitioned tables can be drilled into the same way, and the back
CTA steps up one level
<img width="485" height="306" alt="image"
src="https://github.com/user-attachments/assets/66f6f6cb-8b7d-46c5-8ea3-4ee4fd57aa84"
/>

- Parent partition tables have the following actions (Previously was
only copy name and schema)
<img width="465" height="257" alt="image"
src="https://github.com/user-attachments/assets/2aa90995-7c30-4bcf-a446-d01ab52c1ede"
/>

- Deleting a parent partition table will also delete the child partition
table, and that's highlighted in the confirmation modal
<img width="418" height="316" alt="image"
src="https://github.com/user-attachments/assets/0d61984b-f85e-4c93-84d0-549d300838c9"
/>

- Child partition tables have the following actions (Edit + duplicate
removed since they aren't supported via the UI)
<img width="482" height="229" alt="image"
src="https://github.com/user-attachments/assets/e028b13d-2e92-4491-b05c-7a6cb0a129d6"
/>


## To test
In general, just verify the viewing UX of partitioned tables to see if
it all feels alright, can use the following SQL to quickly set up
partitioned tables
```sql
   create schema if not exists tint;
   create table public.nest_demo (id int, hue int not null, primary key (id, hue))
     partition by range (hue);
   create table public.nest_demo_blue partition of public.nest_demo
     for values from (200) to (300) partition by range (hue);
   create table public.nest_demo_blue_light partition of public.nest_demo_blue
     for values from (200) to (250);
   create table tint.nest_demo_blue_deep partition of public.nest_demo_blue
     for values from (250) to (300);
   create table public.nest_demo_other partition of public.nest_demo
     for values from (0) to (200);
   ```
2026-11-16 17:23:59 +07:00

154 lines
5.3 KiB
TypeScript

import crypto from 'node:crypto'
import { expect, Page } from '@playwright/test'
import { query } from '../utils/db/index.js'
import { dropTable } from '../utils/db/queries.js'
import { test } from '../utils/test.js'
import { toUrl } from '../utils/to-url.js'
import { createApiResponseWaiter } from '../utils/wait-for-response.js'
const uniqueSuffix = () => crypto.randomBytes(4).toString('hex')
/**
* Parent partitioned table (RLS off) with two flat partitions.
*/
const setupFlatFixture = async () => {
const suffix = uniqueSuffix()
const parent = `pw_part_flat_${suffix}`
const childA = `${parent}_a`
const childB = `${parent}_b`
await query(`create table public.${parent} (id int not null, note text) partition by range (id)`)
await query(
`create table public.${childA} partition of public.${parent} for values from (0) to (100)`
)
await query(
`create table public.${childB} partition of public.${parent} for values from (100) to (200)`
)
return {
parent,
childA,
childB,
async [Symbol.asyncDispose]() {
await dropTable(`public.${parent}`)
},
}
}
/**
* Parent -> child (itself partitioned) -> grandchild, plus a sibling leaf.
*/
const setupNestedFixture = async () => {
const suffix = uniqueSuffix()
const parent = `pw_part_nested_${suffix}`
const child = `${parent}_mid`
const grandchild = `${parent}_leaf`
const sibling = `${parent}_sibling`
await query(`create table public.${parent} (id int not null, note text) partition by range (id)`)
await query(
`create table public.${child} partition of public.${parent} for values from (0) to (100) partition by range (id)`
)
await query(
`create table public.${grandchild} partition of public.${child} for values from (0) to (50)`
)
await query(
`create table public.${sibling} partition of public.${parent} for values from (100) to (200)`
)
return {
parent,
child,
grandchild,
sibling,
async [Symbol.asyncDispose]() {
await dropTable(`public.${parent}`)
},
}
}
const goToTableEditor = async (page: Page, ref: string) => {
const tableLoadWait = createApiResponseWaiter(
page,
'pg-meta',
ref,
'query?key=entity-types-public-'
)
await page.goto(toUrl(`/project/${ref}/editor?schema=public`))
await tableLoadWait
}
const entityRow = (page: Page, name: string) =>
page.getByRole('button', { name: `View ${name}`, exact: true })
test.describe('table editor partitions', () => {
test('only the parent is listed, and its partitions open in a second-level list', async ({
page,
ref,
}) => {
await using fixture = await setupFlatFixture()
await goToTableEditor(page, ref)
await expect(
entityRow(page, fixture.parent),
'Parent partitioned table should be listed'
).toBeVisible({ timeout: 30000 })
await expect(
entityRow(page, fixture.childA),
'Child partitions should not be listed alongside regular tables'
).toHaveCount(0)
// Parent has RLS disabled, so it should be flagged as unrestricted
await expect(
entityRow(page, fixture.parent).getByText('Unrestricted'),
'Parent without RLS should show the Unrestricted badge'
).toBeVisible()
await entityRow(page, fixture.parent).getByRole('button', { name: 'View 2 partitions' }).click()
await expect(
page.getByTestId('partitions-list'),
'Partitions list should open after clicking the partition count'
).toBeVisible({ timeout: 30000 })
await expect(entityRow(page, fixture.childA)).toBeVisible()
await expect(entityRow(page, fixture.childB)).toBeVisible()
// Search narrows the partitions
await page.getByPlaceholder('Search partitions...').fill(fixture.childB)
await expect(entityRow(page, fixture.childB)).toBeVisible()
await expect(entityRow(page, fixture.childA)).toHaveCount(0)
// Back returns to the full table list
await page.getByRole('button', { name: 'Back to all tables' }).click()
await expect(entityRow(page, fixture.parent)).toBeVisible()
await expect(entityRow(page, fixture.childA)).toHaveCount(0)
})
test('nested partitions navigate down and back up one level at a time', async ({ page, ref }) => {
await using fixture = await setupNestedFixture()
await goToTableEditor(page, ref)
await entityRow(page, fixture.parent)
.getByRole('button', { name: /View \d+ partitions?/ })
.click()
await expect(entityRow(page, fixture.child)).toBeVisible({ timeout: 30000 })
await expect(entityRow(page, fixture.sibling)).toBeVisible()
await expect(
entityRow(page, fixture.grandchild),
'Only direct children should be listed at the first level'
).toHaveCount(0)
// Drill into the sub-partitioned child
await entityRow(page, fixture.child)
.getByRole('button', { name: /View \d+ partitions?/ })
.click()
await expect(entityRow(page, fixture.grandchild)).toBeVisible({ timeout: 30000 })
await expect(entityRow(page, fixture.sibling)).toHaveCount(0)
// Back goes to the parent's partitions, not all the way out
await page.getByRole('button', { name: 'Back to parent partitions' }).click()
await expect(entityRow(page, fixture.child)).toBeVisible()
await expect(entityRow(page, fixture.sibling)).toBeVisible()
await page.getByRole('button', { name: 'Back to all tables' }).click()
await expect(entityRow(page, fixture.parent)).toBeVisible()
})
})