Skip to content

Introspect

introspect(driver) reads a live database and returns its schema as TableDef[] — the same shape your code defines. This powers drift detection and the Studio ERD.

import { introspectorFor } from "@mountsqli/migration";
const introspect = introspectorFor("postgres");
const defs: TableDef[] = await introspect(driver);
Consumer Purpose
migrate generate compares live schema to code to compute the diff
migrate status detects drift (applied file missing / schema mismatch)
Studio ERD draws tables and relationships
mountsqli analyze reports schema vs live drift

introspectorFor(dialect) returns the right introspector:

  • sqlite — reads sqlite_master + PRAGMA table_info.
  • postgres — reads information_schema.
  • mysql — reads information_schema.

Catch drift in a script:

const live = await introspectorFor("postgres").introspect(driver);
const code = tablesOf(...myTables);
const diff = diffSchemas(live, code); // code as "after"
if (diff.changes.length) console.warn("Schema drift detected");
  • Introspect in a read-only or low-traffic context.
  • Use the result to report drift; fix it with a generated migration.
  • Treating introspected defs as the source of truth — code is.
  • Introspecting :memory: to compare against real schemas.