-- 指标聚合表唯一约束:GORM 的 ON CONFLICT upsert 需要唯一索引才能真正生效。 // Logan.Li DELETE FROM monitor_metric_aggregates a USING monitor_metric_aggregates b WHERE a.hostname = b.hostname AND a.metric = b.metric AND a.interval = b.interval AND a.bucket_time = b.bucket_time AND a.id < b.id; CREATE UNIQUE INDEX IF NOT EXISTS uniq_metric_agg ON monitor_metric_aggregates (hostname, metric, interval, bucket_time);