feat: 启用数据库初始化与分区维护功能,更新配置以支持动态控制
This commit is contained in:
@@ -69,4 +69,7 @@ PROCESSOR_BATCH_TIMEOUT=5000
|
||||
|
||||
# 日志配置
|
||||
LOG_LEVEL=info
|
||||
LOG_FORMAT=json
|
||||
LOG_FORMAT=json
|
||||
|
||||
|
||||
DB_INIT_AND_PARTITION_ENABLED=false
|
||||
@@ -53,6 +53,9 @@ export default {
|
||||
retryAttempts: 3, // 重试次数
|
||||
retryDelay: 1000, // 重试延迟
|
||||
|
||||
// 是否启用数据库初始化与分区维护(若为 false,跳过建表、分区预创建、定时分区检查)
|
||||
initAndPartitionEnabled: (env.DB_INIT_AND_PARTITION_ENABLED ?? 'true') === 'true',
|
||||
|
||||
// 分区维护(方案1):启动时预创建 + 周期维护
|
||||
partitionMaintenance: {
|
||||
enabled: true,
|
||||
|
||||
@@ -37,15 +37,20 @@ class DatabaseManager {
|
||||
client.release();
|
||||
console.log('数据库连接池创建成功');
|
||||
|
||||
// 初始化表结构
|
||||
await this.initTables();
|
||||
// 根据配置决定是否执行初始化与分区维护
|
||||
if (this.config.initAndPartitionEnabled !== false) {
|
||||
// 初始化表结构
|
||||
await this.initTables();
|
||||
|
||||
// 分区维护(方案1):启动时预创建 + 定时维护
|
||||
await this.ensurePartitionsForRange({
|
||||
startDayOffset: -1,
|
||||
endDayOffset: this.getPartitionFutureDays(),
|
||||
});
|
||||
this.startPartitionMaintenance();
|
||||
// 分区维护(方案1):启动时预创建 + 定时维护
|
||||
await this.ensurePartitionsForRange({
|
||||
startDayOffset: -1,
|
||||
endDayOffset: this.getPartitionFutureDays(),
|
||||
});
|
||||
this.startPartitionMaintenance();
|
||||
} else {
|
||||
console.log('[db] 已禁用数据库初始化与分区维护(DB_INIT_AND_PARTITION_ENABLED=false),跳过建表、分区预创建、定时维护');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('数据库连接失败:', error);
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user