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);How it is used
Section titled “How it is used”| 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 |
Dialect support
Section titled “Dialect support”introspectorFor(dialect) returns the right introspector:
sqlite— readssqlite_master+PRAGMA table_info.postgres— readsinformation_schema.mysql— readsinformation_schema.
Real-world example
Section titled “Real-world example”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");Best practices
Section titled “Best practices”- Introspect in a read-only or low-traffic context.
- Use the result to report drift; fix it with a generated migration.
Common mistakes
Section titled “Common mistakes”- Treating introspected defs as the source of truth — code is.
- Introspecting
:memory:to compare against real schemas.
Related
Section titled “Related”- How Migrations Work — diff model.
- DDL Generation — the forward direction.
