database-design

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Database 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.
FileDescriptionWhen to Read
database-selection.md
PostgreSQL vs Neon vs Turso vs SQLiteChoosing database
orm-selection.md
Drizzle vs Prisma vs KyselyChoosing ORM
schema-design.md
Normalization, PKs, relationshipsDesigning schema
indexing.md
Index types, composite indexesPerformance tuning
optimization.md
N+1, EXPLAIN ANALYZEQuery optimization
migrations.md
Safe migrations, serverless DBsSchema changes

**仅阅读与需求相关的文件!**查看内容目录,找到你需要的部分。
文件描述阅读时机
database-selection.md
PostgreSQL vs Neon vs Turso vs SQLite选择数据库时
orm-selection.md
Drizzle vs Prisma vs Kysely选择ORM时
schema-design.md
规范化、主键、关系设计模式时
indexing.md
索引类型、复合索引性能调优时
optimization.md
N+1问题、EXPLAIN ANALYZE查询优化时
migrations.md
安全迁移、无服务器数据库模式变更时

⚠️ 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查询