mirror of
https://github.com/supabase/supabase.git
synced 2026-10-11 12:25:05 +03:00
Moves studio specific SQL queries out of pg-meta into studio itself
This commit is contained in:
1 parent
6437bd2a38
commit
28ecc8b4db
15 files changed
+587
-35
No files matched your search
@@ -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;
|
||||
`
|
||||
}
|
||||
Reference in new issue
Block a user