--from and --to flags, each accepting a typed URI in the form <prefix>:<location>. This document covers every available source type, when to reach for each one, and which --from/--to combinations suit common workflows.
Source Reference
Directory
Syntax:
dir:supabase/schemasSQL files on disk. The default --to source for most commands. supaschema recursively reads every .sql file in the specified path.Git ref
Syntax:
git:HEAD, git:origin/main, git:abc1234Schema at any committed Git ref. supaschema checks out the schemaPaths files at that ref without touching your working tree.Live database
Syntax:
database:$DATABASE_URLRead-only introspection of a live PostgreSQL connection. Never writes to the database.SQL dump
Syntax:
dump:path/to/schema.sql, dump:-A single SQL file, or standard input (-). Useful for one-off analysis of pg_dump output.Catalog snapshot
Syntax:
catalog:path/to/snapshot.jsonA JSON file produced by supaschema inspect. Lets you compare against a saved point-in-time without a live database.dir: — SQL Files on Disk
The dir: source is the backbone of the declarative workflow. supaschema walks the given directory, parses every .sql file it finds, and assembles a SchemaModel from all the CREATE statements inside.
- Local development — your schema files live in the repository alongside your application code.
- Any command where the desired state is what you have currently checked out.
Directory layout example
git: — Schema at a Git Ref
The git: source lets supaschema read the schemaPaths files as they exist at any Git commit, branch, or tag — without modifying your working tree or requiring a database connection.
- CI pull request checks — generate the migration that would be produced by merging this branch, and fail the pipeline if it contains unreviewed destructive operations.
- Release diffs — quickly see what changed between two tagged versions.
- Code review — produce a human-readable SQL diff alongside the file diff in your PR.
supaschema resolves
git: refs against the repository that contains your schemaPaths. The working directory must be inside a Git repository, and the ref must be reachable (fetched). For remote refs like git:origin/main, run git fetch first in your CI step.CI pipeline example
database: — Live Database Introspection
The database: source connects to a running PostgreSQL instance, queries the system catalogs (pg_class, pg_attribute, information_schema, etc.), and builds a SchemaModel from what is actually deployed. The connection is read-only — supaschema never executes DDL against a database: source.
- Initial onboarding — you have an existing database and want to generate your first declarative schema files.
- Drift detection — check whether someone has made out-of-band changes directly on the server.
- Generating a migration from scratch — when you have no prior snapshot, the live database is the most authoritative “from” state.
Connection string formats
dump: — SQL Dump File
The dump: source treats a single SQL file — such as the output of pg_dump --schema-only — as a schema source. You can point it at a file path or pass - to read from standard input.
- One-off analysis — you received a schema dump from a client or legacy system and want to diff it against your current declarative files.
- Audit trails — archive periodic
pg_dumpsnapshots and compare them over time. - Offline workflows — you have a dump but no live connection to the source database.
dump: sources accept the full pg_dump --schema-only output format, including SET statements and pg_catalog preambles. supaschema filters these automatically and focuses on user-defined objects.catalog: — Saved Catalog Snapshot
A catalog snapshot is the JSON output of supaschema inspect. It captures a SchemaModel — including the fingerprint — at a specific point in time. You can save it to a file and reference it later as a source.
- Drift detection without a second live connection — store the post-deploy snapshot in your repo and compare against it in CI instead of needing credentials to a second environment.
- Reproducible comparisons — a
catalog:file is deterministic and version-controllable, unlike a live database connection. - Debugging — share a
catalog:file with a teammate so they can reproduce a diff locally without access to your database.
Common --from / --to Combinations
The table below summarises the most useful source pairings and the workflow each one powers.
| Scenario | --from | --to | Purpose |
|---|---|---|---|
| Local development | database:$LOCAL_URL | dir:supabase/schemas | Generate a migration from your local DB to edited schema files |
| PR safety check (CI) | git:origin/main | dir:supabase/schemas | Diff the branch against the base without a database |
| Deploy to production | database:$PROD_URL | dir:supabase/schemas | Generate a migration targeting the live production database |
| Drift detection | database:$PROD_URL | catalog:snapshots/last-deploy.json | Detect out-of-band changes on the server |
| Onboarding existing DB | database:$DATABASE_URL | dir:supabase/schemas | Bootstrap declarative files from a live database |
| Cross-branch comparison | git:origin/main | git:feature/my-branch | Preview the migration a merge would produce |
| Analyse a legacy dump | dump:legacy-schema.sql | dir:supabase/schemas | Diff a dump file against your current schema |