Files
supabase/apps/studio/data/database-indexes/database-indexes.sql.ts
T
Joshen LimandAli Waseem b94538268b Joshen/fe 2558 shift sql queries to contextual folders update codeowners (#42770)
## Context

Related to Dashboard Scalability, specifically having Postgres team as
CODEOWNERS for dashboard queries

This is just a clean up as we're currently piling manual queries into
one folder under `data/sql/queries`, whereas I reckon it'll be better
for each query to sit within their RQ folder for better context.

Am opting the naming format for files housing queries to be `*.sql.ts`,
and also updating CODEOWNERS to reflect as such

Next step will also be to shift all the dashboard queries within pg-meta
into studio itself as requested by the pg-meta team

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Refactor**
* Consolidated and reorganized internal module structure for the data
layer to improve maintainability and reduce redundancy.
* Streamlined import paths across components to align with new
consolidated module organization.

* **Chores**
* Updated code ownership patterns to reflect reorganized file structure.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Ali Waseem <waseema393@gmail.com>
2026-02-16 18:34:08 +00:00

32 lines
793 B
TypeScript

export const getIndexesSQL = ({ schema }: { schema: string }) => {
const sql = /* SQL */ `
SELECT
n.nspname AS schema,
t.relname AS "table",
i.relname AS name,
pg_get_indexdef(idx.indexrelid) AS definition,
STRING_AGG(
COALESCE(a.attname, '(expression)'),
', ' ORDER BY k.ord
) AS columns
FROM pg_index idx
JOIN pg_class t ON t.oid = idx.indrelid
JOIN pg_class i ON i.oid = idx.indexrelid
JOIN pg_namespace n ON n.oid = t.relnamespace
JOIN LATERAL unnest(idx.indkey) WITH ORDINALITY AS k(attnum, ord) ON TRUE
LEFT JOIN pg_attribute a
ON a.attrelid = t.oid
AND a.attnum = k.attnum
WHERE n.nspname = '${schema}'
GROUP BY
n.nspname,
t.relname,
i.relname,
idx.indexrelid
ORDER BY
schema, "table", name;
`.trim()
return sql
}