Files
supabase/apps/studio/components/interfaces/Database/Tables/ColumnList.utils.test.ts
Danny White 3980bb162d feat(studio): improve database column list scanning (#44208)
## What kind of change does this PR introduce?

UI improvements. Resolves DEPR-419.

## What is the current behavior?

- `ColumnList` splits type information across separate `Data Type` and
`Format` columns, which makes scanning less efficient
- The list only surfaces a limited subset of column metadata up front,
so key structural information like primary keys, foreign keys,
uniqueness, and identity is not easy to scan
- Constraint and nullability affordances are not aligned with the visual
language already used in the Table Editor and Schema Visualiser

## What is the new behavior?

- `ColumnList` now shows a leading type affordance icon, while keeping
the exact Postgres type visible in the `Type` column
- The standalone `Data Type` column is removed, and `format` is now the
primary textual type shown in the table
- The `Constraints` column now surfaces explicit icon-plus-label tokens
for:
  - `Primary`
  - `Foreign key`
  - `Unique`
  - `Identity`
  - `Nullable` / `Non-nullable`
- Constraint tokens use a purpose-built segmented style based on
`ComputeBadge`, including a green primary variant for primary keys
- Nullability now matches Schema Visualiser semantics exactly: outlined
diamond for nullable, filled diamond for non-nullable
- Existing search, descriptions, row actions, and permission gating are
preserved

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2026-03-26 15:55:32 +08:00

67 lines
1.9 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import {
getColumnTypeAffordance,
getForeignKeyColumnNames,
getPrimaryKeyColumnNames,
getUniqueIndexColumnNames,
} from './ColumnList.utils'
describe('ColumnList.utils', () => {
it('normalises quoted array formats before resolving the affordance kind', () => {
expect(getColumnTypeAffordance('"uuid"[]')).toEqual({
kind: 'text',
label: 'Text',
})
})
it('maps recognised Postgres formats to their affordance labels', () => {
expect(getColumnTypeAffordance('timestamptz')).toEqual({
kind: 'time',
label: 'Date / time',
})
expect(getColumnTypeAffordance('jsonb')).toEqual({
kind: 'json',
label: 'JSON',
})
})
it('falls back to the other affordance for unrecognised formats', () => {
expect(getColumnTypeAffordance('citext')).toEqual({
kind: 'other',
label: 'Other',
})
})
it('derives only source-table foreign key column names', () => {
const table = {
schema: 'public',
name: 'orders',
primary_keys: [{ name: 'id' }],
relationships: [
{
source_schema: 'public',
source_table_name: 'orders',
source_column_name: 'customer_id',
target_table_schema: 'public',
target_table_name: 'customers',
target_column_name: 'id',
},
{
source_schema: 'public',
source_table_name: 'customers',
source_column_name: 'account_id',
target_table_schema: 'public',
target_table_name: 'accounts',
target_column_name: 'id',
},
],
unique_indexes: [{ columns: ['reference'] }, { columns: ['customer_id', 'reference'] }],
} as const
expect([...getPrimaryKeyColumnNames(table)]).toEqual(['id'])
expect([...getForeignKeyColumnNames(table)]).toEqual(['customer_id'])
expect([...getUniqueIndexColumnNames(table)]).toEqual(['reference'])
})
})