Created
October 1, 2021 17:54
-
-
Save ethan-gallant/449d96bfec012076ab4a34f86435bbde to your computer and use it in GitHub Desktop.
Quarkus Flyway Workaround
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.rocketplatform.service.player.database; | |
import io.quarkus.runtime.StartupEvent; | |
import org.eclipse.microprofile.config.inject.ConfigProperty; | |
import org.flywaydb.core.Flyway; | |
import javax.enterprise.context.ApplicationScoped; | |
import javax.enterprise.event.Observes; | |
@ApplicationScoped | |
public class MigrationHandler { | |
@ConfigProperty(name = "quarkus.flyway.migrate-at-start") | |
boolean runMigration; | |
@ConfigProperty(name = "quarkus.datasource.reactive.url") | |
String datasourceUrl; | |
@ConfigProperty(name = "quarkus.datasource.username") | |
String datasourceUsername; | |
@ConfigProperty(name = "quarkus.datasource.password") | |
String datasourcePassword; | |
public void runFlywayMigration(@Observes StartupEvent event) { | |
if (runMigration) { | |
Flyway flyway = Flyway.configure().dataSource( "jdbc:" +datasourceUrl.replace("vertx-reactive:", ""), datasourceUsername, datasourcePassword).load(); | |
flyway.migrate(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment