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.
| Key | Environment | What it does |
|---|---|---|
target_version | DBLIFT_TARGET_VERSION | Stop 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_run | DBLIFT_DRY_RUN | Preview 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_executed | DBLIFT_MARK_AS_EXECUTED | Record migrations without running them. This takes the migration lock. |
tags | DBLIFT_TAGS | Include these tags. |
exclude_tags | DBLIFT_EXCLUDE_TAGS | Skip these tags. |
versions | DBLIFT_VERSIONS | Run these versions. |
exclude_versions | DBLIFT_EXCLUDE_VERSIONS | Skip 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.
migrations:
directories:
- "./migrations"
- path: "./vendor/sql"
recursive: false
script_encoding: "utf-8"
detect_encoding: falseSetting 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
| Key | Default | What 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. |
directory | migrations | Single-directory form, kept for older projects. Use directories instead. |
recursive | true | Whether subdirectories are scanned. Applies to any entry that does not set its own. |
table | schema_version | Name recorded for the migration set. The applied-history table is the root history_table key, not this one. |
script_encoding | utf-8 | Encoding used to read migration files. |
detect_encoding | false | Detect 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.
placeholders:
TABLE_NAME: users
LABEL_VALUE: hellodblift migrate --placeholders TABLE_NAME=users LABEL_VALUE=hello --dry-run --show-sqldblift 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.