askill
database-design

database-designSafety --Repository

Schema design, indexing strategy, migration patterns, and anti-patterns for relational databases. Use when designing schemas, writing migrations, optimizing queries, or reviewing database changes.

1 stars
1.2k downloads
Updated 2/6/2026

Package Files

Loading files...
SKILL.md

Database Design

Decision Tree

Data storage needed → What type?
    ├─ Structured, relational → PostgreSQL (server) or SQLite (embedded/mobile)
    ├─ Document-oriented, flexible schema → MongoDB or PostgreSQL JSONB
    ├─ Key-value / caching → Redis
    ├─ Full-text search → PostgreSQL tsvector or Elasticsearch
    └─ Time-series → TimescaleDB (PostgreSQL extension)

Schema Design Checklist

  • Every table has a primary key (prefer UUID or BIGSERIAL)
  • Foreign keys have ON DELETE behavior defined (CASCADE, SET NULL, RESTRICT)
  • Timestamps: created_at and updated_at on every table
  • Columns NOT NULL by default, nullable only when intentional
  • Text fields have reasonable length constraints
  • Sensitive data columns identified for encryption

Indexing Strategy

Always IndexConsider IndexingDon't Index
Foreign keysColumns in WHERE clausesBoolean columns (low cardinality)
Unique constraintsColumns in ORDER BYSmall tables (<1000 rows)
Columns in JOINsPartial indexes for common filtersFrequently updated columns

Migration Rules

  1. Always reversible - Every up has a down
  2. No data loss - Add columns before removing old ones
  3. No locks on large tables - Use CREATE INDEX CONCURRENTLY
  4. One concern per migration - Don't mix schema + data changes
  5. Test with production-size data - Migrations that work on 100 rows may lock on 10M

Anti-Patterns

Anti-PatternProblemFix
EAV (Entity-Attribute-Value)Can't index, can't validateProper columns or JSONB
God table (100+ columns)Slow queries, null hellNormalize into related tables
No foreign keysOrphaned data, integrity bugsAlways define relationships
SELECT *Wastes bandwidth, breaks on schema changeExplicit column list
Comma-separated valuesCan't query, can't joinJunction table
Money as FLOATRounding errorsDECIMAL or integer cents

For detailed patterns see:

Install

Download ZIP
Requires askill CLI v1.0+

AI Quality Score

AI review pending.

Metadata

Licenseunknown
Version-
Updated2/6/2026
PublisherBigPapiCB

Tags

databasetesting
database-design - AI Agent Skill | askill