feat: introduce flyway

This commit is contained in:
Irving
2025-04-26 21:16:31 -04:00
parent 1a2b6be001
commit 9d8293f327
8 changed files with 2108 additions and 36 deletions

View File

@@ -23,6 +23,11 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<!-- Flyway -->
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<!--通用模块--> <!--通用模块-->
<dependency> <dependency>
<groupId>com.starry</groupId> <groupId>com.starry</groupId>
@@ -102,7 +107,6 @@
<artifactId>okio</artifactId> <artifactId>okio</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.tencentcloudapi</groupId> <groupId>com.tencentcloudapi</groupId>
<artifactId>tencentcloud-sdk-java-dnspod</artifactId> <artifactId>tencentcloud-sdk-java-dnspod</artifactId>
@@ -146,6 +150,11 @@
</annotationProcessorPaths> </annotationProcessorPaths>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>7.15.0</version>
</plugin>
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>

View File

@@ -19,7 +19,4 @@ public class Application {
SpringApplication.run(Application.class, args); SpringApplication.run(Application.class, args);
} }
} }

View File

@@ -0,0 +1,20 @@
package com.starry.admin.common.conf;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import javax.sql.DataSource;
@Configuration
public class DataSourceConfig {
// For flyway only
@Bean(name = "primaryDataSource")
@Primary
public DataSource dataSource() {
return DruidDataSourceBuilder.create().build();
}
}

View File

