fix(db): TypeORM 压缩配置对齐 SQL DDL,新增 TimescaleDB 初始化脚本

- kline.entity.ts: compress_segmentby 移除 interval(基表固定 1m 无需分段),schedule_interval 365d→30d 与 init-db SQL 一致
- data-source.ts: 生产环境关闭 synchronize,以 init-db SQL 脚本为建表唯一来源
- 新增 data/db/init-db/ 初始化 SQL 链:
  01-timescaledb.sql — 启用 TimescaleDB 扩展
  02-init-tables.sql — 核心业务表 + klines hypertable(7d chunk / 30d 压缩)
  03-continuous-aggregates.sql — 分层连续聚合视图(5m→15m→30m→1h→4h→1d→1w)
This commit is contained in:
Rekey
2026-06-10 20:03:00 +08:00
parent 805a23f72e
commit 309b11ae30
5 changed files with 655 additions and 4 deletions
+3 -3
View File
@@ -7,7 +7,7 @@
//
// 关键 TimescaleDB 特性(由 @Hypertable 装饰器自动配置):
// - 自动按 time 列做时间分区(by_range
// - 列式压缩(compress),7 天后自动执行
// - 列式压缩(compress),30 天后自动执行
// - 通过 ContinuousAggregate 生成高周期 K 线视图
//
// 注意:@timescaledb/typeorm v0.0.1 为实验版本,
@@ -40,9 +40,9 @@ import type { KlineInterval } from '../../types';
compression: {
compress: true,
compress_orderby: "time DESC",
compress_segmentby: "exchange, symbol, interval",
compress_segmentby: "exchange, symbol",
policy: {
schedule_interval: "365 days", // 365 天后自动压缩
schedule_interval: "30 days", // 30 天后自动压缩
},
},
})