实现 猪舍相关路由组 和 猪圈相关路由组

This commit is contained in:
2025-10-03 18:27:53 +08:00
parent 5754a1d94c
commit 8cbe313c89
13 changed files with 840 additions and 47 deletions

View File

@@ -160,11 +160,16 @@ func (ps *PostgresStorage) creatingHyperTable() error {
{models.TaskExecutionLog{}, "created_at"},
{models.PendingCollection{}, "created_at"},
{models.UserActionLog{}, "time"},
{models.RawMaterialPurchase{}, "purchase_date"},
{models.RawMaterialStockLog{}, "happened_at"},
{models.FeedUsageRecord{}, "recorded_at"},
{models.GroupMedicationLog{}, "happened_at"},
{models.PigBatchLog{}, "happened_at"},
}
for _, table := range tablesToConvert {
tableName := table.model.TableName()
chunkInterval := "1 day" // 统一设置为1
chunkInterval := "7 days" // 统一设置为7
ps.logger.Infow("准备将表转换为超表", "table", tableName, "chunk_interval", chunkInterval)
sql := fmt.Sprintf("SELECT create_hypertable('%s', '%s', chunk_time_interval => INTERVAL '%s', if_not_exists => TRUE);", tableName, table.timeColumn, chunkInterval)
if err := ps.db.Exec(sql).Error; err != nil {
@@ -193,7 +198,7 @@ func (ps *PostgresStorage) applyCompressionPolicies() error {
for _, policy := range policies {
tableName := policy.model.TableName()
compressAfter := "3 days" // 统一设置为2天后即进入第3天开始压缩
compressAfter := "15 days" // 统一设置为15天后开始压缩
// 1. 开启表的压缩设置,并指定分段列
ps.logger.Infow("为表启用压缩设置", "table", tableName, "segment_by", policy.segmentColumn)
@@ -239,14 +244,5 @@ func (ps *PostgresStorage) creatingIndex() error {
}
ps.logger.Info("成功为 tasks 的 parameters 字段创建 GIN 索引 (或已存在)")
// 为 devices 表的 properties 字段创建 GIN 索引
//ps.logger.Info("正在为 devices 表的 properties 字段创建 GIN 索引")
//ginDevicePropertiesIndexSQL := "CREATE INDEX IF NOT EXISTS idx_devices_properties_gin ON devices USING GIN (properties);"
//if err := ps.db.Exec(ginDevicePropertiesIndexSQL).Error; err != nil {
// ps.logger.Errorw("为 devices 的 properties 字段创建 GIN 索引失败", "error", err)
// return fmt.Errorf("为 devices 的 properties 字段创建 GIN 索引失败: %w", err)
//}
//ps.logger.Info("成功为 devices 的 properties 字段创建 GIN 索引 (或已存在)")
return nil
}