4

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();
    }
}

1 Answers1

1

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();
   }
}