Docs/Commands/export-schema
Progenerated from cli/_parser_setup.py
dblift export-schema
Export database schema objects to SQL migration files. Filter by object type, schema, and migration status; write one file or split by type into a directory. The most common use is baselining a brownfield database — exporting the objects your migrations do not yet describe.
Synopsis
$ dblift export-schema [--output PATH | --output-dir DIR [--split-by-type]]
[--source SOURCE] [--snapshot-model PATH]
[--schema NAME] [--tables LIST] [--types LIST]
[--managed-only | --unmanaged-only]
[--include-drops] [--description TEXT]
[--tags TAGS] [--exclude-tags TAGS]
[--versions LIST] [--exclude-versions LIST]
[--target-version VERSION]
[--table TABLE] [--snapshot-table TABLE]Options
FlagDescription
--tableCustom schema history table name (default: dblift_schema_history)--snapshot-tableCustom schema snapshot table name (default: dblift_schema_snapshots)--outputOutput file path (single file output). Use --output-dir for directory output--output-dirOutput directory path (for split-by-type output or multiple files)--sourceSource for schema data: 'database-model' (latest snapshot from database), 'file-model' (JSON model file), or 'live-database' (default, introspect live database). 'database-stored' is accepted as a deprecated alias for 'database-model'.--snapshot-modelPath to JSON model file (required when --source=file-model)--split-by-typeSplit output into separate files by object type (requires --output-dir)--descriptionDescription to include in migration header--schemaDatabase schema name to export (default: use config schema). Only objects from this schema will be exported.--tablesComma-separated list of table names to export (filters to specific tables and related objects)--typesComma-separated list of object types to export (e.g., tables,views,indexes,functions,triggers)--managed-onlyExport only objects defined in applied migrations (tracked objects). Requires --scripts directory to parse migration files.--unmanaged-onlyExport only objects not defined in applied migrations (brownfield baseline). Requires --scripts directory to parse migration files.--include-dropsInclude DROP statements in output (for clean recreation)--tagsOnly consider migrations with specified tags when determining managed objects (comma-separated list)--exclude-tagsExclude migrations with specified tags when determining managed objects (comma-separated list)--versionsOnly consider specific migration versions when determining managed objects (comma-separated list)--exclude-versionsExclude specific migration versions when determining managed objects (comma-separated list)--target-versionOnly consider migrations up to this version when determining managed objectsGlobal flags apply to every command: --config, --env, --scripts, --dry-run, --quiet, --log-level. See global flags.
Examples
Capture the whole live schema into one file
$ dblift export-schema --output migrations/V1_0_0__initial_schema.sqlBaseline a brownfield database — export only what migrations do not describe
$ dblift export-schema --unmanaged-only --scripts migrations --output-dir baseline --split-by-typeExport a few tables and their related objects
$ dblift export-schema --tables customers,orders --types tables,indexes --output orders.sqlExit codes
CodeMeaning
0Command completed successfully4A paid-edition feature was invoked without a valid licence (EXIT_LICENSE_REQUIRED)