From f658ac26df3eb996c41cd6846582ea0673276257 Mon Sep 17 00:00:00 2001 From: Tang Cheng Date: Wed, 24 Apr 2019 15:29:01 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=20flyway=20=E8=BF=9B?= =?utf8?q?=E8=A1=8C=E6=95=B0=E6=8D=AE=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/supwisdom/dlpay/migration.kt | 32 +++++++++++++++++++ src/main/resources/application.properties | 4 +-- ...V1_0-init_data.sql => V1.0__init_data.sql} | 12 +++---- 3 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 src/main/kotlin/com/supwisdom/dlpay/migration.kt rename src/main/resources/db/migration/{V1_0-init_data.sql => V1.0__init_data.sql} (63%) diff --git a/src/main/kotlin/com/supwisdom/dlpay/migration.kt b/src/main/kotlin/com/supwisdom/dlpay/migration.kt new file mode 100644 index 00000000..5495bca3 --- /dev/null +++ b/src/main/kotlin/com/supwisdom/dlpay/migration.kt @@ -0,0 +1,32 @@ +package com.supwisdom.dlpay + +import org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer +import org.flywaydb.core.Flyway +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.DependsOn + + +@Configuration +class MigrationConfiguration { + + /** + * Override default flyway initializer to do nothing + */ + @Bean + fun flywayInitializer(flyway: Flyway): FlywayMigrationInitializer { + return FlywayMigrationInitializer(flyway) { f -> } + } + + + /** + * Create a second flyway initializer to run after jpa has created the schema + */ + @Bean + @DependsOn("entityManagerFactory") + fun delayedFlywayInitializer(flyway: Flyway): FlywayMigrationInitializer { + return FlywayMigrationInitializer(flyway, null) + } + + +} \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index afe6400d..db534baf 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -3,11 +3,11 @@ spring.jpa.show-sql=true spring.datasource.hikari.connection-timeout=60000 spring.datasource.hikari.maximum-pool-size=5 -spring.datasource.initialization-mode=always -spring.datasource.continue-on-error=true spring.jpa.hibernate.ddl-auto=update spring.flyway.locations=classpath:db/migration +spring.flyway.baseline-version=0 +spring.flyway.baseline-on-migrate=true # logging logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n logging.level.org.hibernate.SQL=debug diff --git a/src/main/resources/db/migration/V1_0-init_data.sql b/src/main/resources/db/migration/V1.0__init_data.sql similarity index 63% rename from src/main/resources/db/migration/V1_0-init_data.sql rename to src/main/resources/db/migration/V1.0__init_data.sql index 0b14207b..a28028b6 100644 --- a/src/main/resources/db/migration/V1_0-init_data.sql +++ b/src/main/resources/db/migration/V1.0__init_data.sql @@ -5,18 +5,18 @@ INSERT INTO tb_operator( VALUES ('LOR2IwRkbOjp+sVG9KR2BpHZbwGKepS4', '20500101', '20190101', 'system', '系统管理员', '$2a$10$Ex9xp11.vCaD8D0a7ahiUOKqDij1TcCUBwRAmrqXeDvAkmzLibn4.', '', 'normal'); INSERT INTO tb_role( - role_id, createtime, editflag, lastsaved, rolecode, roledesc, rolename) + roleid, createtime, editflag, lastsaved, rolecode, roledesc, rolename) VALUES ('d1yctWs5+ks0iQN3m9bUvRHus6HbKbrs', '20190101000000', 0, '', 'ROLE_ADMIN', '超级管理员', '超级管理员'); INSERT INTO tb_oper_role( - id, operid, role_id) + id, operid, roleid) VALUES ('1', 'LOR2IwRkbOjp+sVG9KR2BpHZbwGKepS4', 'd1yctWs5+ks0iQN3m9bUvRHus6HbKbrs'); -- 功能表 -Insert into TB_FUNCTION (ID,PARENT_ID,NAME,ORDER_NUM,MENU_URL,MENU_ICON,IS_LEAF) +Insert into TB_FUNCTION (ID,PARENTID,NAME,ORDERNUM,MENUURL,MENUICON,ISLEAF) values ('1','-1','系统中心',1,'#','layui-icon-set',0); -Insert into TB_FUNCTION (ID,PARENT_ID,NAME,ORDER_NUM,MENU_URL,MENU_ICON,IS_LEAF) +Insert into TB_FUNCTION (ID,PARENTID,NAME,ORDERNUM,MENUURL,MENUICON,ISLEAF) values ('2','1','管理员维护',1,'#','layui-icon-set',1); -Insert into TB_ROLE_FUNCTION (ID,FUNCTION_ID,ROLE_ID) values ('1','1','d1yctWs5+ks0iQN3m9bUvRHus6HbKbrs'); -Insert into TB_ROLE_FUNCTION (ID,FUNCTION_ID,ROLE_ID) values ('2','2','d1yctWs5+ks0iQN3m9bUvRHus6HbKbrs'); \ No newline at end of file +Insert into TB_ROLE_FUNCTION (ID,FUNCTIONID,ROLEID) values ('1','1','d1yctWs5+ks0iQN3m9bUvRHus6HbKbrs'); +Insert into TB_ROLE_FUNCTION (ID,FUNCTIONID,ROLEID) values ('2','2','d1yctWs5+ks0iQN3m9bUvRHus6HbKbrs'); \ No newline at end of file -- 2.17.1