Skip to content

Commit

Permalink
✨ spring-boot-demo-flyway 完成
Browse files Browse the repository at this point in the history
  • Loading branch information
xkcoding committed Mar 5, 2020
1 parent a682832 commit f02ac79
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 0 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<module>spring-boot-demo-ratelimit-redis</module>
<module>spring-boot-demo-elasticsearch-rest-high-level-client</module>
<module>spring-boot-demo-https</module>
<module>spring-boot-demo-flyway</module>
</modules>
<packaging>pom</packaging>

Expand Down
29 changes: 29 additions & 0 deletions spring-boot-demo-flyway/.gitignore
Original file line number Diff line number Diff line change
@@ -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/
65 changes: 65 additions & 0 deletions spring-boot-demo-flyway/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-boot-demo-flyway</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>spring-boot-demo-flyway</name>
<description>Demo project for Spring Boot</description>

<parent>
<groupId>com.xkcoding</groupId>
<artifactId>spring-boot-demo</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<!-- 添加 flyway 的依赖 -->
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>

<build>
<finalName>spring-boot-demo-flyway</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.xkcoding.flyway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* <p>
* 启动器
* </p>
*
* @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);
}

}
14 changes: 14 additions & 0 deletions spring-boot-demo-flyway/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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-用户表';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE t_user COMMENT = '用户 v1.1';
20 changes: 20 additions & 0 deletions spring-boot-demo-flyway/src/test/java/com/xkcoding/AppTest.java
Original file line number Diff line number Diff line change
@@ -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 );
}
}

0 comments on commit f02ac79

Please sign in to comment.