spec-writing-database

star 2

Database schema specification using Mermaid ER diagrams, table structures, constraints, and indexes for multi-tenant applications.

michaellperry By michaellperry schedule Updated 1/11/2026

name: spec-writing-database description: Database schema specification using Mermaid ER diagrams, table structures, constraints, and indexes for multi-tenant applications.

Database Schema Specification Patterns

Use when designing database schemas with Mermaid ER diagrams, tables, constraints, and indexes for multi-tenant applications. IMPORTANT: Specify WHAT needs to be built (data structure, relationships, business rules), NOT HOW to build it (no Entity Framework entity classes or fluent configuration code).

When to use

  • Creating ER diagrams for new features or schema documentation
  • Defining table structures with columns, data types, defaults, and constraints
  • Specifying CHECK, UNIQUE, and FOREIGN KEY constraints for data integrity
  • Designing indexes for tenant-filtered queries, uniqueness, and performance
  • Planning additive or breaking schema migrations

Core principles

  • Use Mermaid erDiagram syntax with PK/FK/UK annotations and field descriptions
  • All domain entities include TenantId FK; unique constraints scoped as (TenantId, BusinessKey)
  • Indexes lead with TenantId; use INCLUDE for covering indexes; filter WHERE for active records
  • Integer PKs for performance; GUID alternate keys for external APIs; audit timestamps (CreatedAt, UpdatedAt)
  • CHECK constraints enforce business rules; FK cascade rules respect relationships (RESTRICT, CASCADE)
  • Breaking changes require multi-step migrations with application deployments between steps

Resources

Default locations

  • Specifications: docs/specs/{feature-name}.md (Database Schema section)
  • Mermaid diagrams embedded in markdown specs
  • Migration scripts referenced but not specified in detail

Validation checklist

  • ER diagram shows all entities, relationships (||--o{, etc.), and field annotations (PK, FK, UK)
  • Tables include TenantId FK, integer PK, GUID UK, audit timestamps (CreatedAt, UpdatedAt), and defaults
  • Composite unique constraints: (TenantId, Name) or (TenantId, BusinessGuid)
  • CHECK constraints validate business rules (capacity ranges, dates, prices, non-empty strings)
  • FK constraints specify ON DELETE behavior (RESTRICT for parents, CASCADE for children)
  • Indexes: TenantId first column, INCLUDE for projections, filtered WHERE for active records
  • Design principles documented: tenant isolation, integer PKs, GUID UKs, audit fields, soft deletes
  • Migration strategy specified: additive (backward-compatible) vs breaking (multi-step)
Install via CLI
npx skills add https://github.com/michaellperry/aaad --skill spec-writing-database
Repository Details
star Stars 2
call_split Forks 0
navigation Branch main
article Path SKILL.md
More from Creator
michaellperry
michaellperry Explore all skills →