@@ -18,8 +18,8 @@ public class OssProperties implements InitializingBean {
public static String BUCKET_NAME = ""; public static String BUCKET_NAME = "";
public String endpoint = "oss-cn-hangzhou.aliyuncs.com"; public String endpoint = "oss-cn-hangzhou.aliyuncs.com";
public String accessKeyId = "LTAI5t9ojt6uovFZokYZfJx5"; public String accessKeyId = "LTAI5t9ojt6uovFZokYZfJx5";
public String accessKeySecret = "xfCyNM5BQlAkoaa5NbcpoeipmCKZgf"; public String accessKeySecret = "";
public String bucketName = "live-cloud-cvoon"; public String bucketName = "live-cloudxfCyNM5BQlAkoaa5NbcpoeipmCKZgf-cvoon";
@Override @Override
public void afterPropertiesSet() { public void afterPropertiesSet() {

View File

@@ -1,7 +1,13 @@
# 服务名 # 服务名
spring: spring:
application: application:
name: admin-tenant name: ${SPRING_APPLICATION_NAME:admin-tenant}
flyway:
baseline-on-migrate: true
baseline-version: 1
enabled: true
locations: classpath:db/migration
# druid数据源配置 # druid数据源配置
datasource: datasource:
@@ -9,32 +15,32 @@ spring:
# 配置MySQL的驱动程序类 # 配置MySQL的驱动程序类
driver-class-name: com.p6spy.engine.spy.P6SpyDriver driver-class-name: com.p6spy.engine.spy.P6SpyDriver
# 数据库连接地址(以MySql为例) # 数据库连接地址(以MySql为例)
url: jdbc:p6spy:mysql://127.0.0.1:3306/play-with?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8 url: ${SPRING_DATASOURCE_URL:jdbc:p6spy:mysql://127.0.0.1:3306/play-with?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8}
# 数据库对应的用户名 # 数据库对应的用户名
username: root username: ${SPRING_DATASOURCE_USERNAME:root}
# 数据库对应的密码 # 数据库对应的密码
password: Spinfo0123 password: ${SPRING_DATASOURCE_PASSWORD:Spinfo0123}
druid: druid:
enable: true enable: true
db-type: mysql db-type: mysql
# 配置监控统计拦截的filtersstat是sql监控wall是防火墙(如果不添加则监控无效)添加log4j需要引入jar包 # 配置监控统计拦截的filtersstat是sql监控wall是防火墙(如果不添加则监控无效)添加log4j需要引入jar包
filters: stat,wall,config filters: stat,wall,config
# 连接池最大活跃连接数 # 连接池最大活跃连接数
max-active: 100 max-active: ${SPRING_DATASOURCE_DRUID_MAX_ACTIVE:100}
# 连接池初始化连接数量 # 连接池初始化连接数量
initial-size: 1 initial-size: ${SPRING_DATASOURCE_DRUID_INITIAL_SIZE:1}
# 配置获取连接等待超时的时间 # 配置获取连接等待超时的时间
max-wait: 60000 max-wait: ${SPRING_DATASOURCE_DRUID_MAX_WAIT:60000}
# 连接池最小空闲数 # 连接池最小空闲数
min-idle: 1 min-idle: ${SPRING_DATASOURCE_DRUID_MIN_IDLE:1}
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
timeBetweenEvictionRunsMillis: 60000 timeBetweenEvictionRunsMillis: ${SPRING_DATASOURCE_DRUID_TIME_BETWEEN_EVICTION_RUNS_MILLIS:60000}
# 配置一个连接在池中最小生存的时间,单位是毫秒 # 配置一个连接在池中最小生存的时间,单位是毫秒
minEvictableIdleTimeMillis: 300000 minEvictableIdleTimeMillis: ${SPRING_DATASOURCE_DRUID_MIN_EVICTABLE_IDLE_TIME_MILLIS:300000}
# 指定空闲连接检查、废弃连接清理、空闲连接池大小调整之间的操作时间间隔 # 指定空闲连接检查、废弃连接清理、空闲连接池大小调整之间的操作时间间隔
time-between-eviction-runs-millis: 60000 time-between-eviction-runs-millis: ${SPRING_DATASOURCE_DRUID_TIME_BETWEEN_EVICTION_RUNS_MILLIS:60000}
# 指定一个空闲连接最少空闲多久后可被清除 # 指定一个空闲连接最少空闲多久后可被清除
min-evictable-idle-time-millis: 300000 min-evictable-idle-time-millis: ${SPRING_DATASOURCE_DRUID_MIN_EVICTABLE_IDLE_TIME_MILLIS:300000}
# 连接是否有效的查询语句 # 连接是否有效的查询语句
validation-query: select 'x' validation-query: select 'x'
test-while-idle: true test-while-idle: true
@@ -42,11 +48,11 @@ spring:
test-on-return: false test-on-return: false
# 打开 PSCache并且指定每个连接上 PSCache 的大小 # 打开 PSCache并且指定每个连接上 PSCache 的大小
pool-prepared-statements: true pool-prepared-statements: true
max-open-prepared-statements: 50 max-open-prepared-statements: ${SPRING_DATASOURCE_DRUID_MAX_OPEN_PREPARED_STATEMENTS:50}
max-pool-prepared-statement-per-connection-size: 20 max-pool-prepared-statement-per-connection-size: ${SPRING_DATASOURCE_DRUID_MAX_POOL_PREPARED_STATEMENT_PER_CONNECTION_SIZE:20}
# 配置 DruidStatFilter # 配置 DruidStatFilter
web-stat-filter: web-stat-filter:
enabled: true #\u662F\u5426\u542F\u7528StatFilter\u9ED8\u8BA4\u503Ctrue enabled: true
# 排除一些不必要的url比如.js,/jslib/等 # 排除一些不必要的url比如.js,/jslib/等
exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
# 过滤规则 # 过滤规则
@@ -56,27 +62,25 @@ spring:
# 手动重置监控数据 # 手动重置监控数据
enabled: true enabled: true
# IP白名单没有配置或者为空则允许所有访问 # IP白名单没有配置或者为空则允许所有访问
allow: 127.0.0.1 allow: ${SPRING_DATASOURCE_DRUID_STAT_VIEW_SERVLET_ALLOW:127.0.0.1}
# IP黑名单若白名单也存在则优先使用 # IP黑名单若白名单也存在则优先使用
deny: deny:
# 配置druid登录用户名、密码 # 配置druid登录用户名、密码
login-username: admin login-username: ${SPRING_DATASOURCE_DRUID_STAT_VIEW_SERVLET_LOGIN_USERNAME:admin}
login-password: admin login-password: ${SPRING_DATASOURCE_DRUID_STAT_VIEW_SERVLET_LOGIN_PASSWORD:admin}
# HTML 中 Reset All 按钮 # HTML 中 Reset All 按钮
reset-enable: true reset-enable: true
redis: redis:
host: 127.0.0.1 # Redis服务器地址 host: ${SPRING_REDIS_HOST:127.0.0.1} # Redis服务器地址
database: 10 # Redis数据库索引默认为0 database: ${SPRING_REDIS_DATABASE:10} # Redis数据库索引默认为0
port: 6379 # Redis服务器连接端口 port: ${SPRING_REDIS_PORT:6379} # Redis服务器连接端口
password: Spinfo@0123 password: ${SPRING_REDIS_PASSWORD:Spinfo@0123}
timeout: 3000ms # 连接超时时间(毫秒) timeout: ${SPRING_REDIS_TIMEOUT:3000ms} # 连接超时时间(毫秒)
# 全局日志级别 # 全局日志级别
logging: logging:
level: level:
root: info root: ${LOGGING_LEVEL_ROOT:info}
jwt: jwt:
tokenHeader: X-Token #JWT存储的请求头 tokenHeader: X-Token #JWT存储的请求头
@@ -84,10 +88,20 @@ jwt:
secret: yz-admin-secret #JWT加解密使用的密钥 secret: yz-admin-secret #JWT加解密使用的密钥
expiration: 360000 #JWT的超期限时间秒(60*60*24) expiration: 360000 #JWT的超期限时间秒(60*60*24)
# token配置
token:
# 令牌自定义标识
header: Authorization
# 令牌密钥
secret: abcdefghijklmnopqrstuvwxyz
# 令牌有效期单位分钟默认30分钟
expireTime: 129600
# xl自定义配置 # xl自定义配置
xl: xl:
login: login:
authCode: authCode:
# 登录验证码是否开启开发环境配置false方便测试 # 登录验证码是否开启开发环境配置false方便测试
enable: false enable: ${XL_LOGIN_AUTHCODE_ENABLE:false}

File diff suppressed because it is too large Load Diff

10
pom.xml
View File

@@ -53,6 +53,8 @@
<ws-schild.version>3.1.1</ws-schild.version> <ws-schild.version>3.1.1</ws-schild.version>
<!-- Lombok --> <!-- Lombok -->
<lombok.version>1.18.30</lombok.version> <lombok.version>1.18.30</lombok.version>
<!-- Flyway -->
<flyway.version>7.15.0</flyway.version>
<!--腾讯云 COS 对象存储--> <!--腾讯云 COS 对象存储-->
<cos-version>5.6.205</cos-version> <cos-version>5.6.205</cos-version>
@@ -236,8 +238,12 @@
<version>1.7.2</version> <version>1.7.2</version>
</dependency> </dependency>
<!-- Flyway -->
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>${flyway.version}</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>

5
todo.md Normal file
View File

@@ -0,0 +1,5 @@
[] DB migration
[] Domain migration