database-design
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDatabase Design
数据库设计
Learn to THINK, not copy SQL patterns.
学会思考,而非照搬SQL模式。
🎯 Selective Reading Rule
🎯 选择性阅读规则
Read ONLY files relevant to the request! Check the content map, find what you need.
| File | Description | When to Read |
|---|---|---|
| PostgreSQL vs Neon vs Turso vs SQLite | Choosing database |
| Drizzle vs Prisma vs Kysely | Choosing ORM |
| Normalization, PKs, relationships | Designing schema |
| Index types, composite indexes | Performance tuning |
| N+1, EXPLAIN ANALYZE | Query optimization |
| Safe migrations, serverless DBs | Schema changes |
**仅阅读与需求相关的文件!**查看内容目录,找到你需要的部分。
| 文件 | 描述 | 阅读时机 |
|---|---|---|
| PostgreSQL vs Neon vs Turso vs SQLite | 选择数据库时 |
| Drizzle vs Prisma vs Kysely | 选择ORM时 |
| 规范化、主键、关系 | 设计模式时 |
| 索引类型、复合索引 | 性能调优时 |
| N+1问题、EXPLAIN ANALYZE | 查询优化时 |
| 安全迁移、无服务器数据库 | 模式变更时 |
⚠️ Core Principle
⚠️ 核心原则
- ASK user for database preferences when unclear
- Choose database/ORM based on CONTEXT
- Don't default to PostgreSQL for everything
- 当不确定时,询问用户的数据库偏好
- 根据场景选择数据库/ORM
- 不要默认所有场景都使用PostgreSQL
Decision Checklist
决策检查清单
Before designing schema:
- Asked user about database preference?
- Chosen database for THIS context?
- Considered deployment environment?
- Planned index strategy?
- Defined relationship types?
在设计模式之前:
- 是否询问了用户的数据库偏好?
- 是否针对当前场景选择了数据库?
- 是否考虑了部署环境?
- 是否规划了索引策略?
- 是否定义了关系类型?
Anti-Patterns
反模式
❌ Default to PostgreSQL for simple apps (SQLite may suffice)
❌ Skip indexing
❌ Use SELECT * in production
❌ Store JSON when structured data is better
❌ Ignore N+1 queries
❌ 简单应用默认使用PostgreSQL(SQLite可能就足够)
❌ 跳过索引
❌ 生产环境中使用SELECT *
❌ 当结构化数据更合适时存储JSON
❌ 忽略N+1查询