# Add Flyway Migrations to a Quarkus App

Yes. An agent adds quarkus-flyway, turns import.sql and the create strategy into V1 and V2 migration files, keeps the RestAssured tests green and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-flyway-migrations/quarkus/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads how the schema is produced before it writes a migration. In a service shaped like the `hibernate-orm-panache-quickstart` of quarkusio/quarkus-quickstarts, `pom.xml` imports `io.quarkus.platform:quarkus-bom` 3.40.1.1 and depends on `quarkus-hibernate-orm-panache`, `quarkus-rest-jackson` and `quarkus-jdbc-postgresql`, with `quarkus-junit` and `rest-assured` for tests, on Java 17. `src/main/resources/application.properties` has five lines: SQL logging on, `quarkus.hibernate-orm.sql-load-script=import.sql`, and for the `prod` profile a datasource URL plus `quarkus.hibernate-orm.schema-management.strategy=create`, which drops and recreates every table on each start. `import.sql` inserts Cherry, Apple and Banana into both `fruitEntity` and `fruit` and restarts the two sequences at 4. The two entities, `FruitEntity` extending `PanacheEntity` and `Fruit` with its own `@Id @GeneratedValue`, each have a `name` column of length 40 with a unique constraint.

The agent adds `io.quarkus:quarkus-flyway` to `pom.xml`, unversioned under the BOM, and writes `src/main/resources/db/migration/V1__create_fruit_tables.sql` with the DDL Hibernate was generating: the two tables, their sequences with `INCREMENT BY 50` to match Panache's default allocation, and the unique constraints on `name`. `V2__seed_fruits.sql` carries the three rows per table from `import.sql`, and `import.sql` is deleted along with its `sql-load-script` line. In `application.properties` the `prod` strategy becomes `none`, `quarkus.flyway.migrate-at-start=true` applies to every profile, and `quarkus.hibernate-orm.schema-management.strategy=validate` is set so a drift between an entity and the migrated schema fails startup with a clear message instead of silently working.

Dev and test profiles use Dev Services, which start a PostgreSQL container for `./mvnw quarkus:dev` and `./mvnw verify` when Docker is available; the migrations run there too, so `FruitsEndpointTest` keeps reading the three seeded fruits through `/entity/fruits` and `/repository/fruits` and deleting id 1. The agent adds `FlywayMigrationTest`, a `@QuarkusTest` that injects `Flyway` and asserts `flyway.info().current().getVersion()` is 2 and that both tables exist through a count query, and the matching `IT` subclass the quickstart convention uses for the native profile.

Before pushing, the agent runs `./mvnw -B clean verify` on JDK 21, the version `.github/workflows/build-pr-development.yml` uses, writes explicit imports because that workflow fails any `*;` import, and pastes the Surefire summary plus the Flyway log lines, `Migrating schema "public" to version "1 - create fruit tables"` and the version 2 line, in the pull request.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "codex",
  "input": "Add Flyway migrations to this Quarkus service and open a pull request. Read pom.xml, src/main/resources/application.properties, src/main/resources/import.sql, src/main/java/org/acme/hibernate/orm/panache/entity/FruitEntity.java, src/main/java/org/acme/hibernate/orm/panache/repository/Fruit.java, src/test/java/org/acme/hibernate/orm/panache/FruitsEndpointTest.java and FruitsEndpointIT.java first. Add quarkus-flyway unversioned under the BOM. Write src/main/resources/db/migration/V1__create_fruit_tables.sql with the tables, sequences and unique constraints Hibernate currently generates, and V2__seed_fruits.sql with the rows from import.sql. Remove import.sql and the sql-load-script property. Set quarkus.flyway.migrate-at-start=true, change the prod schema-management strategy to none and set validate for all profiles. Add FlywayMigrationTest as a @QuarkusTest that checks the current version is 2 and both tables hold three rows, plus its IT subclass. Use explicit imports. Run ./mvnw -B clean verify and paste the Surefire summary and the Flyway migration log lines in the pull request. Do not change the resources, the entities or the Dockerfiles.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request with one new dependency in `pom.xml`, two files under `src/main/resources/db/migration/`, a deleted `import.sql`, a four-line change to `application.properties`, and `FlywayMigrationTest.java` with `FlywayMigrationIT.java`. The description shows the `./mvnw clean verify` summary and the two Flyway log lines from the test run, so the reviewer sees the migrations applied against a real PostgreSQL rather than described.

