fix: 优化数据库连接配置和超时设置

- 禁用云函数环境下的自动迁移
- 增加连接超时和重试机制配置
- 优化连接池参数设置
- 提升数据库连接稳定性和性能
This commit is contained in:
imeepos 2025-09-26 15:29:52 +08:00
parent 489756b7a0
commit 54a1bf141b
1 changed files with 13 additions and 1 deletions

View File

@ -20,7 +20,19 @@ export const databaseConfig = (
'DB_LOGGING', 'DB_LOGGING',
process.env.NODE_ENV === 'development', process.env.NODE_ENV === 'development',
), ),
migrationsRun: configService.get<boolean>('DB_MIGRATIONS_RUN', true), // 自动运行迁移 migrationsRun: configService.get<boolean>('DB_MIGRATIONS_RUN', false), // 云函数环境禁用自动迁移
charset: 'utf8mb4', charset: 'utf8mb4',
timezone: '+08:00', timezone: '+08:00',
// 添加连接超时和重试配置
connectTimeout: 60000, // 60秒连接超时
acquireTimeout: 60000, // 60秒获取连接超时
retryAttempts: 3, // 重试3次
retryDelay: 3000, // 重试间隔3秒
// 连接池配置
extra: {
connectionLimit: 10,
idleTimeout: 30000,
acquireTimeout: 60000,
timeout: 60000, // 60秒查询超时
},
}); });