Skip to content

Commit b44d2f1

Browse files
committed
使用 Flyway Migration 统一数据库结构脚本(数据库版本控制)
1 parent 22e253c commit b44d2f1

File tree

6 files changed

+65
-31
lines changed

6 files changed

+65
-31
lines changed

README.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,33 @@
3030
> 3. 配置文件`application.properties`新增配置参数 GitHub.client 信息
3131
> 4. 使用 `MyBaits` 链接数据库并插入数据
3232
> 5. 实现持久化登录 服务器下发 user_token 并在数据库查询
33+
> 6. 集成 `Flyway Migration` 统一数据库结构脚本(数据库版本控制)
3334
>
3435
36+
```markdown
37+
Creating the first migration
38+
We create the migration directory `src/main/resources/db/migration`
39+
Followed by a first migration called `src/main/resources/db/migration/V1__Create_person_table.sql`
40+
```
3541
## 数据库脚本
3642

3743
```sql
3844
table For H2
3945
-- ----------------------------
4046
-- Table structure for User
4147
-- ----------------------------
42-
CREATE TABLE "PUBLIC"."USER"(
43-
44-
"ID" INT DEFAULT AUTO_INCREMENT PRIMARY KEY NOT NULL,
45-
"ACCOUNT_ID" VARCHAR,
46-
"NAME" VARCHAR(100),
47-
"TOKEN" CHAR(36),
48-
"GMT_CREATE" BIGINT,
49-
"GMT_MODIFIED" BIGINT
50-
)
48+
create table USER
49+
(
50+
ID INT auto_increment,
51+
ACCOUNT_ID VARCHAR,
52+
NAME VARCHAR(100),
53+
TOKEN CHAR(36),
54+
GMT_CREATE BIGINT,
55+
GMT_MODIFIED BIGINT,
56+
BIO VARCHAR(256),
57+
constraint TABLE_NAME_PK
58+
primary key (ID)
59+
);
5160

5261
```
5362

bash.exe.stackdump

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Stack trace:
2+
Frame Function Args
3+
000FFFFA1F8 001800617BE (0018025C578, 0018023DFBE, 000FFFFA1F8, 000FFFF9100)
4+
000FFFFA1F8 001800490FA (00000000000, 00000000000, 00000000000, 00000000000)
5+
000FFFFA1F8 00180049132 (0018025C629, 000FFFFA0B8, 000FFFFA1F8, 00000000000)
6+
000FFFFA1F8 001800B4BA5 (00000000000, 00000000000, 00000000000, 00000000000)
7+
000FFFFA1F8 001800B4CDD (000FFFFA210, 00000000000, 00000000000, 00000000000)
8+
000FFFFA4C0 001800B6351 (000FFFFA210, 00000000000, 00000000000, 00000000000)
9+
End of stack trace

pom.xml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<artifactId>spring-boot-starter-jdbc</artifactId>
3535
</dependency>
3636

37-
<!-- mybatis/ -->
37+
<!-- mybatis -->
3838
<dependency>
3939
<groupId>org.mybatis</groupId>
4040
<artifactId>mybatis</artifactId>
@@ -62,8 +62,8 @@
6262
<groupId>com.squareup.okhttp3</groupId>
6363
<artifactId>okhttp</artifactId>
6464
<version>3.14.4</version>
65-
<!-- 使用4.x版本会报错 -->
66-
<!-- <version>4.2.2</version> -->
65+
<!-- 使用4.x版本会报错 -->
66+
<!-- <version>4.2.2</version> -->
6767
</dependency>
6868
<dependency>
6969
<groupId>com.alibaba</groupId>
@@ -78,9 +78,6 @@
7878
<version>1.4.200</version>
7979
</dependency>
8080

81-
82-
83-
8481
</dependencies>
8582

8683
<build>
@@ -89,6 +86,26 @@
8986
<groupId>org.springframework.boot</groupId>
9087
<artifactId>spring-boot-maven-plugin</artifactId>
9188
</plugin>
89+
<plugin>
90+
<!-- flywaydb信息配置 -->
91+
<groupId>org.flywaydb</groupId>
92+
<artifactId>flyway-maven-plugin</artifactId>
93+
<version>6.3.1</version>
94+
<!-- flywaydb 数据库地址配置 -->
95+
<configuration>
96+
<url>jdbc:h2:~\SqlServerDB\community.db</url>
97+
<user>root</user>
98+
<password>123456</password>
99+
</configuration>
100+
<!-- flywaydb 数据库驱动配置 -->
101+
<dependencies>
102+
<dependency>
103+
<groupId>com.h2database</groupId>
104+
<artifactId>h2</artifactId>
105+
<version>1.4.200</version>
106+
</dependency>
107+
</dependencies>
108+
</plugin>
92109
</plugins>
93110
</build>
94111

src/main/java/life/majiang/community/model/User.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
11
package life.majiang.community.model;
22

3-
4-
/**
5-
* 数据库User表脚本
6-
create table USER
7-
(
8-
ID INT auto_increment,
9-
ACCOUNT_ID VARCHAR,
10-
NAME VARCHAR(100),
11-
TOKEN CHAR(36),
12-
GMT_CREATE BIGINT,
13-
GMT_MODIFIED BIGINT,
14-
constraint TABLE_NAME_PK
15-
primary key (ID)
16-
);
17-
*/
18-
193
public class User {
204
private Integer id; // 用户自增id
215
private String name; // username
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
create table USER
2+
(
3+
ID INT auto_increment,
4+
ACCOUNT_ID VARCHAR,
5+
NAME VARCHAR(100),
6+
TOKEN CHAR(36),
7+
GMT_CREATE BIGINT,
8+
GMT_MODIFIED BIGINT,
9+
constraint TABLE_NAME_PK
10+
primary key (ID)
11+
);
12+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
alter table USER
2+
add bio varchar(256) null;
3+

0 commit comments

Comments
 (0)