On a repository with the quickstarts' workflow, the pull request runs `./mvnw clean install` on JDK 21 and the wildcard-import check, and `FruitsEndpointTest` runs unchanged against the migrated schema, which is the real proof that `V1` matches what the entities expect; a column type or sequence mismatch fails that test, not the new one.

A reviewer checks that the `prod` strategy is `none` so Flyway owns the schema in production, that `validate` is on everywhere, that the sequence increment matches the entity's allocation size, and that the seed data belongs in a migration at all rather than in a dev-only script. Then they point `quarkus.datasource` at their database and run the jar once.

## Run it on every service onboarded to schema migrations

A platform team moving services from Hibernate-generated schemas to Flyway sends one `POST /o/{org}/sessions` per repository with this prompt and that repository in `resources`. Each run reads its own entities and `application.properties`, so a service with ten entities gets a `V1` that covers all ten, and each run opens its own pull request.

Give the API key a `webhook_url` and Rush POSTs `run.completed` when each turn ends, with the `session_url` to read the pull request and the migration log from.

## Why run it on Rush?

Writing `V1` by hand means reading every entity and reproducing the exact DDL Hibernate would emit, sequences and increments included, and the only way to know it is right is to run the suite against a database created by the migration alone. In a Rush sandbox the agent does that with the repository's own Maven wrapper, keeps every `mvnw` command and its output in the run's record, and the pull request shows the migration log lines a deploy would print.

The quickstart's existing tests act as the acceptance test: they pass only if the migrated schema serves the same rows the generated one did. The same request works unchanged on every Quarkus service a team owns that still uses `drop-and-create` or `create`.

## Frequently asked questions

### Does the test profile still need a database?

Yes. Without a `%test` datasource URL, Quarkus Dev Services starts a PostgreSQL container for the tests, as it did before the change, and Flyway runs against it. A machine without Docker needs a `%test.quarkus.datasource.jdbc.url` pointing at a database it can reach.

### Why keep validate on?

With `schema-management.strategy=validate`, Hibernate compares every mapped entity to the migrated tables at startup and refuses to start on a mismatch. That turns a forgotten migration into a startup error in dev rather than a `500` in production.

### What about the sequences Panache uses?

`PanacheEntity` ids come from `fruitEntity_SEQ` with an allocation size of 50, so `V1` creates the sequence with `INCREMENT BY 50`. Creating it with the default increment would still start but would raise duplicate-key errors after the first batch of inserts; the new test's row count would not catch that, which the pull request calls out.

### Does it add seed data to production?

`V2` carries the three fruits from `import.sql` because the existing tests depend on them. The pull request marks that file as the one to drop, or move to a `%dev`-only location with `quarkus.flyway.locations`, before the service ships.

## More Quarkus jobs

- [Add Graceful Shutdown to a Quarkus Service](https://getrush.ai/run/add-graceful-shutdown/quarkus/)
- [Add Health Checks to a Quarkus Service](https://getrush.ai/run/add-health-checks/quarkus/)
- [Add Input Validation to a Quarkus REST API](https://getrush.ai/run/add-input-validation/quarkus/)

## The same job on other stacks

- [Add Flyway Migrations to a Ktor App](https://getrush.ai/run/add-flyway-migrations/ktor/)

## More jobs like this: Hand off a long task

- [Add Form Validation to an Angular App](https://getrush.ai/run/add-form-validation/angular/)
- [Add Form Validation to a React Router App](https://getrush.ai/run/add-form-validation/react-router/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
