class FlywaySchemaInitializer implements SchemaInitializer {

  @Override
  public Map<String, String> init() throws SchemaInitializationException {
    final Map<String, String> initResult = new HashMap<>();
    try (final Connection conn = dataSource.getConnection()) {
      final Flyway flyway = new Flyway();
      flyway.setDataSource(dataSource);
      flyway.setLocations(locations);
      flyway.setClassLoader(Thread.currentThread().getContextClassLoader());
      final DbSupport dbSupport = DbSupportFactory.createDbSupport(conn, true);
      final MetaDataTable mt =
          new MetaDataTableImpl(
              dbSupport,
              dbSupport.getOriginalSchema().getTable(flyway.getTable()),
              flyway.getInstalledBy());
      initResult.put(BARE_DB_INIT_PROPERTY_NAME, String.valueOf(!mt.hasAppliedMigrations()));
      final String productName = conn.getMetaData().getDatabaseProductName().toLowerCase();
      flyway.setResolvers(
          new CustomSqlMigrationResolver(productName, dbSupport, placeholderReplacer));
      flyway.setSkipDefaultResolvers(true);
      flyway.setBaselineOnMigrate(baselineOnMigrate);
      if (baselineOnMigrate) {
        flyway.setBaselineVersionAsString(baselineVersion);
      }
      flyway.setSqlMigrationSeparator(versionSeparator);
      flyway.setSqlMigrationSuffix(scriptsSuffix);
      flyway.setSqlMigrationPrefix(scriptsPrefix);
      flyway.migrate();
    } catch (SQLException | RuntimeException x) {
      throw new SchemaInitializationException(x.getLocalizedMessage(), x);
    }
    return initResult;
  }

  @Inject public  FlywaySchemaInitializer(
      @Named("db.schema.flyway.scripts.locations") String[] scriptsLocations,
      @Named("db.schema.flyway.scripts.prefix") String scriptsPrefix,
      @Named("db.schema.flyway.scripts.suffix") String scriptsSuffix,
      @Named("db.schema.flyway.scripts.version_separator") String versionSeparator,
      @Named("db.schema.flyway.baseline.enabled") boolean baselineOnMigrate,
      @Named("db.schema.flyway.baseline.version") String baselineVersion,
      DataSource dataSource,
      PlaceholderReplacer placeholderReplacer);
  public  FlywaySchemaInitializer(DataSource dataSource, String... locations);

}