mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## I have read the [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) file. YES ## What kind of change does this PR introduce? Cleanup: remove a fully rolled-out Studio feature flag. Resolves CLI-2759. Supersedes #50260 and #47931 (rebuilt on current master). ## What is the new behavior? Scoped introspection is the only path. - Studio: delete `data/scoped-introspection.ts` and `PG_META_SCOPED_INTROSPECTION_FLAG`; stop threading `scoped` through table editor, rows/counts, privileges, enumerated types, table definition, retrieve, prefetcher, `EntityListItem`, `SidePanelEditor`, `EditHookPanel`, `DefaultLayout`. - pg-meta: drop `scoped?: boolean` from public builders and delete the frozen unscoped SQL. `tables.list` keeps its full-catalog `TABLES_SQL` (never flag-gated). ## Test plan - [x] pg-meta + Studio typecheck - [x] pg-meta suite against Docker DB (521/521) - [x] Studio vitest for touched areas - [x] Open Table Editor, row counts, privileges, and enumerated types on a project (dogfooded on the preview deploy) - [ ] After merge, retire `pgMetaScopedIntrospection` in the flag dashboard 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
127 lines
3.6 KiB
TypeScript
127 lines
3.6 KiB
TypeScript
import { afterAll, expect, test } from 'vitest'
|
|
|
|
import { getTableEditorSql } from '../../../src'
|
|
import { cleanupRoot, createTestDatabase } from '../../db/utils'
|
|
|
|
afterAll(async () => {
|
|
await cleanupRoot()
|
|
})
|
|
|
|
type Entity = {
|
|
entity_type: string
|
|
id: number
|
|
schema: string
|
|
name: string
|
|
primary_keys: Array<{ table_id: number; schema: string; table_name: string; name: string }>
|
|
unique_indexes: Array<{ table_id: number; schema: string; table_name: string; columns: string[] }>
|
|
relationships: Array<{
|
|
id: number
|
|
constraint_name: string
|
|
source_schema: string
|
|
source_table_name: string
|
|
source_column_name: string
|
|
target_table_schema: string
|
|
target_table_name: string
|
|
target_column_name: string
|
|
}>
|
|
columns: Array<{
|
|
name: string
|
|
is_unique: boolean
|
|
check: string | null
|
|
comment: string | null
|
|
}>
|
|
}
|
|
|
|
const withTestDatabase = (
|
|
name: string,
|
|
fn: (db: Awaited<ReturnType<typeof createTestDatabase>>) => Promise<void>
|
|
) => {
|
|
test(name, async () => {
|
|
const db = await createTestDatabase()
|
|
try {
|
|
await fn(db)
|
|
} finally {
|
|
await db.cleanup()
|
|
}
|
|
})
|
|
}
|
|
|
|
withTestDatabase(
|
|
'scopes primary keys, unique indexes, relationships and columns to the target table',
|
|
async ({ executeQuery }) => {
|
|
await executeQuery(`
|
|
create schema if not exists editor_scope;
|
|
|
|
create table editor_scope.authors (
|
|
id serial primary key
|
|
);
|
|
|
|
create table editor_scope.books (
|
|
id serial primary key,
|
|
isbn text not null unique,
|
|
price numeric not null check (price > 0),
|
|
author_id int not null references editor_scope.authors (id)
|
|
);
|
|
comment on column editor_scope.books.isbn is 'International Standard Book Number';
|
|
|
|
create table editor_scope.reviews (
|
|
id serial primary key,
|
|
book_id int not null references editor_scope.books (id)
|
|
);
|
|
`)
|
|
|
|
const [{ id: booksId }] = await executeQuery<{ id: number }[]>(
|
|
`select 'editor_scope.books'::regclass::oid::int8 as id;`
|
|
)
|
|
|
|
const sql = getTableEditorSql({ id: booksId })
|
|
const [{ entity }] = await executeQuery<{ entity: Entity }[]>(sql)
|
|
|
|
// Basic identity.
|
|
expect(entity.id).toBe(booksId)
|
|
expect(entity.schema).toBe('editor_scope')
|
|
expect(entity.name).toBe('books')
|
|
|
|
// Primary key scoped to `books`.
|
|
expect(entity.primary_keys).toEqual([
|
|
{ schema: 'editor_scope', table_name: 'books', table_id: booksId, name: 'id' },
|
|
])
|
|
|
|
// Unique index scoped to `books`.
|
|
expect(entity.unique_indexes).toHaveLength(1)
|
|
expect(entity.unique_indexes[0]).toMatchObject({
|
|
schema: 'editor_scope',
|
|
table_name: 'books',
|
|
table_id: booksId,
|
|
columns: ['isbn'],
|
|
})
|
|
|
|
// Relationships include both the outgoing FK (books -> authors) and the
|
|
// incoming FK (reviews -> books).
|
|
expect(entity.relationships).toContainEqual(
|
|
expect.objectContaining({
|
|
source_table_name: 'books',
|
|
source_column_name: 'author_id',
|
|
target_table_name: 'authors',
|
|
target_column_name: 'id',
|
|
})
|
|
)
|
|
expect(entity.relationships).toContainEqual(
|
|
expect.objectContaining({
|
|
source_table_name: 'reviews',
|
|
source_column_name: 'book_id',
|
|
target_table_name: 'books',
|
|
target_column_name: 'id',
|
|
})
|
|
)
|
|
|
|
// Columns: unique flag, check constraint definition, and comment.
|
|
const isbnCol = entity.columns.find((c) => c.name === 'isbn')!
|
|
expect(isbnCol.is_unique).toBe(true)
|
|
expect(isbnCol.comment).toBe('International Standard Book Number')
|
|
|
|
const priceCol = entity.columns.find((c) => c.name === 'price')!
|
|
expect(priceCol.check).toContain('price > 0')
|
|
}
|
|
)
|