> For the complete documentation index, see [llms.txt](https://docs.openiam.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.openiam.com/troubleshooting/databases/run_flyway_repair_mode.md).

# Run Flyway in repair mode

Clearing a Flyway checksum mismatch by running the migration in repair mode, then putting the command back.

| Symptom                                                                                        | Likely cause                                                                          | Resolution                                   |
| ---------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | -------------------------------------------- |
| `Validate failed: Migrations have failed validation`, with a checksum mismatch for one version | A migration already applied to this database was changed afterwards in the repository | Run the migration once in repair mode, below |

Flyway records a checksum for every migration it applies. If that script is edited later, the recorded checksum and the current one disagree and Flyway refuses to go further:

{% code overflow="wrap" %}

```
ERROR: Validate failed: Migrations have failed validation
Migration checksum mismatch for migration version 4.2.1.2.001
-> Applied to database : 938263552
-> Resolved locally    : 726554884. Either revert the changes to the migration, or run repair to update the schema history.
```

{% endcode %}

**Repair rewrites the recorded checksums to match the scripts as they are now.** It does not re-run anything, so it fixes the bookkeeping rather than the database.

{% hint style="info" %}
This is most common on deployments tracking a `dev` or `qa` tag, where a migration can still change after it has been released.
{% endhint %}

## How the mode is set

The migration script `flyway.migrate.sh` reads the environment variable **`FLYWAY_COMMAND`**, which defaults to `migrate`. Setting it to `repair` changes what that one run does — the mechanism is the same on both deployment types, and only the place you set it differs.

{% tabs %}
{% tab title="RPM" %}
{% stepper %}
{% step %}
**Set the command for the run.**

```bash
export FLYWAY_COMMAND=repair
```

{% endstep %}

{% step %}
**Run the migration**, and read its output. The checksum error should be gone.
{% endstep %}

{% step %}
**Put it back**, so the next run migrates rather than repairing:

```bash
unset FLYWAY_COMMAND
```

{% endstep %}
{% endstepper %}
{% endtab %}

{% tab title="Kubernetes" %}
{% stepper %}
{% step %}
**Set `openiam.flyway.command` to `repair`** in your Helm values. The Flyway job passes it straight through as `FLYWAY_COMMAND`:

{% code title="values.yaml" %}

```yaml
openiam:
  flyway:
    command: "repair"
```

{% endcode %}
{% endstep %}

{% step %}
**Re-run the Flyway job**, then read its log. The checksum error should be gone.

```bash
kubectl logs job/flyway-job
```

{% endstep %}

{% step %}
**Set it back to `migrate`.**
{% endstep %}
{% endstepper %}
{% endtab %}
{% endtabs %}

{% hint style="warning" %}
**Leaving `repair` set means migrations stop being applied.** It is not a one-shot — every subsequent run would repair instead of migrating, and new schema changes would silently never land.
{% endhint %}

If the mismatch returns after a later update, the same script was edited again; repeat these steps.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.openiam.com/troubleshooting/databases/run_flyway_repair_mode.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
