Docs/Govern/Export Schema
Pro

Export Schema

Use the Pro export-schema command to capture database schema as SQL migration files. It reads from a live database, a stored snapshot in the database, or a JSON snapshot file on disk.

This is different from Enterprise snapshot, which exports a portable JSON model for plan, preflight, and diff workflows. Use export-schema when you need SQL scripts — for example a brownfield baseline or a split-by-type migration layout.

Common workflows

Baseline from an existing database:

dblift export-schema --output migrations/V1__baseline.sql

Export only objects not yet managed by DBLift migrations (brownfield):

dblift export-schema --unmanaged-only --output migrations/unmanaged.sql

Export only objects defined in applied migrations:

dblift export-schema --managed-only --output migrations/managed.sql

Split output by object type:

dblift export-schema --split-by-type --output-dir migrations/baseline/

Export from a committed snapshot model (no live DB):

dblift export-schema \
--source file-model \
--snapshot-model snapshots/schema.json \
--output migrations/V1__baseline.sql

Export from the latest snapshot stored in the database:

dblift export-schema --source database-model --output migrations/V1__baseline.sql

Source options

--sourceDescription
live-database (default)Introspect the configured database connection
database-modelRead the latest schema snapshot stored in the database
file-modelRead a JSON snapshot file (--snapshot-model required)

Filtering options

OptionDescription
--schemaExport a single schema (defaults to configured schema)
--tablesComma-separated table names (includes related objects)
--typesObject types to include, e.g. tables,views,functions,triggers
--managed-onlyOnly objects tracked by applied migrations
--unmanaged-onlyOnly objects not tracked by migrations
--tags / --exclude-tagsFilter which migrations define managed objects
--versions / --exclude-versionsFilter by migration version
--target-versionConsider migrations up to this version only
--include-dropsEmit DROP statements for clean recreation
--descriptionText included in the migration header

Output options

OptionDescription
--outputSingle output file
--output-dirDirectory output (required with --split-by-type)
--split-by-typeWrite separate files per object type

Typical brownfield adoption

  1. Export unmanaged objects as a baseline migration.
  2. Run dblift baseline so DBLift treats the current state as already applied.
  3. Add new versioned migrations for future changes.

See Commands for the full option list and Snapshots for portable JSON models used by Enterprise workflows.

On this page