定义model
This commit is contained in:
@@ -165,11 +165,13 @@ func (ps *PostgresStorage) creatingHyperTable() error {
|
||||
{models.FeedUsageRecord{}, "recorded_at"},
|
||||
{models.GroupMedicationLog{}, "happened_at"},
|
||||
{models.PigBatchLog{}, "happened_at"},
|
||||
{models.WeighingBatch{}, "weighing_time"},
|
||||
{models.WeighingRecord{}, "weighing_time"},
|
||||
}
|
||||
|
||||
for _, table := range tablesToConvert {
|
||||
tableName := table.model.TableName()
|
||||
chunkInterval := "7 days" // 统一设置为7天
|
||||
chunkInterval := "1 days" // 统一设置为1天
|
||||
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 {
|
||||
@@ -194,11 +196,18 @@ func (ps *PostgresStorage) applyCompressionPolicies() error {
|
||||
{models.TaskExecutionLog{}, "task_id"},
|
||||
{models.PendingCollection{}, "device_id"},
|
||||
{models.UserActionLog{}, "user_id"},
|
||||
{models.RawMaterialPurchase{}, "raw_material_id"},
|
||||
{models.RawMaterialStockLog{}, "raw_material_id"},
|
||||
{models.FeedUsageRecord{}, "pen_id"},
|
||||
{models.GroupMedicationLog{}, "pig_batch_id"},
|
||||
{models.PigBatchLog{}, "pig_batch_id"},
|
||||
{models.WeighingBatch{}, "pig_batch_id"},
|
||||
{models.WeighingRecord{}, "weighing_batch_id"},
|
||||
}
|
||||
|
||||
for _, policy := range policies {
|
||||
tableName := policy.model.TableName()
|
||||
compressAfter := "15 days" // 统一设置为15天后开始压缩
|
||||
compressAfter := "3 days" // 统一设置为2天后(即进入第3天)开始压缩
|
||||
|
||||
// 1. 开启表的压缩设置,并指定分段列
|
||||
ps.logger.Infow("为表启用压缩设置", "table", tableName, "segment_by", policy.segmentColumn)
|
||||
|
||||
Reference in New Issue
Block a user