Skip to main content

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

  1. Reads and parses the migration pack SQL file.
  2. Opens a connection to the production database (as defined in the config file).
  3. Begins a database transaction.
  4. Executes each statement in order.
  5. On success: commits the transaction.
  6. On any error: rolls back the transaction automatically, leaving production unchanged.

Flags

FlagRequiredDescription
--packYesPath to the migration pack SQL file
--configNoPath to the configuration file (default: deepdiffdb.config.yaml)
--dry-runNoValidate the SQL without executing it
--resumeNoResume from the last saved checkpoint
--verboseNoEnable debug-level logging
--log-levelNoMinimum log level: debug, info, warn, error (default: info)
--log-formatNoLog output format: text or json (default: text)
--log-fileNoWrite 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

  • apply only writes to the production database; it never reads from or writes to the dev database.
  • The migration pack is generated by gen-pack — always review migration_pack.sql before running apply.
  • Use --dry-run in 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

CodeMeaning
0Apply completed successfully
1Apply failed; transaction was rolled back