skills/council/architect/schema-design/SKILL.md
Use when designing or modifying database schemas with migration plans. Covers entity definition, relationship mapping, normalization trade-offs, indexing strategies, and RLS policies. Do not use for API endpoint contracts (use api-design) or codebase analysis (use codebase-context).
npx skillsauth add dtsong/my-claude-setup schema-designInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Design relational database schemas with normalization trade-offs, migration plans, and indexing strategies. Produces migration-ready SQL that can be applied directly to the database.
No user-provided values are used in commands or file paths. All inputs are treated as read-only analysis targets.
Read current schema files, migration history, or ORM models. List all existing tables with their columns, types, constraints, and relationships. Note any existing indexes and RLS policies.
From the feature requirements and interview output, determine what new data needs to be stored. List candidate entities and their purpose.
For each new entity, define:
Define all relationships between entities:
Default to 3NF. For each denormalization decision, document:
Drive index choices from query patterns:
If using Supabase or row-level security:
Write executable SQL:
Compaction resilience: If context was lost during a long session, re-read the Inputs section to reconstruct what system is being analyzed, check the Progress Checklist for completed steps, then resume from the earliest incomplete step.
# Schema Design: [Feature Name]
## Entity Overview
| Entity | Purpose | New/Modified |
|--------|---------|-------------|
| ... | ... | ... |
## Entity Definitions
### [entity_name]
| Column | Type | Nullable | Default | Constraints |
|--------|------|----------|---------|-------------|
| id | uuid | NO | gen_random_uuid() | PK |
| ... | ... | ... | ... | ... |
## Relationships
[ASCII diagram] users 1──N posts posts N──M tags (through: post_tags)
## Index Strategy
| Table | Index | Columns | Type | Rationale |
|-------|-------|---------|------|-----------|
| ... | ... | ... | ... | ... |
## Denormalization Decisions
| What | Why | Consistency Strategy |
|------|-----|---------------------|
| ... | ... | ... |
## RLS Policies
| Table | Operation | Policy | Using |
|-------|-----------|--------|-------|
| ... | ... | ... | ... |
## Migration SQL
### Up
```sql
-- New tables
CREATE TABLE ...
-- Indexes
CREATE INDEX ...
-- RLS
ALTER TABLE ... ENABLE ROW LEVEL SECURITY;
CREATE POLICY ...
DROP POLICY ...
DROP INDEX ...
DROP TABLE ...
## Quality Checks
- [ ] Every entity has a primary key
- [ ] Foreign keys reference existing or newly created tables
- [ ] Indexes support the identified query patterns
- [ ] Migration is reversible (Down section undoes Up completely)
- [ ] RLS policies cover all access patterns (SELECT, INSERT, UPDATE, DELETE)
- [ ] Timestamp columns (created_at, updated_at) are present on mutable entities
- [ ] CASCADE behavior is explicitly defined for all foreign keys
- [ ] No orphan tables (every table is reachable via relationships or has a documented reason for isolation)
## Evolution Notes
<!-- Observations appended after each use -->
development
Use when planning implementation steps, deciding commit format, or structuring development approach. Provides brainstorm-plan-implement flow with conventional commits. Triggers on 'how should I approach this', 'commit format'.
development
Security audit checklist for web applications. Use when reviewing, auditing, or hardening a web app's security posture. Covers rate limiting, auth headers, IP blocking, CORS, security middleware, input validation, file upload limits, ORM usage, and password hashing. Triggers on requests like "review security", "harden this app", "security audit", "check for vulnerabilities", or when building/reviewing API endpoints.
development
Review UI code for Web Interface Guidelines compliance. Use when asked to "review my UI", "check accessibility", "audit design", "review UX", or "check my site against best practices".
development
React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.