Hack to force Flyway to initialize early

pull/896/merge
Dave Syer 11 years ago
parent 341ca38d56
commit 2cc5bdfa09

@ -20,7 +20,9 @@ import javax.annotation.PostConstruct;
import javax.sql.DataSource;
import org.flywaydb.core.Flyway;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
@ -31,6 +33,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
@ -52,7 +55,7 @@ public class FlywayAutoConfiguration {
@Configuration
@ConditionalOnMissingBean(Flyway.class)
@EnableConfigurationProperties(FlywayProperties.class)
public static class LiquibaseConfiguration {
public static class FlywayConfiguration {
@Autowired
private FlywayProperties properties = new FlywayProperties();
@ -93,6 +96,26 @@ public class FlywayAutoConfiguration {
return flyway;
}
@Bean
@DependsOn("flyway")
protected BeanPostProcessor forceFlywayToInitialize() {
return new BeanPostProcessor() {
@Override
public Object postProcessAfterInitialization(Object bean, String beanName)
throws BeansException {
return bean;
}
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName)
throws BeansException {
return bean;
}
};
}
}
}

@ -1,2 +1,2 @@
spring.jpa.generate-ddl: false
spring.jpa.hibernate.ddl-auto: none
spring.jpa.hibernate.ddl-auto: validate

@ -1,5 +1,5 @@
CREATE TABLE PERSON (
id INTEGER GENERATED BY DEFAULT AS IDENTITY,
id BIGINT GENERATED BY DEFAULT AS IDENTITY,
first_name varchar(255) not null,
last_name varchar(255) not null
);

Loading…
Cancel
Save