309b11ae30
- 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)
29 lines
1.0 KiB
TypeScript
29 lines
1.0 KiB
TypeScript
import { DataSource } from "typeorm";
|
|
import { pgsql } from "../config";
|
|
import * as entities from "./entities";
|
|
|
|
export const AppDataSource = new DataSource({
|
|
type: "postgres",
|
|
host: pgsql.host,
|
|
port: pgsql.port,
|
|
database: pgsql.database,
|
|
username: pgsql.user,
|
|
password: pgsql.password,
|
|
// 实体注册:关系实体通过 entities/index.ts 统一导出
|
|
// TimescaleDB K 线实体后续通过 @timescaledb/typeorm 装饰器注册
|
|
entities: [
|
|
...Object.values(entities),
|
|
],
|
|
// 生产环境禁用 synchronize,使用 Migration
|
|
synchronize: false,
|
|
migrations: [__dirname + "/migrations/*.{ts,js}"],
|
|
// 连接池
|
|
extra: {
|
|
max: pgsql.max, // 最大连接数 20
|
|
idleTimeoutMillis: pgsql.idleTimeoutMillis, // 空闲超时 30s
|
|
connectionTimeoutMillis: pgsql.connectionTimeoutMillis, // 连接超时 5s
|
|
},
|
|
logging: process.env.NODE_ENV === "development" ? ["error", "warn"] : ["error"],
|
|
});
|
|
|
|
await AppDataSource.initialize(); |