feat: add dependency graph API endpoint#1038
Open
jonathan-fulton wants to merge 1 commit intosupabase:masterfrom
Open
feat: add dependency graph API endpoint#1038jonathan-fulton wants to merge 1 commit intosupabase:masterfrom
jonathan-fulton wants to merge 1 commit intosupabase:masterfrom
Conversation
Add a new endpoint GET /dependency-graph that returns database object dependencies for visualization. Queries PostgreSQL system catalogs to build a complete graph of relationships between: - Tables (including partitioned tables) - Views and materialized views - Functions and procedures - Triggers - RLS policies - Indexes - Sequences - Custom types (enum, composite, domain) Edge types include: - Foreign key relationships - Trigger → table and trigger → function - Policy → table - Index → table - View dependencies - Function → table usage - Sequence ownership The endpoint supports filtering by schema and object type.
6 tasks
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a new API endpoint
GET /dependency-graphthat queries PostgreSQL system catalogs to return database object dependencies as nodes and edges, suitable for graph visualization.Motivation
Understanding database schema dependencies is challenging in complex projects. This endpoint enables building visual tools that show:
This is the backend foundation for an interactive Schema Graph feature in Supabase Studio.
Changes
New Files
src/lib/PostgresMetaDependencyGraph.ts- Main class that queries and transforms dependency datasrc/lib/sql/dependency_graph.sql.ts- SQL queries for nodes and edgessrc/server/routes/dependency-graph.ts- Fastify route handlerModified Files
src/lib/PostgresMeta.ts- Register dependency graph classsrc/lib/index.ts- Export new typessrc/lib/types.ts- Add TypeScript types and schemassrc/server/routes/index.ts- Register routeAPI
Endpoint
Query Parameters
include_system_schemasincluded_schemasexcluded_schemasincluded_typesResponse
Node Types Supported
Edge Types Supported
fk- Foreign key constraintstrigger_table- Trigger attached to tabletrigger_function- Trigger calls functionpolicy- RLS policy on tableindex- Index on tableview_dependency- View depends on table/viewfunction_table- Function references tablesequence_owned- Sequence owned by table columnTesting
Build passes:
The SQL queries have been tested against databases with complex schemas including multiple schemas, cross-schema references, triggers, policies, and materialized views.
Future Improvements