From 4d6eecca726cbbe5848482c9d0504bf2e3ee5322 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Fri, 20 Oct 2023 17:57:15 +0800 Subject: [PATCH] Add auto create database table --- pom.xml | 11 +++++++++ src/main/resources/application.yml | 4 ++++ .../V1_0_0_231019__Add_table_'t_user'.sql | 19 +++++++++++++++ .../V1_0_0_231020__Add_table_'t_sys_log'.sql | 24 +++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 src/main/resources/db/migration/V1_0_0_231019__Add_table_'t_user'.sql create mode 100644 src/main/resources/db/migration/V1_0_0_231020__Add_table_'t_sys_log'.sql diff --git a/pom.xml b/pom.xml index abe9e27..9372dfc 100644 --- a/pom.xml +++ b/pom.xml @@ -64,6 +64,7 @@ 1.8.22 ${maven.build.timestamp} yyyy-MM-dd'T'HH:mm:ss + 9.22.3 @@ -158,6 +159,16 @@ com.fasterxml.jackson.datatype jackson-datatype-jsr310 + + org.flywaydb + flyway-core + ${flyway.version} + + + org.flywaydb + flyway-mysql + ${flyway.version} + diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 897ad44..7e4db33 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -11,6 +11,10 @@ spring: jackson: date-format: yyyy-MM-dd'T'HH:mm:ss.SSS'Z' time-zone: GMT + flyway: + baseline-on-migrate: true + baseline-version: 0 + clean-disabled: false mybatis-plus: global-config: diff --git a/src/main/resources/db/migration/V1_0_0_231019__Add_table_'t_user'.sql b/src/main/resources/db/migration/V1_0_0_231019__Add_table_'t_user'.sql new file mode 100644 index 0000000..659635e --- /dev/null +++ b/src/main/resources/db/migration/V1_0_0_231019__Add_table_'t_user'.sql @@ -0,0 +1,19 @@ +drop table if exists t_user; + +create table if not exists t_user +( + id bigint not null primary key, + username varchar(20) not null comment '用户名', + password char(70) not null comment '密码', + locking int not null comment '锁定', + expiration datetime comment '过期时间', + credentials_expiration datetime comment '认证过期时间', + enable int not null comment '启用', + last_login_time datetime comment '上次登录时间', + last_login_ip varchar(128) comment '上次登录 IP', + create_time datetime not null default (utc_timestamp()) comment '创建时间', + update_time datetime not null default (utc_timestamp()) comment '修改时间', + deleted bigint not null default 0, + version int not null default 0, + constraint t_user_unique unique (username, deleted) +) comment '用户表'; \ No newline at end of file diff --git a/src/main/resources/db/migration/V1_0_0_231020__Add_table_'t_sys_log'.sql b/src/main/resources/db/migration/V1_0_0_231020__Add_table_'t_sys_log'.sql new file mode 100644 index 0000000..01e04f1 --- /dev/null +++ b/src/main/resources/db/migration/V1_0_0_231020__Add_table_'t_sys_log'.sql @@ -0,0 +1,24 @@ +drop table if exists t_sys_log; +create table t_sys_log +( + id bigint not null, + log_type varchar(50) not null comment '日志类型', + operate_user_id bigint not null comment '操作用户', + operate_time datetime(3) not null default (utc_timestamp()) comment '操作时间', + request_uri varchar(500) default null comment '请求 URI', + request_method varchar(10) default null comment '请求方式', + request_params text comment '请求参数', + request_ip varchar(20) not null comment '请求 IP', + request_server_address varchar(50) not null comment '请求服务器地址', + is_exception char(1) default null comment '是否异常', + exception_info text comment '异常信息', + start_time datetime(3) not null comment '开始时间', + end_time datetime(3) not null comment '结束时间', + execute_time bigint default null comment '执行时间', + user_agent varchar(500) default null comment '用户代理', + primary key (id) using btree, + key idx_sys_log_log_type (log_type) using btree, + key idx_sys_log_operate_user_id (operate_user_id) using btree, + key idx_sys_log_is_exception (is_exception) using btree, + key idx_sys_log_operate_time (operate_time) using btree +) comment '系统日志表'; \ No newline at end of file