topfans/backend/migrations/2026_06_08_010_statistic_partitions_initial.sql
zerosaturation f5ece5e1d2 feat(statistic): T3 service skeleton (config + main + healthz + metrics + 10 SQL)
- 6 config blocks (DB/Redis/Channel/Refresh/Partition/Extension with 4 EnableXxx=false)
- 14 Prometheus metric declarations
- self-impl healthz (/healthz + /metrics) — bypasses pkg/health to keep /metrics
- main.go startup: logger → config → DB → Redis → healthz HTTP :21009
- 10 SQL migrations: events partitioned + 4 MV + 3 pre-agg + refresh_log + 7-day initial

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-08 17:20:53 +08:00

22 lines
618 B
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- statistic 服务 events 表初始 7 天分区
-- 创建时间: 2026-06-08
-- 关联: spec §3.3 分区管理
-- 说明: 手动运行一次或由 partitioner worker 自动运行
-- worker/partitioner.go 实现,自动调度见 plan Task 8
DO $$
DECLARE
i INT;
d DATE;
n DATE;
BEGIN
FOR i IN 0..6 LOOP
d := CURRENT_DATE + i;
n := d + 1;
EXECUTE format(
'CREATE TABLE IF NOT EXISTS statistic.events_%s PARTITION OF statistic.events FOR VALUES FROM (%L) TO (%L)',
to_char(d, 'YYYY_MM_DD'), d::text, n::text
);
END LOOP;
END $$;