diff --git a/pom.xml b/pom.xml
index d8ca386..532d379 100644
--- a/pom.xml
+++ b/pom.xml
@@ -68,6 +68,7 @@
+ * 启动器 + *
+ * + * @author yangkai.shen + * @date Created in 2020/3/4 18:30 + */ +@SpringBootApplication +public class SpringBootDemoFlywayApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringBootDemoFlywayApplication.class, args); + } + +} diff --git a/spring-boot-demo-flyway/src/main/resources/application.yml b/spring-boot-demo-flyway/src/main/resources/application.yml new file mode 100644 index 0000000..7c32fe9 --- /dev/null +++ b/spring-boot-demo-flyway/src/main/resources/application.yml @@ -0,0 +1,14 @@ +spring: + flyway: + enabled: true + # 迁移前校验 SQL 文件是否存在问题 + validate-on-migrate: true + # 生产环境一定要关闭 + clean-disabled: true + # 校验路径下是否存在 SQL 文件 + check-location: false + datasource: + url: jdbc:mysql://127.0.0.1:3306/flyway-test?useSSL=false + username: root + password: root + type: com.zaxxer.hikari.HikariDataSource diff --git a/spring-boot-demo-flyway/src/main/resources/db/migration/V1_0__INIT.sql b/spring-boot-demo-flyway/src/main/resources/db/migration/V1_0__INIT.sql new file mode 100644 index 0000000..6d8cd6f --- /dev/null +++ b/spring-boot-demo-flyway/src/main/resources/db/migration/V1_0__INIT.sql @@ -0,0 +1,17 @@ +DROP TABLE IF EXISTS `t_user`; +CREATE TABLE `t_user` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键', + `username` varchar(32) NOT NULL COMMENT '用户名', + `password` varchar(32) NOT NULL COMMENT '加密后的密码', + `salt` varchar(32) NOT NULL COMMENT '加密使用的盐', + `email` varchar(32) NOT NULL COMMENT '邮箱', + `phone_number` varchar(15) NOT NULL COMMENT '手机号码', + `status` int(2) NOT NULL DEFAULT '1' COMMENT '状态,-1:逻辑删除,0:禁用,1:启用', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `last_login_time` datetime DEFAULT NULL COMMENT '上次登录时间', + `last_update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '上次更新时间', + PRIMARY KEY (`id`), + UNIQUE KEY `username` (`username`), + UNIQUE KEY `email` (`email`), + UNIQUE KEY `phone_number` (`phone_number`) +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COMMENT='1.0-用户表'; diff --git a/spring-boot-demo-flyway/src/main/resources/db/migration/V1_1__ALTER.sql b/spring-boot-demo-flyway/src/main/resources/db/migration/V1_1__ALTER.sql new file mode 100644 index 0000000..4cfbafb --- /dev/null +++ b/spring-boot-demo-flyway/src/main/resources/db/migration/V1_1__ALTER.sql @@ -0,0 +1 @@ +ALTER TABLE t_user COMMENT = '用户 v1.1'; \ No newline at end of file diff --git a/spring-boot-demo-flyway/src/test/java/com/xkcoding/AppTest.java b/spring-boot-demo-flyway/src/test/java/com/xkcoding/AppTest.java new file mode 100644 index 0000000..16a8ef2 --- /dev/null +++ b/spring-boot-demo-flyway/src/test/java/com/xkcoding/AppTest.java @@ -0,0 +1,20 @@ +package com.xkcoding; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +/** + * Unit test for simple App. + */ +public class AppTest +{ + /** + * Rigorous Test :-) + */ + @Test + public void shouldAnswerWithTrue() + { + assertTrue( true ); + } +}