Files
supabase/apps/studio/data/database/table-definition-query.ts
Andrew ValleteauandClaude Opus 5.5 e42f4ec612 chore: remove pgMetaScopedIntrospection feature flag (#52019)
## 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>
2026-10-20 17:40:13 +02:00

55 lines
1.6 KiB
TypeScript

import { getTableDefinitionSql } from '@supabase/pg-meta'
import { useQuery } from '@tanstack/react-query'
import { databaseKeys } from './keys'
import { executeSql } from '@/data/sql/execute-sql-mutation'
import { ResponseError, UseCustomQueryOptions } from '@/types'
type GetTableDefinitionArgs = {
id?: number
}
export type TableDefinitionVariables = GetTableDefinitionArgs & {
projectRef?: string
connectionString?: string | null
}
export async function getTableDefinition(
{ projectRef, connectionString, id }: TableDefinitionVariables,
signal?: AbortSignal
) {
if (!id) throw new Error('id is required')
const sql = getTableDefinitionSql({ id })
const { result } = await executeSql(
{
projectRef,
connectionString,
sql,
queryKey: ['table-definition', id],
},
signal
)
return result[0].definition.trim() as string
}
export type TableDefinitionData = string
export type TableDefinitionError = ResponseError
export const useTableDefinitionQuery = <TData = TableDefinitionData>(
{ projectRef, connectionString, id }: TableDefinitionVariables,
{
enabled = true,
...options
}: UseCustomQueryOptions<TableDefinitionData, TableDefinitionError, TData> = {}
) => {
return useQuery<TableDefinitionData, TableDefinitionError, TData>({
queryKey: databaseKeys.tableDefinition(projectRef, id),
queryFn: ({ signal }) => getTableDefinition({ projectRef, connectionString, id }, signal),
enabled:
enabled && typeof projectRef !== 'undefined' && typeof id !== 'undefined' && !isNaN(id),
...options,
})
}