72a53cc86d
- 新增 build_aggregates_sql.ts:按月粒度刷新 klines 聚合视图链 (5m→1w),支持 dry-run/execute 模式 - 新增 run_exchange.sh 交易所数据拉取脚本 - DataSource 启动时输出配置概要,Binance REST 客户端添加超时配置 - 开发依赖新增 ts-node,env.yaml 更新数据库地址
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import { DataSource } from "typeorm";
|
|
import { pgsql, printConfigSummary } from "../config";
|
|
import * as entities from "./entities";
|
|
|
|
printConfigSummary();
|
|
|
|
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(); |