Docs/Configuration/migrations
OSS

migrations

Where migration files are found and how they are read. A root migrations_dir key raises, including an empty or null value. Move it to migrations.directory or migrations.directories. The migrations_dir argument of the Python API and the CLI is unchanged.

Which files a run applies can come from the command flags, from DBLIFT_*, or from YAML. An explicit argument wins, then the environment, then the file. from_config_file applies the same keys. from_sqlalchemy without config= reads neither the file nor the environment.

KeyEnvironmentWhat it does
target_versionDBLIFT_TARGET_VERSIONStop at this script version. An unknown version is a usage error: CLI exit 2, or InvalidTargetVersionError from the API. An empty YAML value is refused. An empty environment variable is ignored. undo also accepts 0 and an applied version whose file was deleted.
dry_runDBLIFT_DRY_RUNPreview without applying. A configured true is not cleared by the Python default dry_run=False. Clear it in YAML or with DBLIFT_DRY_RUN=false.
mark_as_executedDBLIFT_MARK_AS_EXECUTEDRecord migrations without running them. This takes the migration lock.
tagsDBLIFT_TAGSInclude these tags.
exclude_tagsDBLIFT_EXCLUDE_TAGSSkip these tags.
versionsDBLIFT_VERSIONSRun these versions.
exclude_versionsDBLIFT_EXCLUDE_VERSIONSSkip these versions.

Boolean environment values are true only for 1, true, or yes.

Directories

A directory entry is either a plain path or a path with its own recursive setting. Mixing both forms in one list is fine.

yaml
migrations: directories: - "./migrations" - path: "./vendor/sql" recursive: false script_encoding: "utf-8" detect_encoding: false

Setting directories makes the older single directory key inert — it is not appended to the list. With neither set, DBLift reads ./migrations. For a tree with one folder per module, see Multi-module projects.

Keys

KeyDefaultWhat it does
directories[]Where migration files are found. Each entry is a path, or a path with its own recursive setting. When set, directory is ignored.
directorymigrationsSingle-directory form, kept for older projects. Use directories instead.
recursivetrueWhether subdirectories are scanned. Applies to any entry that does not set its own.
tableschema_versionName recorded for the migration set. The applied-history table is the root history_table key, not this one.
script_encodingutf-8Encoding used to read migration files.
detect_encodingfalseDetect each file's encoding before reading it, rather than assuming the setting above.

Placeholders

SQL files may contain ${NAME} or ${NAME:default}. Values are merged from the root placeholders: map, then --placeholders on the command.

yaml
placeholders: TABLE_NAME: users LABEL_VALUE: hello
dblift migrate --placeholders TABLE_NAME=users LABEL_VALUE=hello --dry-run --show-sql
dblift migrate --placeholders "TABLE_NAME=users,LABEL_VALUE=hello"

Unresolved tokens stay in the SQL and a warning is logged. Python migrations are not substituted — they read context.placeholders. See dblift migrate.

On this page