docs: add table prefix migration task (21 CarLog tables)
按用户决定「i系统内的carlog数据库表要加carlog_前缀」: - 之前方案是「留给将来加第二个子系统时」, 现在提前做 - 新增 Task 2.8 表前缀迁移 (含 5 个子节 + review checklist) - DEV-PLAN.md: - 关键决策表「本阶段不做」→「本阶段做」 - 加 Task 2.8: 备份 + migration 020 + 改 server SQL + reset-all.js + 验证 - 加 §6.2.11 表前缀迁移 review checklist (10 项) - 「不做的事」: 删掉表前缀 - 「完成定义」: 加 Task 2.8 - ARCHITECTURE.md: - §3 决策表同步 - §7 W2 改成完整 RENAME TABLE 21 张 + 备份警告 - 删掉过时的 db.js tableName helper 建议 - README.md: - 决策表同步 - 实施路线按 Phase 1 / 2 / 2.8 / 3 重新分组 - 删掉「暂不做: CarLog 表前缀」 迁移策略: - 21 张 CarLog 业务表加 carlog_ 前缀 (含 carlog_settings) - 5 张共享表不动 (users / login_attempts / auth_locks / schema_migrations / 平台表) - 改前必做 mysqldump 备份 (RENAME 是 DDL 不能事务回滚) - 直接改 SQL (不加 helper 函数, 20 张表工作量可控) - sed \\b word boundary 安全替换 (列了完整 21 张表清单, 不动共享表 4 张)
This commit is contained in:
+30
-16
@@ -63,7 +63,7 @@ i 平台是一个「生活操作系统」:单 Vue SPA + 单 Express 进程 +
|
||||
|
||||
| 隔离维度 | 做法 |
|
||||
|---|---|
|
||||
| 数据 | 表前缀 `{subsystem}_*`(同一 DB 内;本阶段 CarLog 还没加前缀,留给将来加第二个子系统时) |
|
||||
| 数据 | 表前缀 `{subsystem}_*`(同一 DB 内;CarLog 已加 `carlog_` 前缀,将来加 fitness/reading 直接走 `fitness_*` / `reading_*`) |
|
||||
| 路由 | 子系统自己的路径空间(`/api/carlog/*` 现有;将来 `/api/fitness/*` 等) |
|
||||
| 代码 | 子系统独立目录(`server/src/subsystems/{name}/`、`client/src/views/subsystems/{name}/`) |
|
||||
| 设置 | 每个子系统有自己的 settings schema(JSON Schema,存 `platform_settings` 表,key 前缀 `{name}.*`) |
|
||||
@@ -238,26 +238,40 @@ const groupedCategories = computed(() => {
|
||||
|
||||
### W2: 表前缀迁移(CarLog)
|
||||
|
||||
把所有 CarLog 表加 `carlog_` 前缀:
|
||||
把所有 21 张 CarLog 业务表加 `carlog_` 前缀(共享表 `users / login_attempts / auth_locks / schema_migrations` 不动):
|
||||
|
||||
```sql
|
||||
RENAME TABLE vehicles TO carlog_vehicles;
|
||||
RENAME TABLE wash_records TO carlog_wash_records;
|
||||
RENAME TABLE refuel_records TO carlog_refuels;
|
||||
RENAME TABLE charging_records TO carlog_chargings;
|
||||
-- ... 其他表
|
||||
-- migration 020_carlog_prefix.sql
|
||||
DROP TABLE IF EXISTS _weather_snapshots_new; -- 清理 0013 临时表
|
||||
|
||||
RENAME TABLE
|
||||
vehicles TO carlog_vehicles,
|
||||
wash_records TO carlog_wash_records,
|
||||
chemicals TO carlog_chemicals,
|
||||
insurance_records TO carlog_insurance_records,
|
||||
chemical_usage TO carlog_chemical_usage,
|
||||
refuel_records TO carlog_refuel_records,
|
||||
settings TO carlog_settings,
|
||||
maintenance_records TO carlog_maintenance_records,
|
||||
charging_records TO carlog_charging_records,
|
||||
weather_snapshots TO carlog_weather_snapshots,
|
||||
operation_logs TO carlog_operation_logs,
|
||||
record_tags TO carlog_record_tags,
|
||||
notifications TO carlog_notifications,
|
||||
wash_photos TO carlog_wash_photos,
|
||||
tags TO carlog_tags,
|
||||
user_achievements TO carlog_user_achievements,
|
||||
notification_prefs TO carlog_notification_prefs,
|
||||
grocy_sync_logs TO carlog_grocy_sync_logs,
|
||||
category_mappings TO carlog_category_mappings,
|
||||
chemical_inventory_log TO carlog_chemical_inventory_log;
|
||||
```
|
||||
|
||||
`db.js` 加 helper:
|
||||
**改 server SQL**:13 个路由文件 + reset-all.js 全部加前缀(用 sed word boundary `\b` 替换,**`users`/`login_attempts`/`auth_locks`/`schema_migrations` 不要替换**)。
|
||||
|
||||
```js
|
||||
const TABLE_PREFIX = {
|
||||
vehicles: 'carlog_vehicles',
|
||||
wash_records: 'carlog_wash_records',
|
||||
};
|
||||
export function tableName(name) {
|
||||
return TABLE_PREFIX[name] || name;
|
||||
}
|
||||
> ⚠️ **改前先 mysqldump 备份**!RENAME 是 DDL 不能事务回滚。
|
||||
|
||||
**注意**: 直接改 SQL,**不加 helper 函数**(helper 让代码难读,20 张表工作量可控)。
|
||||
```
|
||||
|
||||
### W3+(暂不规划)
|
||||
|
||||
Reference in New Issue
Block a user