Files
bps/.cursor/rules/database-rules.mdc
T
2025-05-04 20:37:40 +08:00

68 lines
1.2 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:
globs:
alwaysApply: false
---
# 数据库设计规范
## 数据库选型
- 主数据库:MySQL 8.0
- ORMPrisma
- 缓存:Redis
## 命名规范
1. 表名使用小写字母,下划线分隔
2. 字段名使用小写字母,下划线分隔
3. 主键统一命名为 id
4. 外键命名格式:{表名}_id
5. 索引命名格式:idx_{表名}_{字段名}
## 字段规范
1. 必须包含 id、created_at、updated_at 字段
2. 使用合适的数据类型
3. 字段必须添加注释
4. 设置合理的默认值
5. 使用 NOT NULL 约束
## 索引规范
1. 主键使用自增ID
2. 合理使用唯一索引
3. 避免过多索引
4. 考虑索引的选择性
## 表关系规范
1. 使用外键约束
2. 合理设计表关系
3. 避免过度规范化
4. 考虑查询性能
## 查询优化
1. 避免 SELECT *
2. 使用适当的索引
3. 避免大事务
4. 合理使用分页
## 数据安全
1. 敏感数据加密
2. 定期备份
3. 访问权限控制
4. 审计日志
## 性能优化
1. 表分区策略
2. 读写分离
3. 缓存策略
4. 定期维护
## 迁移规范
1. 使用 Prisma 迁移
2. 版本控制
3. 回滚机制
4. 测试验证
## 监控规范
1. 性能监控
2. 容量监控
3. 慢查询监控
4. 异常监控