apply
Applies a migration pack file to the production database. All statements are executed inside a single transaction — either everything commits or everything rolls back.
Usage
deepdiffdb apply --pack diff-output/migration_pack.sql --config deepdiffdb.config.yaml
What It Does
- Reads and parses the migration pack SQL file.
- Opens a connection to the production database (as defined in the config file).
- Begins a database transaction.
- Executes each statement in order.
- On success: commits the transaction.
- On any error: rolls back the transaction automatically, leaving production unchanged.
Flags
| Flag | Required | Description |
|---|---|---|
--pack | Yes | Path to the migration pack SQL file |
--config | No | Path to the configuration file (default: deepdiffdb.config.yaml) |
--dry-run | No | Validate the SQL without executing it |
--resume | No | Resume from the last saved checkpoint |
--verbose | No | Enable debug-level logging |
--log-level | No | Minimum log level: debug, info, warn, error (default: info) |
--log-format | No | Log output format: text or json (default: text) |
--log-file | No | Write logs to this file in addition to stdout |
Dry Run Mode
Use --dry-run to parse and validate the pack without executing any statements:
deepdiffdb apply --pack diff-output/migration_pack.sql --dry-run
Dry run output:
Dry-run mode: no changes will be applied.
Parsed 31 statements.
Validation passed.
Example — Live Apply
deepdiffdb apply \
--pack diff-output/migration_pack.sql \
--config deepdiffdb.config.yaml \
--log-format json \
--log-file apply.log
Expected output on success:
Applying migration pack: diff-output/migration_pack.sql
Statements executed: 31
Transaction committed.
Apply complete.
Resume an Interrupted Apply
If apply is interrupted mid-way:
deepdiffdb apply \
--pack diff-output/migration_pack.sql \
--config deepdiffdb.config.yaml \
--resume
DeepDiff DB loads the last apply checkpoint and continues from the last committed batch. See Checkpoint and Resume for details.
Safety Notes
applyonly writes to the production database; it never reads from or writes to the dev database.- The migration pack is generated by
gen-pack— always reviewmigration_pack.sqlbefore runningapply. - Use
--dry-runin CI to validate the pack before scheduling a maintenance window. - If the transaction rolls back, the error message includes the failing statement for quick diagnosis.
Exit Codes
| Code | Meaning |
|---|---|
0 | Apply completed successfully |
1 | Apply failed; transaction was rolled back |