database-schema-design
Skill100 starsChanged 59 days agoMITView on GitHub
6 other projects use a version of this.
Adopted by
Most recently taken up by
- anuragsarkar97/skillstheir own version, first seen Nov 8, 2026
- reddygopalkrishna/developer-agent-skillstheir own version, first seen Nov 8, 2026
- WST2002/claude-code-skillstheir own version, first seen Oct 17, 2026
- manish1803/nextjs-fullstack-skillstheir own version, first seen Oct 13, 2026
- timwukp/agent-skills-best-practicetheir own version, first seen Sep 16, 2026
- agent-packs/registrytheir own version, first seen Jun 15, 2026
Other versions6 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 6
- timwukp/agent-skills-best-practice★ 10same name
- reddygopalkrishna/developer-agent-skills★ 8same name
- WST2002/claude-code-skills★ 4same name
- manish1803/nextjs-fullstack-skills★ 2same name
- agent-packs/registry★ 0same name
- anuragsarkar97/skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository15 other files it gives its agents.
- AGENTS.mdAGENTS.md
- harness/AGENTS.mdAGENTS.md
- i-test-target/AGENTS.mdAGENTS.md
- anti-overengineeringSkill
- app-type-classifierSkill
- auth-permission-securitySkill
- backend-api-designSkill
- CAP-SKILL-004Skill
- CAP-SKILL-013Skill
- CAP-SKILL-014Skill
- CAP-SKILL-015Skill
- frontend-ui-systemSkill
- mobile-miniapp-patternsSkill
- product-architectureSkill
- webapp-preview-testingSkill
The file
We found no rules to list in this file: it reads as prose or reference rather than instructions.
Files
Database Schema Design
用途
设计专业的数据库 Schema:实体、审计字段、索引、唯一约束、事务边界。 特别关注:次数/余额/库存/额度的安全操作。
使用场景
- 设计数据表时
- 涉及金额、次数、库存等敏感操作时
每张表的基础字段
CREATE TABLE xxx (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
-- 业务字段
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
deleted_at TIMESTAMPTZ -- 软删除
);四类表的区分
| 表类型 | 用途 | 特点 | 示例 |
| 当前状态表 | 记录实体的当前状态 | 会被 UPDATE | users, products, user_quota |
| 事件记录表 | 记录已发生的事件 | 只 INSERT,不 UPDATE | generation_history, orders |
| 修正记录表 | 记录对状态的手动修正 | 只 INSERT | quota_adjustments |
| 审计日志表 | 记录敏感操作 | 只 INSERT,用于追溯 | audit_logs, api_logs |
安全操作模式
次数/余额/库存/额度操作(必须防负数 + 防重复)
-- ❌ 错误做法:先读再写(有竞态条件)
SELECT quota_used FROM users WHERE id = ?;
-- 如果够用
UPDATE users SET quota_used = quota_used + 1 WHERE id = ?;
-- ✅ 正确做法:用条件 UPDATE + 检查 affected rows
UPDATE users
SET quota_used = quota_used + 1
WHERE id = ? AND quota_used + 1 <= quota_total;
-- 如果 affected rows = 0 → 额度不足
-- ✅ 或者用事务 + 行级锁
BEGIN;
SELECT quota_used FROM users WHERE id = ? FOR UPDATE;
-- 判断
UPDATE users SET quota_used = quota_used + 1 WHERE id = ?;
COMMIT;唯一约束(防止重复)
-- 用户名唯一
ALTER TABLE users ADD CONSTRAINT uq_users_username UNIQUE (username);
-- 用户 + 类型唯一(每人每种记录只能有一条)
ALTER TABLE user_settings ADD CONSTRAINT uq_user_type UNIQUE (user_id, type);索引原则
- 所有外键加索引
- 频繁查询的字段加索引
- 分页排序的字段加索引
- 唯一约束自带索引,不用额外加
常见错误
- ❌ 表没有 created_at / updated_at
- ❌ 先 SELECT 再 UPDATE(竞态条件)
- ❌ 没有唯一约束(重复数据)
- ❌ 涉及金额用 FLOAT(用 DECIMAL 或 INTEGER 存分)
- ❌ 软删除的字段不加索引
- ❌ 状态用字符串不用枚举
输出格式
## 数据库设计
### 表列表
1. [表名] — [说明]
- 字段列表
- 索引
- 唯一约束
### 关系图
[表A] 1:N [表B]
[表B] M:N [表C]
### 安全操作
- [操作]:[保护方式]Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

