Files
shanxia2.0/docs/crm-migration/ref-database-rules.md
T
2026-06-01 08:21:21 +08:00

52 lines
2.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 参考:数据库迁移规则
> 编写 DDL、Model、Schema 时加载此文档。
---
## 公共字段适配(7 项强制)
| 变更项 | 原 CRM(Java) | shanxia2.0 | 示例 |
|--------|---------------|------------|------|
| 主键 | `bigint(20) AUTO_INCREMENT` | `varchar(64) NOT NULL`(UUID) | `id varchar(64) NOT NULL COMMENT '主键ID(UUID)'` |
| 租户 | `tenant_id varchar(20)` | `tenant_no varchar(64)` | — |
| 创建部门 | `create_dept bigint(20)` | `create_dept_id varchar(64)` | — |
| 删除标记 | `del_flag tinyint(1)` | `del_flag smallint(6)` | — |
| 版本号 | `version int(11)` | 移除 | 不使用乐观锁 |
| 公共字段顺序 | 不统一 | `tenant_no → order_num → remark → create_by → create_dept_id → create_time → update_by → update_time → del_flag` | — |
| 字符集 | `utf8mb4` | `utf8mb4`(不变) | — |
## 业务字段对齐原则
除 7 项公共字段适配外,所有业务字段语义必须与原 CRM 完全一致:
- 字段名不变(`customer_name`、`deal_status` 等)
- 类型可等价或略宽(`varchar(20)` 保留,不得缩为 `char(1)`)
- 默认值不变(`status varchar(20) DEFAULT 'normal'`,不得改为 `DEFAULT '1'`)
- COMMENT 枚举不变
- 索引保留
## 字典数据迁移(强制)
| 规则 | 说明 |
|------|------|
| `dict_type` 不可改 | 如 `crm_customer_status`,原样迁移 |
| `dict_value` 不可改 | 如 `on/off`、`normal/pool/invalid`,禁止改为 `1/0` |
| `dict_label` 不可改 | 展示文案以原 CRM 为准 |
| 数据来源 | 从 `sx.sql` 的 `sys_dict_type` / `sys_dict_data` 中筛选 `crm_%` 导入 |
禁止做法:
- ❌ 将 `on/off` 改为 `1/0`
- ❌ 将 `normal/pool/invalid` 改为 `1/2/3`
- ❌ 写兼容层做值转换
## DDL 检查清单
- [ ] 主键 `varchar(64) NOT NULL`
- [ ] 业务字段与 `sx.sql` 一致
- [ ] 公共字段按标准顺序排列
- [ ] 字符集 `utf8mb4`,引擎 `InnoDB`
- [ ] 所有字段有 COMMENT
- [ ] 索引与原 CRM 等价
- [ ] SQL 增量脚本保存到 `docs/sql/`