com.github.zhengframework.jdbc.migrate.FlywayMigrateModule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zheng-migrate-flyway Show documentation
Show all versions of zheng-migrate-flyway Show documentation
zheng framework module: database migrate support by flyway
package com.github.zhengframework.jdbc.migrate;
import static com.google.inject.name.Names.named;
import com.github.zhengframework.configuration.ConfigurationAwareModule;
import com.github.zhengframework.configuration.ConfigurationBeanMapper;
import com.github.zhengframework.jdbc.ManagedSchema;
import com.google.inject.Key;
import com.google.inject.multibindings.OptionalBinder;
import java.util.Map;
import java.util.Map.Entry;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = false)
public class FlywayMigrateModule extends ConfigurationAwareModule {
@Override
protected void configure() {
Map flywayConfigMap = ConfigurationBeanMapper
.resolve(getConfiguration(), FlywayConfig.class);
for (Entry entry : flywayConfigMap.entrySet()) {
String name = entry.getKey();
FlywayConfig flywayConfig = entry.getValue();
if (name.isEmpty()) {
bind(FlywayConfig.class).toInstance(flywayConfig);
OptionalBinder.newOptionalBinder(binder(), Key.get(ManagedSchema.class))
.setBinding().toInstance(new FlywayManagedSchema(flywayConfig));
} else {
bind(Key.get(FlywayConfig.class, named(name))).toInstance(flywayConfig);
OptionalBinder.newOptionalBinder(binder(), Key.get(ManagedSchema.class, named(name)))
.setBinding().toInstance(new FlywayManagedSchema(flywayConfig));
}
}
}
}