Moves studio specific SQL queries out of pg-meta into studio itself

This commit is contained in:
Joshen Lim committed 2026-03-05 18:05:43 +08:00
1 parent 6437bd2a38
commit 28ecc8b4db
15 files changed
+587 -35

No files matched your search

+21
View File
@@ -18,3 +18,24 @@ export const getLiveTupleEstimateKey = (
table: string,
schema = 'public'
) => sqlKeys.query(projectRef, ['live-tuple-estimate', schema, table])
export const getCheckPrimaryKeysExistsSQL = (tables: { name: string; schema: string }[]) => {
const formattedTables = tables.map((table) => `'${table.schema}.${table.name}'`).join(',')
return /* SQL */ `
WITH targets(rel) AS (
SELECT unnest(ARRAY[${formattedTables}]::regclass[])
)
SELECT
c.oid AS id,
n.nspname AS schema,
c.relname AS name,
(con.conrelid IS NOT NULL) AS has_primary_key
FROM targets t
JOIN pg_class c ON c.oid = t.rel
JOIN pg_namespace n ON n.oid = c.relnamespace
LEFT JOIN pg_constraint con
ON con.conrelid = c.oid AND con.contype = 'p'
ORDER BY n.nspname, c.relname;
`
}