Work / System utility

PostgreSQL Schema Knowledge Graph

EXPERIMENTAL

เปลี่ยนโครงสร้างฐานข้อมูล PostgreSQL เป็น Knowledge Graph ใน Obsidian

Source repository

Database schema documentation is frequently stale or buried in dense DDL migration files, obscuring referential integrity and data dependencies.

My implementation: Python and SQLAlchemy schema inspector querying PostgreSQL information_schema. Markdown exporter emitting table details and relational wikilinks.

The script reads PostgreSQL metadata and counts table rows; SELECT access to those tables is required.

01

Context

Understanding relational database schemas across hundreds of tables with complex foreign keys is cognitively demanding without interactive lineage graphs.

Problem

Database schema documentation is frequently stale or buried in dense DDL migration files, obscuring referential integrity and data dependencies.

What it enables

Automatically maps PostgreSQL catalog tables and foreign key dependencies into an interactive graph network, enabling instant relationship exploration and visual schema audit.

Constraints

  • The script reads PostgreSQL metadata and counts table rows; SELECT access to those tables is required.
  • Generates standardized Obsidian wikilink markdown notes for offline graph visualization.
02

System

Automated extraction of PostgreSQL schema relationships, constraints and foreign keys into interconnected Obsidian Graph notes and Markdown documentation.

SCHEMA-MAP ENGINE
PostgreSQL DDL & Foreign Keys → Obsidian Graph View

Illustrative schema and row estimates. This viewer is not connected to a live database.

Extracted Tables:6 relational entities
FK Relationships:5 referential constraints
Output Destination:Obsidian Graph View (.md wikilinks)

Inputs

  • PostgreSQL information_schema tables and key column usage catalogs
  • Foreign key constraint definitions and referential actions
  • Table column definitions, data types, nullability, and primary key metadata

Implementation

  • A Python SQLAlchemy inspector reads public-schema tables, keys, columns and indexes.
  • An incoming-key index complements outgoing foreign keys; the relationships are not assumed to form an acyclic graph.
  • The script writes Markdown tables, relation lists, row counts and an index note for Obsidian.
  • Python and SQLAlchemy schema inspector querying PostgreSQL information_schema.
  • Markdown exporter emitting table details and relational wikilinks.
03

Decisions

  • Map foreign keys as directional wikilinksBidirectional linking allows exploring upstream dependencies and downstream consumers organically.
  • Keep columns, keys and indexes beside the relation linksGenerated notes make the schema details available without reconnecting to the database at question time.
04

Artifacts

The artifact above is the committed evidence for this project. More screenshots and files are in the public repository.

05

Evidence

Evidence classes distinguish what can be inspected directly from what is documented, simulated or reconstructed.

06

Limitations

  • Snapshot utility: re-run after schema changes. Row counts require table SELECT access and may be costly on large tables.
  • Relationship labels use a heuristic and require review for composite keys. The portfolio viewer is illustrative, not connected to a database.

Discuss a system like this.

Start a work enquiryAll work