|
|
@@ -0,0 +1,45 @@
|
|
|
+import "reflect-metadata"
|
|
|
+import { DataSource } from "typeorm"
|
|
|
+import process from 'node:process'
|
|
|
+
|
|
|
+/**
|
|
|
+ * TypeORM 迁移数据源配置
|
|
|
+ *
|
|
|
+ * 此文件专用于 TypeORM 迁移 CLI 命令:
|
|
|
+ * - pnpm migration:show
|
|
|
+ * - pnpm migration:run
|
|
|
+ * - pnpm migration:revert
|
|
|
+ *
|
|
|
+ * 注意:
|
|
|
+ * - 使用 glob 模式加载实体,避免循环依赖
|
|
|
+ * - 关闭自动同步(synchronize: false)
|
|
|
+ * - 迁移通过 glob 模式加载
|
|
|
+ */
|
|
|
+export const AppDataSource = new DataSource({
|
|
|
+ type: "postgres",
|
|
|
+ host: process.env.DB_HOST || "localhost",
|
|
|
+ port: parseInt(process.env.DB_PORT || "5432"),
|
|
|
+ username: process.env.DB_USERNAME || "postgres",
|
|
|
+ password: process.env.DB_PASSWORD || "",
|
|
|
+ database: process.env.DB_DATABASE || "postgres",
|
|
|
+ // 使用明确的包路径加载实体,避免循环依赖
|
|
|
+ entities: [
|
|
|
+ // allin-packages 中的模块
|
|
|
+ "../allin-packages/channel-module/src/entities/*.ts",
|
|
|
+ "../allin-packages/company-module/src/entities/*.ts",
|
|
|
+ "../allin-packages/disability-module/src/entities/*.ts",
|
|
|
+ "../allin-packages/order-module/src/entities/*.ts",
|
|
|
+ "../allin-packages/statistics-module/src/entities/*.ts",
|
|
|
+ "../allin-packages/platform-module/src/entities/*.ts",
|
|
|
+ "../allin-packages/salary-module/src/entities/*.ts",
|
|
|
+ // packages 中的模块
|
|
|
+ "../packages/core-module/src/entities/*.ts",
|
|
|
+ "../packages/geo-areas/src/entities/*.ts",
|
|
|
+ "../packages/bank-names-module/src/entities/*.ts",
|
|
|
+ ],
|
|
|
+ migrations: [
|
|
|
+ "./migrations/*[0-9].ts", // 只匹配数字时间戳开头的迁移文件,排除 index.ts
|
|
|
+ ],
|
|
|
+ synchronize: false, // 迁移时必须关闭自动同步
|
|
|
+ logging: process.env.DB_LOGGING === "true",
|
|
|
+})
|