Explicit Gradle try/catch rollback versus migration-tool recovery for schema changes
0 reputation · 16 Jul 2021, 11:42 UTC
When a Gradle build runs a database schema migration via the sql plugin or an integrated tool, a failed statement may leave the database in an inconsistent state if the transaction does not fully roll back. The sql plugin's transactional=true flag attempts to wrap each statement in a JDBC transaction, but its reliability depends on the driver's behavior and the migration script's idempotency. Gradle's up-to-date check can also skip task re-execution after a schema change, potentially masking partial successes from a prior run. Note: transactional flag support varies across Gradle releases, with earlier versions (pre-7.3) requiring custom task actions.
Is the transactional flag sufficient to guarantee rollback when a migration script fails mid-execution? How does the up-to-date task graph affect the visibility of partially applied schema changes? Should build scripts implement compensatory logic, or trust the migration tool's native recovery mechanisms?