来源仓库:jxc/ai-fresh-delivery 来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d 快照树: 09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件) 按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据 (生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、 deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
55 lines
2.5 KiB
Markdown
55 lines
2.5 KiB
Markdown
# 克隆名单补齐模板已有业务表
|
||
|
||
日期:2026-09-10
|
||
关联:[20260910-tenant-clone-rls.md](./20260910-tenant-clone-rls.md);`public.tenant_business_tables()`;后续守卫见 [20260915-tenant-table-list-guard.md](./20260915-tenant-table-list-guard.md)(断言抽成可复用函数 + 每次迁移自动校验)
|
||
|
||
## 目标 / 非目标
|
||
|
||
**目标**
|
||
|
||
- `tenant_business_tables()` 覆盖 `tenant_template` 里实际存在、但未进名单的业务表(本机核对 11 张)。
|
||
- 已有分公司(如 BR004/BR005)经 `ensure_tenant_schemas_match_template` 从模板补建缺表。
|
||
- 之后 `clone_tenant_schema` 开新公司带上这些表;看板查询 `processing_demand_items` 不再因缺表失败。
|
||
|
||
**非目标**
|
||
|
||
- 不改 `_clone_table_structure` 丢跨表 FK 的既有行为(与其它克隆表一致)。
|
||
- 不把这些表纳入 20260815 核心 RLS 名单。
|
||
- 不为仓库里尚无迁移文件的表(如本机已有的 `supplier_price_agreements`)补写 DDL;只保证模板有则克隆。
|
||
|
||
## 方案要点
|
||
|
||
后期迁移对「当时已有 schema」`CREATE TABLE`,但未改 `tenant_business_tables()`,新 schema 只按名单 `LIKE` 克隆。
|
||
|
||
补进名单(插在父表之后):
|
||
|
||
| 表 | 说明 |
|
||
|---|---|
|
||
| `import_mapping_memories` | `20260792` |
|
||
| `inventory_reservations` | `20260796` |
|
||
| `parse_session_items` | `20260844` |
|
||
| `processing_demand_items` / `processing_demand_picks` | `20260850`(看板损耗查询) |
|
||
| `quality_report_prep_links` | `20260816` |
|
||
| `self_purchase_stock_inbounds` | `20260849` |
|
||
| `sku_direct_delivery_customers` | `20260860` |
|
||
| `print_jobs` / `weigh_devices` | `20260861` |
|
||
| `supplier_price_agreements` | 模板已有;仓库无独立迁移文件 |
|
||
|
||
迁移末尾 `ensure_tenant_schemas_match_template()`,并断言 `tenant_template` 不再有名单外基表。
|
||
|
||
## 改动面
|
||
|
||
- `migrations/20260910_tenant_clone_missing_tables.sql`
|
||
- `docs/modules/12-平台与系统.md`(开公司克隆名单)
|
||
- `docs/数据库结构与表职责.md`(清单权威迁移文件名)
|
||
|
||
## 验收标准
|
||
|
||
- [x] `tenant_template` 基表 ⊆ `tenant_business_tables()`(本机断言通过,名单外 0 张)
|
||
- [x] 各 `tenant_br*` 与模板表名集合一致(BR001–BR005 与模板均为 104 张)
|
||
- [ ] 新开公司 schema 含 `processing_demand_items`;看板不再报该关系不存在(待你重新创建公司验证)
|
||
|
||
## 风险与回滚
|
||
|
||
只 `CREATE TABLE LIKE` 空壳,不迁历史数据。回滚:从函数数组去掉新增名(已建表可留)。
|