How to Run Flyway Migrations in GitHub Actions
Run flyway migrate via the official Flyway image (or CLI) against the CI database to apply versioned SQL migrations from your migrations folder.
Mount your sql/ migrations into the flyway/flyway image and run migrate with the JDBC URL of the CI service container. Flyway tracks applied versions in its schema history table.
Steps
- Start the database service with a health check.
- Run
flyway migratewith-url,-user,-password, and-locations. - Use the
flyway/flywayDocker image or install the CLI.
Workflow
.github/workflows/ci.yml
steps:
- uses: actions/checkout@v4
- name: Run Flyway migrations
run: |
docker run --rm --network host \
-v "$PWD/sql:/flyway/sql" \
flyway/flyway:10 \
-url=jdbc:postgresql://localhost:5432/app_test \
-user=postgres -password=postgres \
-locations=filesystem:/flyway/sql \
migrate
- run: ./gradlew testGotchas
- A checksum mismatch means a previously applied migration file changed; never edit an applied migration, add a new one or run
flyway repair. - Use
--network hostso the container reaches the service onlocalhost, or connect by the runner host IP.
Related guides
How to Run Liquibase Migrations in GitHub ActionsApply Liquibase changelog migrations in GitHub Actions using the official liquibase Docker image, running liq…
How to Run Database Migrations Before Tests in GitHub ActionsApply schema migrations against the CI database in a step that runs before your test command, so the test sui…
How to Validate Migrations Are Reversible in GitHub ActionsVerify a new migration can roll back cleanly in GitHub Actions by applying it, rolling it back one step, and…