supabase/supabase
Database management
The set of Studio surfaces that manipulate Postgres directly: tables, columns, rows, indexes, functions, triggers, policies, publications, replication, roles, extensions, cron, queues, vault, and the SQL editor. This is the core of Studio.
Studio surfaces involved
| Folder | Purpose |
|---|---|
apps/studio/components/interfaces/Database/ |
Top-level database settings: roles, extensions, replication, indexes, cron, queues, vault, publications, triggers, functions, types, policies. |
apps/studio/components/interfaces/TableGridEditor/ |
Table editor — the spreadsheet-like grid built on a patched react-data-grid. |
apps/studio/components/grid/ |
Data grid primitives shared by TableGridEditor and the SQL editor results panel. |
apps/studio/components/interfaces/SQLEditor/ |
Full SQL editor — Monaco, tabs, snippets, formatter, AI completions, explain. |
apps/studio/components/interfaces/QueryInsights/ and QueryPerformance/ |
Read-only views over Postgres stats and Logflare metrics. |
apps/studio/components/interfaces/ExplainVisualizer/ |
Visualizes EXPLAIN output. |
apps/studio/components/interfaces/Linter/, Advisors/ |
Schema and security advisors that surface lint findings. |
Data layer
Each domain has its own folder under apps/studio/data/:
| Folder | What it owns |
|---|---|
database/ |
Generic database queries (settings, status). |
database-columns/ |
Columns CRUD via pg-meta-columns. |
database-cron-jobs/ |
Cron jobs. |
database-event-triggers/ |
Event triggers. |
database-extensions/ |
Extension install / enable. |
database-functions/ |
DB functions CRUD. |
database-indexes/ |
Indexes. |
database-integrations/ |
Integrations metadata. |
database-policies/ |
RLS policies. |
database-publications/ |
Logical replication. |
database-queues/ |
Postgres-backed queues. |
database-roles/ |
DB roles + grants. |
database-triggers/ |
Triggers. |
tables/, table-rows/, table-editor/, entity-types/ |
Tables / rows / editor state. |
materialized-views/, views/, foreign-tables/ |
Other relations. |
enumerated-types/, privileges/, replication/, read-replicas/ |
Auxiliary metadata. |
sql/ |
Generic SQL execution: execute-sql-query.ts, execute-sql-mutation.ts, abort-query-mutation.ts, ongoing-queries-query.ts. |
How a schema change flows
sequenceDiagram
participant UI as Studio UI
participant Hook as data/<domain>/use*Mutation
participant PgMeta as packages/pg-meta
participant Exec as data/sql/execute-sql-mutation
participant API as Mgmt API "execute SQL"
participant PG as Postgres
UI->>Hook: user submits change
Hook->>PgMeta: build { sql, zod }
Hook->>Exec: send sql via execute-sql-mutation
Exec->>API: POST /v1/projects/{ref}/database/query
API->>PG: run SQL
PG-->>API: rows / error
API-->>Exec: response
Exec-->>Hook: rows
Hook-->>UI: validated via zodSelf-host installs short-circuit the management API and call postgres-meta directly via Kong.
SQL Editor specifics
The SQL editor combines:
- Monaco (
@monaco-editor/react) for the editor surface. libpg-query(wasm) for parsing, used by AI completions and the formatter.sql-formatterfor formatting.@supabase/sql-to-restfor the SQL → REST conversion shown in the snippet panel.packages/ai-commandsfor inline LLM completions.
Tabs and snippets are persisted via idb (IndexedDB) per project.
RLS and Auth-adjacent
RLS policy authoring lives in Database/Policies and Auth/Policies. The AI policy generator is implemented in packages/ai-commands/src/sql/. Validation uses pg-meta-policies.ts.
Integration points
packages/pg-metafor SQL generation.packages/api-typesfor typed access to the management API'sdatabase/queryendpoint.- Kong + postgres-meta for self-host.
- Logflare for query-performance and explain-visualizer telemetry.
Entry points for modification
- New table-editor capability → start in
components/interfaces/TableGridEditor/and add the necessary mutation underdata/tables/ordata/table-rows/. - New advisor → extend
Advisors/andLinter/, plus a query module underdata/lint/. - New SQL editor feature → most behavior is in
components/interfaces/SQLEditor/. Persistence and snippets indata/content/.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.