From f02ac795daf32a072a6fc8117a51b9a376471da9 Mon Sep 17 00:00:00 2001 From: "Yangkai.Shen" <237497819@qq.com> Date: Thu, 5 Mar 2020 11:03:20 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20spring-boot-demo-flyway=20?= =?UTF-8?q?=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 1 + spring-boot-demo-flyway/.gitignore | 29 +++++++++ spring-boot-demo-flyway/pom.xml | 65 +++++++++++++++++++ .../SpringBootDemoFlywayApplication.java | 21 ++++++ .../src/main/resources/application.yml | 14 ++++ .../resources/db/migration/V1_0__INIT.sql | 17 +++++ .../resources/db/migration/V1_1__ALTER.sql | 1 + .../src/test/java/com/xkcoding/AppTest.java | 20 ++++++ 8 files changed, 168 insertions(+) create mode 100644 spring-boot-demo-flyway/.gitignore create mode 100644 spring-boot-demo-flyway/pom.xml create mode 100644 spring-boot-demo-flyway/src/main/java/com/xkcoding/flyway/SpringBootDemoFlywayApplication.java create mode 100644 spring-boot-demo-flyway/src/main/resources/application.yml create mode 100644 spring-boot-demo-flyway/src/main/resources/db/migration/V1_0__INIT.sql create mode 100644 spring-boot-demo-flyway/src/main/resources/db/migration/V1_1__ALTER.sql create mode 100644 spring-boot-demo-flyway/src/test/java/com/xkcoding/AppTest.java diff --git a/pom.xml b/pom.xml index d8ca386a0..532d379df 100644 --- a/pom.xml +++ b/pom.xml @@ -68,6 +68,7 @@ spring-boot-demo-ratelimit-redis spring-boot-demo-elasticsearch-rest-high-level-client spring-boot-demo-https + spring-boot-demo-flyway pom diff --git a/spring-boot-demo-flyway/.gitignore b/spring-boot-demo-flyway/.gitignore new file mode 100644 index 000000000..153c9335e --- /dev/null +++ b/spring-boot-demo-flyway/.gitignore @@ -0,0 +1,29 @@ +HELP.md +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +/build/ + +### VS Code ### +.vscode/ diff --git a/spring-boot-demo-flyway/pom.xml b/spring-boot-demo-flyway/pom.xml new file mode 100644 index 000000000..802f67b1b --- /dev/null +++ b/spring-boot-demo-flyway/pom.xml @@ -0,0 +1,65 @@ + + + 4.0.0 + + spring-boot-demo-flyway + 1.0.0-SNAPSHOT + jar + + spring-boot-demo-flyway + Demo project for Spring Boot + + + com.xkcoding + spring-boot-demo + 1.0.0-SNAPSHOT + + + + UTF-8 + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.flywaydb + flyway-core + + + + org.springframework.boot + spring-boot-starter-data-jdbc + + + + mysql + mysql-connector-java + runtime + + + + + spring-boot-demo-flyway + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/spring-boot-demo-flyway/src/main/java/com/xkcoding/flyway/SpringBootDemoFlywayApplication.java b/spring-boot-demo-flyway/src/main/java/com/xkcoding/flyway/SpringBootDemoFlywayApplication.java new file mode 100644 index 000000000..7a300bc45 --- /dev/null +++ b/spring-boot-demo-flyway/src/main/java/com/xkcoding/flyway/SpringBootDemoFlywayApplication.java @@ -0,0 +1,21 @@ +package com.xkcoding.flyway; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + *

+ * 启动器 + *

+ * + * @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 000000000..7c32fe96b --- /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 000000000..6d8cd6fc9 --- /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 000000000..4cfbafb69 --- /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 000000000..16a8ef2c9 --- /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 ); + } +}