Skip to content

Commit f02ac79

Browse files
committed
✨ spring-boot-demo-flyway 完成
1 parent a682832 commit f02ac79

File tree

8 files changed

+168
-0
lines changed

8 files changed

+168
-0
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
<module>spring-boot-demo-ratelimit-redis</module>
6969
<module>spring-boot-demo-elasticsearch-rest-high-level-client</module>
7070
<module>spring-boot-demo-https</module>
71+
<module>spring-boot-demo-flyway</module>
7172
</modules>
7273
<packaging>pom</packaging>
7374

spring-boot-demo-flyway/.gitignore

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
HELP.md
2+
/target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
5+
### STS ###
6+
.apt_generated
7+
.classpath
8+
.factorypath
9+
.project
10+
.settings
11+
.springBeans
12+
.sts4-cache
13+
14+
### IntelliJ IDEA ###
15+
.idea
16+
*.iws
17+
*.iml
18+
*.ipr
19+
20+
### NetBeans ###
21+
/nbproject/private/
22+
/nbbuild/
23+
/dist/
24+
/nbdist/
25+
/.nb-gradle/
26+
/build/
27+
28+
### VS Code ###
29+
.vscode/

spring-boot-demo-flyway/pom.xml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<artifactId>spring-boot-demo-flyway</artifactId>
7+
<version>1.0.0-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>spring-boot-demo-flyway</name>
11+
<description>Demo project for Spring Boot</description>
12+
13+
<parent>
14+
<groupId>com.xkcoding</groupId>
15+
<artifactId>spring-boot-demo</artifactId>
16+
<version>1.0.0-SNAPSHOT</version>
17+
</parent>
18+
19+
<properties>
20+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
21+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
22+
<java.version>1.8</java.version>
23+
</properties>
24+
25+
<dependencies>
26+
<dependency>
27+
<groupId>org.springframework.boot</groupId>
28+
<artifactId>spring-boot-starter-web</artifactId>
29+
</dependency>
30+
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-test</artifactId>
34+
<scope>test</scope>
35+
</dependency>
36+
37+
<!-- 添加 flyway 的依赖 -->
38+
<dependency>
39+
<groupId>org.flywaydb</groupId>
40+
<artifactId>flyway-core</artifactId>
41+
</dependency>
42+
43+
<dependency>
44+
<groupId>org.springframework.boot</groupId>
45+
<artifactId>spring-boot-starter-data-jdbc</artifactId>
46+
</dependency>
47+
48+
<dependency>
49+
<groupId>mysql</groupId>
50+
<artifactId>mysql-connector-java</artifactId>
51+
<scope>runtime</scope>
52+
</dependency>
53+
</dependencies>
54+
55+
<build>
56+
<finalName>spring-boot-demo-flyway</finalName>
57+
<plugins>
58+
<plugin>
59+
<groupId>org.springframework.boot</groupId>
60+
<artifactId>spring-boot-maven-plugin</artifactId>
61+
</plugin>
62+
</plugins>
63+
</build>
64+
65+
</project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.xkcoding.flyway;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
/**
7+
* <p>
8+
* 启动器
9+
* </p>
10+
*
11+
* @author yangkai.shen
12+
* @date Created in 2020/3/4 18:30
13+
*/
14+
@SpringBootApplication
15+
public class SpringBootDemoFlywayApplication {
16+
17+
public static void main(String[] args) {
18+
SpringApplication.run(SpringBootDemoFlywayApplication.class, args);
19+
}
20+
21+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
spring:
2+
flyway:
3+
enabled: true
4+
# 迁移前校验 SQL 文件是否存在问题
5+
validate-on-migrate: true
6+
# 生产环境一定要关闭
7+
clean-disabled: true
8+
# 校验路径下是否存在 SQL 文件
9+
check-location: false
10+
datasource:
11+
url: jdbc:mysql://127.0.0.1:3306/flyway-test?useSSL=false
12+
username: root
13+
password: root
14+
type: com.zaxxer.hikari.HikariDataSource
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
DROP TABLE IF EXISTS `t_user`;
2+
CREATE TABLE `t_user` (
3+
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
4+
`username` varchar(32) NOT NULL COMMENT '用户名',
5+
`password` varchar(32) NOT NULL COMMENT '加密后的密码',
6+
`salt` varchar(32) NOT NULL COMMENT '加密使用的盐',
7+
`email` varchar(32) NOT NULL COMMENT '邮箱',
8+
`phone_number` varchar(15) NOT NULL COMMENT '手机号码',
9+
`status` int(2) NOT NULL DEFAULT '1' COMMENT '状态,-1:逻辑删除,0:禁用,1:启用',
10+
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
11+
`last_login_time` datetime DEFAULT NULL COMMENT '上次登录时间',
12+
`last_update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '上次更新时间',
13+
PRIMARY KEY (`id`),
14+
UNIQUE KEY `username` (`username`),
15+
UNIQUE KEY `email` (`email`),
16+
UNIQUE KEY `phone_number` (`phone_number`)
17+
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COMMENT='1.0-用户表';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE t_user COMMENT = '用户 v1.1';
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.xkcoding;
2+
3+
import static org.junit.Assert.assertTrue;
4+
5+
import org.junit.Test;
6+
7+
/**
8+
* Unit test for simple App.
9+
*/
10+
public class AppTest
11+
{
12+
/**
13+
* Rigorous Test :-)
14+
*/
15+
@Test
16+
public void shouldAnswerWithTrue()
17+
{
18+
assertTrue( true );
19+
}
20+
}

0 commit comments

Comments
 (0)