{"record":{"id":"33f77b507a342dd2","repo":"kestra-io/kestra","slug":"cannot-repair-migration-script-scriptid-becaus","errorCode":null,"errorMessage":"Cannot repair migration script [<scriptId>] because it has not been applied.","messagePattern":"Cannot repair migration script \\[<scriptId>\\] because it has not been applied\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/migration/MigrationRunner.java","lineNumber":151,"sourceCode":"    public void repairChecksum(final String scriptId) throws MigrationLockedException, Exception {\n        if (!lock.tryAcquire()) {\n            throw new MigrationLockedException();\n        }\n\n        try {\n            historyStore.bootstrapIfNeeded();\n\n            MigrationScript script = scripts.stream()\n                .filter(candidate -> candidate.scriptId().equals(scriptId))\n                .findFirst()\n                .orElseThrow(() -> new IllegalArgumentException(\"Unknown migration script [\" + scriptId + \"].\"));\n\n            if (script.checksum() == null) {\n                throw new IllegalArgumentException(\"Migration script [\" + scriptId + \"] has no checksum to repair.\");\n            }\n\n            if (!historyStore.isApplied(scriptId)) {\n                throw new IllegalStateException(\"Cannot repair migration script [\" + scriptId + \"] because it has not been applied.\");\n            }\n\n            historyStore.updateChecksum(script);\n            log.info(\"Migration checksum repaired for script [{}].\", scriptId);\n        } finally {\n            lock.release();\n        }\n    }\n\n    /**\n     * Returns all scripts that have not yet been applied, sorted by {@code scriptId}.\n     * Used by EE to detect pending scripts before deciding whether to run or fail.\n     *\n     * <p>\n     * This method does <strong>not</strong> acquire the migration lock. It is intended as a\n     * read-only startup check on a single node (EE {@code auto=false} path) to decide whether to\n     * throw {@link MigrationPendingException}. In multi-node deployments, callers should be aware\n     * that another node may concurrently apply migrations between this call and any subsequent action.","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/migration/MigrationRunner.java#L133-L169","documentation":"Thrown by repairChecksum() when historyStore.isApplied(scriptId) returns false — the script was never executed against the backend, so there is no stored checksum row to update. Repair is only meaningful for scripts already recorded in migration history. This is an IllegalStateException (not argument) signalling the requested operation is invalid for the current backend state.","triggerScenarios":"Calling repair on a pending (not-yet-applied) migration script; calling repair before any migrations have run on a fresh instance; the history store bootstrap recorded the script as absent.","commonSituations":"New script added that has not yet been executed; operator assumes a script ran but it was skipped; fresh database where history is empty.","solutions":["Run 'kestra migrate' to apply pending scripts first.","After migration completes, re-run 'kestra migrate repair <scriptId>' if a checksum drift still exists.","If the script should already be applied, verify the history table is not corrupt or truncated."],"exampleFix":"// before\n$ kestra migrate repair 0_009_xyz\n// IllegalStateException: not applied\n\n// after\n$ kestra migrate            // apply first\n$ kestra migrate repair 0_009_xyz","handlingStrategy":"validation","validationCode":"if (!historyStore.isApplied(scriptId)) {\n    log.warn(\"Script {} not applied yet; run migrations before repair.\", scriptId);\n    return;\n}","typeGuard":null,"tryCatchPattern":"try {\n    migrationRunner.repairChecksum(scriptId);\n} catch (IllegalStateException e) {\n    log.warn(\"Cannot repair {}: {}\", scriptId, e.getMessage());\n    // run 'kestra migrate' first, then retry\n}","preventionTips":["Apply all pending migrations before repairing checksums.","Verify history-store state before invoking repair."],"tags":["migration","state","repair","validation"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}