Skip to content
Latchkey

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 migrate with -url, -user, -password, and -locations.
  • Use the flyway/flyway Docker 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 test

Gotchas

  • 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 host so the container reaches the service on localhost, or connect by the runner host IP.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →