|
|
@@ -1,19 +1,13 @@
|
|
|
import "reflect-metadata"
|
|
|
import { DataSource } from "typeorm"
|
|
|
import process from 'node:process'
|
|
|
+import * as entities from './entities'
|
|
|
|
|
|
/**
|
|
|
- * TypeORM 迁移数据源配置
|
|
|
+ * TypeORM 数据源配置
|
|
|
*
|
|
|
- * 此文件专用于 TypeORM 迁移 CLI 命令:
|
|
|
- * - pnpm migration:show
|
|
|
- * - pnpm migration:run
|
|
|
- * - pnpm migration:revert
|
|
|
- *
|
|
|
- * 注意:
|
|
|
- * - 使用 glob 模式加载实体,避免循环依赖
|
|
|
- * - 关闭自动同步(synchronize: false)
|
|
|
- * - 迁移通过 glob 模式加载
|
|
|
+ * 使用类导入方式加载实体,让 Vite SSR 正确处理 TypeScript 编译
|
|
|
+ * 实体内部已使用字符串语法解决循环依赖问题
|
|
|
*/
|
|
|
export const AppDataSource = new DataSource({
|
|
|
type: "postgres",
|
|
|
@@ -22,11 +16,8 @@ export const AppDataSource = new DataSource({
|
|
|
username: process.env.DB_USERNAME || "postgres",
|
|
|
password: process.env.DB_PASSWORD || "",
|
|
|
database: process.env.DB_DATABASE || "postgres",
|
|
|
- // 使用 glob 模式加载实体,避免循环依赖
|
|
|
- entities: [
|
|
|
- "../allin-packages/*/src/entities/*.ts",
|
|
|
- "../packages/*/src/entities/*.ts",
|
|
|
- ],
|
|
|
+ // 使用类导入方式,Vite SSR 会处理 TypeScript 编译
|
|
|
+ entities: Object.values(entities),
|
|
|
migrations: [
|
|
|
"./migrations/*[0-9].ts", // 只匹配数字时间戳开头的迁移文件,排除 index.ts
|
|
|
],
|