Skip to content

Failures, rollbacks and re-runs

The failure report

When a script fails, the report tells you everything needed to fix it without guessing. An example, abridged:

step 2/3 failed: 02-interest-function.sql, batch 1 of 1, line 14, column 9
PostgreSQL error 42883 (ERROR): function round(double precision, integer) does not exist
HINT: No function matches the given name and argument types. You might need to add explicit type casts.

  12 |   RETURN ROUND(
  13 |     principal *
> 14 |     power(1 + rate, months), 2);
  15 | END;

rollback of step 2: ok
rollback of step 1: ok
database state: back to how it was before the package
  • The file, the batch and the exact line (and column on PostgreSQL), mapped back to your script.
  • Everything the server said: error number or SQLSTATE, severity, state, detail, hint, the procedure or function where it happened.
  • The SQL around the error.
  • What happened afterwards: each rollback and the state the database was left in.

SQL Server reports the line where the failing statement starts; the report says so.

Rollbacks

With on_error: rollback (the default) the failed step's rollback runs first, then the rollbacks of the completed steps, newest first. With on_error: stop nothing is rolled back and the database stays as it was at the failure, for analysis.

If a rollback itself fails, the report says so and the history marks the database for manual review (failed_rollback_failed).

Re-running

A version whose last attempt failed can run again: each attempt is recorded with its own report (attempt 2, attempt 3…). Turn this off per environment with rerun_after_failure: false, or per run with --no-rerun.

Timeouts and cancellation

--timeout (and timeout per step) stops a script that runs too long; Ctrl+C cancels the running query on the server. In both cases the rollbacks still run.