Files
nl-blogs/sql/.cursor/rules/Sql-Standards.mdc
2026-08-24 09:58:07 +08:00

32 lines
1.4 KiB
Plaintext
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.
---
description: nl-erp SQL 增量规范(药企 ERP 业务表,与 nl-admin 平台库分离)
alwaysApply: true
---
# 基础规范
1. 每个字段、每条 INSERT 写中文注释
2. 代码中要有详细的行级中文注释:约束、默认值、枚举取值、可重复执行的原因都要写在该行或紧上一行
3. 相邻代码块空行不超过 2 行
4. `created_at` / `updated_at` / `deleted_at` 统一 int 时间戳,软删 `deleted_at=0` 表示未删
# 与 nl-admin 的边界
- 平台底座表admin/role/menu/api_endpoint 等)仍在 `D:\myCode\sql\nl-admin`
- **药企 ERP 业务表、业务角色种子、业务菜单、业务接口登记**只写本仓库
- 增量可 INSERT 平台表(如 `nl_role` / `nl_menu` / `nl_api_endpoint`),不要改 `nl-admin` 的初始化快照
# 文件组织
- 路径:`{YYYYMMDD}/{当天第几个sql}_sql名字.sql`,日期 8 位数字
- 可重复执行:建表用 `CREATE TABLE IF NOT EXISTS`,种子用 `INSERT IGNORE`
- 尚无全量初始化快照;表结构以日期化增量文件为准
# 建表约定
- 物理表前缀 `nl_`,引擎 InnoDB`utf8mb4` / `utf8mb4_0900_ai_ci``ROW_FORMAT=DYNAMIC`
- 常规表必备:`id` int UNSIGNED AUTO_INCREMENT + 时间三件套
- 状态:`status` 0=正常/上架 1=禁用/下架(除非 SRS 另行注明)
- 布尔:`is_xxx` tinyint(1) 0否 1是
- 类型/枚举用 tinyint注释写清取值