依据 Gitea v1.27.3 modules/charset/escape_stream.go 的判定规则 (analyzeDetectResults:仅当左右相邻字符都不是非 ASCII 时才标记, 且 _common 表恒定生效),把说明文档中会被标记的全角标点 (,:;?!() 等)改为半角,并保证成对括号宽度一致。 中文语境中的全角标点(左右均为中文)保持原样,不动代码与契约语义。 同时删除临时探针目录 _probe/(仅用于确认 Gitea 判定规则)。
58 lines
1.8 KiB
Markdown
58 lines
1.8 KiB
Markdown
# T-WEB-002 TypeORM 迁移生成表结构
|
|
|
|
- **状态**: done
|
|
- **依赖**: T-WEB-001
|
|
|
|
## 目标
|
|
|
|
用 TypeORM migration 在现有实例的 `opendance` 库中建立全部表结构。不使用
|
|
`DB_SYNCHRONIZE`,迁移必须可逆。
|
|
|
|
## load
|
|
|
|
```
|
|
DSH.md
|
|
contracts/database.md
|
|
contracts/data-models.md
|
|
web-server/src/entities/*.entity.ts
|
|
web-server/src/migrations/*.ts
|
|
web-server/src/db/data-source.ts
|
|
```
|
|
|
|
## 表结构
|
|
|
|
| 表 | 用途 | 关键列 |
|
|
|---|---|---|
|
|
| `assets` | 上传文件元数据 | `sha256` 唯一索引(去重)、`stored_path`、`size` |
|
|
| `songs` | 曲目 | 来源五元组、`status`、`deleted_at` |
|
|
| `motions` | 动作数据 | `song_id` FK(ON DELETE SET NULL)、预处理产物列 |
|
|
| `models` | 角色模型 | `format`、`vrm_version`、`is_primary` |
|
|
| `review_records` | 审核流水 | `(target_type, target_id)` 复合索引 |
|
|
|
|
统一约定(`contracts/database.md`):
|
|
|
|
- 表名 `snake_case` 复数;主键 `BIGINT AUTO_INCREMENT`
|
|
- 时间列 `DATETIME`;软删除 `deleted_at`
|
|
- Tags 使用 `simple-json`(MariaDB 下落 LONGTEXT,规避 JSON 类型差异)
|
|
|
|
## 交付物
|
|
|
|
- `web-server/src/entities/{asset,song,motion,model,review-record}.entity.ts`
|
|
- `web-server/src/migrations/1789382903060-InitSchema.ts`(由 `migration:generate`
|
|
对真实库生成,保证与实体零漂移)
|
|
- `web-server/src/db/data-source.ts` 的 `migrations` 通配配置
|
|
|
|
## 验收
|
|
|
|
```bash
|
|
cd web-server
|
|
npm run migration:run # 1 migrations were executed successfully
|
|
npm run migration:show # [X] 1 InitSchema1789382903060
|
|
npm run migration:revert && npm run migration:run # 验证可逆
|
|
```
|
|
|
|
## 结果
|
|
|
|
- 迁移已在 `opendance` 库执行成功,创建 5 张业务表 + `typeorm_migrations`。
|
|
- `down()` 完整删除索引、外键与表,可逆性通过 `migration:revert` 验证。
|