mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
flyway 在hibernate之后运行
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<project version="4">
|
||||
<component name="PersistenceUnitSettings">
|
||||
<persistence-units>
|
||||
<persistence-unit name="Default">
|
||||
<persistence-unit moduleName="coal" name="Default">
|
||||
<packages>
|
||||
<package value="cn.lihongjie.coal" />
|
||||
</packages>
|
||||
|
||||
@@ -9,6 +9,7 @@ import cn.lihongjie.coal.session.SessionService;
|
||||
import cn.lihongjie.coal.user.entity.UserEntity;
|
||||
import cn.lihongjie.coal.user.service.UserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.flywaydb.core.Flyway;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.security.core.context.SecurityContext;
|
||||
@@ -33,6 +34,9 @@ public class InitDataRunner implements CommandLineRunner {
|
||||
@Autowired
|
||||
ResourceService resourceService;
|
||||
|
||||
@Autowired
|
||||
Flyway flyway;
|
||||
|
||||
|
||||
@Autowired
|
||||
DictionaryService dictionaryService;
|
||||
@@ -40,6 +44,8 @@ public class InitDataRunner implements CommandLineRunner {
|
||||
@Transactional
|
||||
public void run(String... args) throws Exception {
|
||||
|
||||
flyway.migrate();
|
||||
|
||||
|
||||
OrganizationEntity e = organizationService.initOrGetAdminOrg();
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.lihongjie.coal.spring.config;
|
||||
|
||||
import org.flywaydb.core.Flyway;
|
||||
import org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class FlywayConfig {
|
||||
|
||||
|
||||
/**
|
||||
* Override default flyway initializer to do nothing
|
||||
*/
|
||||
@Bean
|
||||
FlywayMigrationInitializer flywayInitializer(Flyway flyway) {
|
||||
return new FlywayMigrationInitializer(flyway, (f) ->{} );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
1
src/main/resources/db/migration/V2__test.sql
Normal file
1
src/main/resources/db/migration/V2__test.sql
Normal file
@@ -0,0 +1 @@
|
||||
select 1;
|
||||
Reference in New Issue
Block a user