Revert deferred DDL changes and re-oreder database migrations
Schema initialization now happens in @PostConstruct (effectively) whether it is via the Hibernate EntityManagerFactory or the Boot DataSourceInitialization (in addition or instead). The data.sql script if it exists is still executed on an event fired from the other places, so those tests are passing. Flyway and liquibase have bean factory post processors (like the one they use to order the audit aspect in Spring Data) that enforce a dependency on those components from the EntityManagerFactory. So Hibernate validation is still happy (and there are 2 tests to prove it now as well). Fixes gh-1022pull/1031/head
parent
f7d1aab9f3
commit
74166e770a
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.orm.jpa;
|
||||
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceInitialization.DataSourceInitializedEvent;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
public class DataSourceInitializedPublisher implements BeanPostProcessor {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
private DataSource dataSource;
|
||||
|
||||
@Override
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName)
|
||||
throws BeansException {
|
||||
return bean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName)
|
||||
throws BeansException {
|
||||
if (bean instanceof DataSource) {
|
||||
// Normally this will be the right DataSource
|
||||
this.dataSource = (DataSource) bean;
|
||||
}
|
||||
if (bean instanceof EntityManagerFactory && this.dataSource != null) {
|
||||
this.applicationContext.publishEvent(new DataSourceInitializedEvent(
|
||||
this.dataSource));
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
databaseChangeLog:
|
||||
- changeSet:
|
||||
id: 1
|
||||
author: dsyer
|
||||
changes:
|
||||
- createTable:
|
||||
tableName: city
|
||||
columns:
|
||||
- column:
|
||||
name: id
|
||||
type: bigint
|
||||
autoIncrement: true
|
||||
constraints:
|
||||
primaryKey: true
|
||||
nullable: false
|
||||
- column:
|
||||
name: name
|
||||
type: varchar(50)
|
||||
constraints:
|
||||
nullable: false
|
||||
- column:
|
||||
name: state
|
||||
type: varchar(50)
|
||||
constraints:
|
||||
nullable: false
|
||||
- column:
|
||||
name: country
|
||||
type: varchar(50)
|
||||
constraints:
|
||||
nullable: false
|
||||
- column:
|
||||
name: map
|
||||
type: varchar(50)
|
||||
constraints:
|
||||
nullable: true
|
||||
|
@ -0,0 +1,7 @@
|
||||
CREATE TABLE CITY (
|
||||
id BIGINT GENERATED BY DEFAULT AS IDENTITY,
|
||||
name VARCHAR(30),
|
||||
state VARCHAR(30),
|
||||
country VARCHAR(30),
|
||||
map VARCHAR(30)
|
||||
);
|
Loading…
Reference in New Issue