db-schema
Skill2 starsChanged 6 months agoMITView on GitHub
Enforce schema discipline: queries-first design, index-every-filter, safe migrations, verify-at-scale thinking. Prevents the common failure of designing schemas for demos that break in production. Use when creating tables, planning migrations, designing data models, or when user mentions database, schema, migration, indexing, multi-tenant.
5 other projects use a version of this.
Adopted by
Most recently taken up by
- adarshaccreteinfo/Claude-Skillstheir own version, first seen Aug 27, 2026
- Ericcccccc777/CCC-MAGItheir own version, first seen Jun 28, 2026
- sordi-ai/skill-everythingtheir own version, first seen May 13, 2026
- Pascal-Neubauer/Claude_Skillstheir own version, first seen Apr 20, 2026
- zeon-kun/claude-skillstheir own version, first seen Apr 7, 2026
Other versions5 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 5
- sordi-ai/skill-everything★ 20same name
- zeon-kun/claude-skills★ 6same name
- adarshaccreteinfo/Claude-Skills★ 1same name
- Ericcccccc777/CCC-MAGI★ 1same name
- Pascal-Neubauer/Claude_Skills★ 1same 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 repository20 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- skill-forgeSkill
- ai-debt-detectorSkill
- arch-from-codeSkill
- context-builderSkill
- design-modeSkill
- diagnoseSkill
- dynamic-workflowSkill
- error-resilienceSkill
- git-workflowSkill
- grillSkill
- handoffSkill
- mcp-conductorSkill
- prove-itSkill
- self-reviewSkill
- session-guardSkill
- setupSkill
- web-perfSkill
- zoom-outSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
13 rules. 0 are common, 11 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 4 edited versions we read keep these.
11
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 22
Before writing ANY schema:
- Distinctive: line 34
Never CREATE TABLE without knowing the top 5 queries it serves
- Distinctive: line 35
Never deploy a migration without testing against production-sized data
- Distinctive: line 36
Never use FLOAT for money (DECIMAL or integer cents)
- Very specific: line 37
Never skip explicit created_at/updated_at on any table
- Distinctive: line 38
Never add a column with DEFAULT on a large table (locks it)
- Distinctive: line 39
Never DROP COLUMN in one step (stop writing → deploy → then drop)
- Distinctive: line 41
Before creating any table:
- Distinctive: line 83
Write-heavy tables where read is rare (indexes slow writes)
- Distinctive: line 95
Add new column → copy data → update code → drop old column
- Distinctive: line 118
Run migration against it
- Very specific: line 216
Not adding created_at/updated_at to every table
- Distinctive: line 221
Not planning for time zones (always use TIMESTAMPTZ)
“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Overview
Enforce queries-first schema discipline — design every table around its access patterns, index every filter, and verify migrations are safe at production scale.
Database Schema Design
Persistence
ACTIVE on every schema change. Every CREATE TABLE, every ALTER, every migration. Think at scale before writing DDL.
The Discipline
Before writing ANY schema:
1. QUERIES FIRST — what queries will run against this? (schema serves queries, not the other way around)
2. SCALE QUESTION — what happens at 10M rows? 100M? Does this still work?
3. INDEX PLAN — every WHERE, JOIN, ORDER BY gets an index. No exceptions.
4. MIGRATION SAFETY — can this ALTER run without locking the table for minutes?
5. VERIFY — explain analyze the critical queries. Prove they use indexes.Rules (never break)
- Never CREATE TABLE without knowing the top 5 queries it serves
- Never deploy a migration without testing against production-sized data
- Never use FLOAT for money (DECIMAL or integer cents)
- Never skip explicit
created_at/updated_aton any table - Never add a column with DEFAULT on a large table (locks it)
- Never DROP COLUMN in one step (stop writing → deploy → then drop)
Before creating any table:
- Define the access patterns FIRST (queries drive schema, not the other way around)
- Choose normalization level based on read/write ratio
- Plan for the 10x scale (what happens at 10M rows?)
- Identify foreign keys and cascade behavior
- Define indexes for every WHERE/JOIN/ORDER BY clause
- Plan soft-delete vs hard-delete strategy
- Consider multi-tenancy needs upfront
Normalization Decision
| Situation | Strategy | Why |
| Read-heavy, rarely changes | Denormalize | Avoid JOINs at query time |
| Write-heavy, consistency critical | Normalize (3NF) | Single source of truth |
| Analytics/reporting | Star schema (denormalized) | Optimized for aggregation |
| User-facing CRUD | 3NF with strategic denorm | Balance of integrity + speed |
Indexing Strategy
Rules of Thumb
-- Index every column that appears in:
-- WHERE, JOIN ON, ORDER BY, GROUP BY
-- Composite index order matters: most selective first
CREATE INDEX idx_orders_user_status ON orders(user_id, status);
-- This supports: WHERE user_id = ? AND status = ?
-- Also supports: WHERE user_id = ? (leftmost prefix)
-- Does NOT support: WHERE status = ? (not leftmost)
-- Covering index (includes all columns query needs)
CREATE INDEX idx_orders_covering ON orders(user_id, status) INCLUDE (total, created_at);
-- Query can be answered entirely from index (no table lookup)When NOT to Index
- Columns with < 10 distinct values (low cardinality) — except in composite indexes
- Tables with < 1000 rows (full scan is faster)
- Write-heavy tables where read is rare (indexes slow writes)
- Columns that change frequently (index maintenance cost)
Migration Safety
The Golden Rules
- Never DROP COLUMN in production without a 2-step process:
- Step 1: Stop writing to the column (deploy code change)
- Step 2: Drop the column (next migration, after deploy confirmed)
- Never rename columns directly:
- Add new column → copy data → update code → drop old column
- Always make migrations reversible:
-- UP ALTER TABLE users ADD COLUMN display_name VARCHAR(255); -- DOWN (must always exist) ALTER TABLE users DROP COLUMN display_name; - Lock-free schema changes for large tables:
-- BAD: locks table for minutes on 10M+ rows ALTER TABLE orders ADD COLUMN priority INT DEFAULT 0; -- GOOD: add nullable first, backfill in batches ALTER TABLE orders ADD COLUMN priority INT; -- Then backfill in 10K batches with sleep between - Test migrations against production-sized data:
- Dump production schema (not data)
- Run migration against it
- Measure lock time and query impact
Multi-Tenant Patterns
| Pattern | Isolation | Complexity | When to Use |
| Shared table + tenant_id | Logical | Low | < 1000 tenants, simple data |
| Schema per tenant | Strong | Medium | Enterprise, compliance needs |
| Database per tenant | Maximum | High | Regulated industries, massive scale |
Shared Table (Most Common)
-- Every table has tenant_id
CREATE TABLE projects (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
tenant_id UUID NOT NULL REFERENCES tenants(id),
name VARCHAR(255) NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW()
);
-- Row-level security (PostgreSQL)
ALTER TABLE projects ENABLE ROW LEVEL SECURITY;
CREATE POLICY tenant_isolation ON projects
USING (tenant_id = current_setting('app.tenant_id')::UUID);
-- Composite index (tenant first!)
CREATE INDEX idx_projects_tenant ON projects(tenant_id, created_at DESC);Common Patterns
Soft Delete
CREATE TABLE posts (
id UUID PRIMARY KEY,
title TEXT NOT NULL,
deleted_at TIMESTAMPTZ, -- NULL = active, timestamp = deleted
-- ...
);
-- Default scope excludes deleted
CREATE VIEW active_posts AS SELECT * FROM posts WHERE deleted_at IS NULL;
-- Index for active records only (partial index)
CREATE INDEX idx_posts_active ON posts(created_at) WHERE deleted_at IS NULL;Audit Trail
CREATE TABLE audit_log (
id BIGSERIAL PRIMARY KEY,
table_name TEXT NOT NULL,
record_id UUID NOT NULL,
action TEXT NOT NULL, -- INSERT, UPDATE, DELETE
old_data JSONB,
new_data JSONB,
actor_id UUID,
created_at TIMESTAMPTZ DEFAULT NOW()
);
-- Trigger-based (automatic)
CREATE OR REPLACE FUNCTION audit_trigger() RETURNS TRIGGER AS $$
BEGIN
INSERT INTO audit_log(table_name, record_id, action, old_data, new_data, actor_id)
VALUES (TG_TABLE_NAME, COALESCE(NEW.id, OLD.id), TG_OP,
to_jsonb(OLD), to_jsonb(NEW), current_setting('app.actor_id', true)::UUID);
RETURN COALESCE(NEW, OLD);
END;
$$ LANGUAGE plpgsql;Polymorphic Associations
-- BAD: string type column
-- commentable_type: 'Post' | 'Video' | 'Comment'
-- GOOD: separate FKs (type-safe, indexable)
CREATE TABLE comments (
id UUID PRIMARY KEY,
body TEXT NOT NULL,
post_id UUID REFERENCES posts(id),
video_id UUID REFERENCES videos(id),
-- Exactly one must be non-null
CONSTRAINT one_parent CHECK (
(post_id IS NOT NULL)::int + (video_id IS NOT NULL)::int = 1
)
);Common Mistakes
- Designing schema before knowing the queries (build for access patterns)
- Using UUIDs as primary key without considering index bloat (use ULIDs for time-ordered)
- Not adding
created_at/updated_atto every table - Cascading deletes without understanding the full graph
- N+1 schema design (forcing the app to make N queries)
- Storing money as FLOAT (use DECIMAL/NUMERIC or integer cents)
- Indexing everything (slows writes, wastes storage)
- Not planning for time zones (always use TIMESTAMPTZ)
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.

