|
|
|
@ -40,11 +40,14 @@ import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfigurat
|
|
|
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
|
|
import org.springframework.boot.context.properties.ConfigurationPropertiesBinding;
|
|
|
|
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
|
|
|
import org.springframework.boot.jdbc.DatabaseDriver;
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
import org.springframework.core.convert.TypeDescriptor;
|
|
|
|
|
import org.springframework.core.convert.converter.GenericConverter;
|
|
|
|
|
import org.springframework.core.io.ResourceLoader;
|
|
|
|
|
import org.springframework.jdbc.support.JdbcUtils;
|
|
|
|
|
import org.springframework.jdbc.support.MetaDataAccessException;
|
|
|
|
|
import org.springframework.orm.jpa.AbstractEntityManagerFactoryBean;
|
|
|
|
|
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
|
|
|
|
import org.springframework.util.Assert;
|
|
|
|
@ -126,7 +129,7 @@ public class FlywayAutoConfiguration {
|
|
|
|
|
@Bean
|
|
|
|
|
@ConfigurationProperties(prefix = "flyway")
|
|
|
|
|
public Flyway flyway() {
|
|
|
|
|
Flyway flyway = new Flyway();
|
|
|
|
|
Flyway flyway = new SpringBootFlyway();
|
|
|
|
|
if (this.properties.isCreateDataSource()) {
|
|
|
|
|
flyway.setDataSource(this.properties.getUrl(), this.properties.getUser(),
|
|
|
|
|
this.properties.getPassword(),
|
|
|
|
@ -182,6 +185,45 @@ public class FlywayAutoConfiguration {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class SpringBootFlyway extends Flyway {
|
|
|
|
|
|
|
|
|
|
private static final String VENDOR_PLACEHOLDER = "{vendor}";
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setLocations(String... locations) {
|
|
|
|
|
if (usesVendorLocation(locations)) {
|
|
|
|
|
try {
|
|
|
|
|
String url = (String) JdbcUtils.extractDatabaseMetaData(
|
|
|
|
|
getDataSource(), "getURL");
|
|
|
|
|
DatabaseDriver vendor = DatabaseDriver.fromJdbcUrl(url);
|
|
|
|
|
if (vendor != DatabaseDriver.UNKNOWN) {
|
|
|
|
|
for (int i = 0; i < locations.length; i++) {
|
|
|
|
|
locations[i] = locations[i].replace(
|
|
|
|
|
VENDOR_PLACEHOLDER,
|
|
|
|
|
vendor.getId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (MetaDataAccessException ex) {
|
|
|
|
|
throw new IllegalStateException(ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
super.setLocations(locations);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean usesVendorLocation(String... locations) {
|
|
|
|
|
for (String location : locations) {
|
|
|
|
|
if (location.contains(VENDOR_PLACEHOLDER)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert a String or Number to a {@link MigrationVersion}.
|
|
|
|
|
*/
|
|
|
|
|