I have configured test containers using jdbc url and trying to use init function to run flyway. Is there any example were the following is achieved. I am struggling to fetch the datasource properties dynamically in init function
public class JDBCDriverTest {
public static void sampleInitFunction(Connection connection) throws SQLException {
Flyway flyway = Flyway.configure().dataSource("", "", "").load();
flyway.migrate();
}
}
I achieved it in following way
public class JDBCDriverTest {
public static void sampleInitFunction(Connection connection) throws SQLException {
Properties datasourceProperties = ((ConnectionImpl) connection).getProperties();
String user = datasourceProperties.getProperty("user");
String password = (String) datasourceProperties.get("password");
String url = ((ConnectionImpl) connection).getURL();
Flyway flyway = Flyway.configure().dataSource(url, user, password).load();
flyway.migrate();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With