Loading…
Loading…
Describes the KnownChecksumVariantHealer, which automatically repairs specific database migration checksum mismatches to prevent application startup
The KnownChecksumVariantHealer is an automated utility that runs during application startup to prevent a specific class of database migration failures. It is a Flyway callback that detects and corrects known, benign checksum mismatches in the database migration history table.
This component solves a problem where an application fails to start because Flyway's validation step detects a "Migration checksum mismatch". This can happen if a previously applied migration script file is altered in a way that changes its checksum, even if the change is non-functional (e.g., editing a SQL comment).
The healer targets a very specific scenario: a migration script was shipped in two different byte variants that are functionally identical but have different checksums. Databases that applied the initial variant will fail validation against any application build that includes the final variant. Instead of requiring manual database repair, the KnownChecksumVariantHealer automatically updates the recorded checksum in the database to match the canonical version shipped with the application, allowing startup to proceed.
The process is automatic, safe, and narrowly scoped. It only acts on a predefined list of known benign variants. Any other checksum mismatch will still cause Flyway to fail validation as expected, preserving the integrity of the migration process.
The KnownChecksumVariantHealer integrates with the Flyway migration process as a Callback bean, automatically discovered and registered by the platform's Spring Boot configuration. It is designed to be idempotent and safe, ensuring that it either fixes a known issue or has no effect.
The healing process is triggered before Flyway's main validation and migration phases.
sequenceDiagram
participant App as Application Startup
participant Flyway
participant Healer as KnownChecksumVariantHealer
participant DB as Database
App->>Flyway: Initiate migrations
Flyway->>Healer: handle(BEFORE_VALIDATE)
Healer->>DB: Check for history table
alt History table exists
DB-->>Healer: Table name
Healer->>Healer: For each known variant...
Healer->>DB: UPDATE history table SET checksum=toChecksum WHERE version=v AND checksum=fromChecksum
DB-->>Healer: N rows updated
opt N > 0
Healer->>Healer: Log S2R-FLYWAY-CHECKSUM-HEAL
end
else History table does not exist
DB-->>Healer: Not found
Healer-->>Flyway: Return (no-op)
end
Healer-->>Flyway: Return
Flyway->>Flyway: Proceed with standard validationBEFORE_VALIDATE and BEFORE_MIGRATE events.defaultSchema and schemas properties. If the history table does not exist (e.g., on a fresh database installation), the healer does nothing.KNOWN_VARIANTS). For each variant, it executes a SQL UPDATE statement to change the old checksum (fromChecksum) to the new, correct checksum (toChecksum) for the specified migration version.INFO message with the code S2R-FLYWAY-CHECKSUM-HEAL. This log entry includes the table name, migration version, the old and new checksums, the number of rows affected, and the reason for the change.UPDATE statement's WHERE clause will no longer match any rows for an already-healed variant, so the operation has no effect.The entire healing process is wrapped in a try-catch block. If any SQLException or RuntimeException occurs (e.g., due to insufficient database permissions), the healer will:
WARN message with the code S2R-FLYWAY-CHECKSUM-HEAL could not run.Flyway will then proceed with its standard validation. If the checksum mismatch was not fixed, Flyway will report its normal "Migration checksum mismatch" error and the application will fail to start. This design ensures the healer never introduces a new failure mode.
When the KnownChecksumVariantHealer finds and corrects a known checksum mismatch, it produces a log entry similar to the following. This indicates that a manual database intervention was successfully avoided.
S2R-FLYWAY-CHECKSUM-HEAL table=public.flyway_schema_history version=256 from=49376275 to=-1205763391 rows=1 reason="V256 intermediate variant (2026-08-11..08-26) differs from the shipped file in one SQL comment line only; no DDL difference"
The KnownChecksumVariantHealer is enabled automatically and has no direct configuration properties. However, its behavior is influenced by the standard Flyway configuration used by the application, as it uses these settings to locate the migration history table.
| Property (Flyway) | Type | Description |
|---|---|---|
table | String | The name of the Flyway schema history table. The healer uses this to target its UPDATE statements. |
defaultSchema | String | The default schema used for database connections. The healer prioritizes this schema when qualifying the history table name. |
schemas | String[] | A list of schemas to search for database objects. If defaultSchema is not set, the healer uses the first schema in this list. If neither is set, the connection's current schema is used. |
The healer will only act on the specific version and checksum pairs defined in its internal KNOWN_VARIANTS list. Any other mismatch will be ignored and reported by Flyway as a validation failure.
| Version | From Checksum | To Checksum | Reason |
|---|---|---|---|
256 | 49376275 | -1205763391 | An intermediate variant of migration V256, live between 2026-08-11 and 2026-08-26, differed from the final shipped file in a single SQL comment line. The DDL is identical. |
IMPORTANT
The toChecksum value must always match the checksum of the migration file as it is currently shipped with the product. This is enforced by internal tests.
| Symptom | Meaning | Resolution |
|---|---|---|
| Application fails to start with a "Migration checksum mismatch" error. | The checksum of an applied migration in the database does not match the checksum of the corresponding file in the current application build. If the version and checksums do not appear in the Known Variants Reference, this is an unexpected and potentially harmful change that the healer correctly ignored. | Investigate the history of the reported migration file to understand why its contents changed. Do not manually alter the database unless you are certain the change is benign. |
A log entry appears with S2R-FLYWAY-CHECKSUM-HEAL could not run. | The healer attempted to run but encountered an error, such as insufficient database permissions. The automatic repair did not occur. | Review the exception details in the log. Grant the necessary permissions (e.g., UPDATE on the Flyway history table) to the application's database user. The application will likely fail to start with a standard Flyway checksum error until the healer can run successfully. |