Search code examples
postgresqlmicronaut

Micronaut: use Flyway to run db migrations on micronaut-postgres-reactive (based on reactive-pg-client)


I have been able to successfully instantiate a connection to PostgreSQL using the reactive driver and config as per the micronaut docs. See: https://docs.micronaut.io/snapshot/guide/index.html#postgresSupport

I have been trying to figure out a way to use flyway to run db migrations but in order to instantiate a flyway bean I need a Datasource which doesn't seem to be possible to get using the reactive driver.


Solution

  • You don't need a datasource bean to instantiate flyway. You can provide it with the url, username, and password instead.

    The micronaut configuration can be injected and read to get the configuration values. io.micronaut.configuration.postgres.reactive.PgPoolConfiguration

    From their docs:

        // Create the Flyway instance and point it to the database
        Flyway flyway = Flyway.configure().dataSource("jdbc:h2:file:./target/foobar", "sa", null).load();
    
        // Start the migration
        flyway.migrate();