Database Design

Design relational and document database schemas with normalization, indexing, and migration patterns.

Updated Jul 16, 2026
One-click install
npx skills add https://github.com/pjherron/hypoc --skill database-design-pjherron
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: Database Design
Source: https://github.com/pjherron/hypoc/tree/main/hypoc/skills/database-design
Command: npx skills add https://github.com/pjherron/hypoc --skill database-design-pjherron

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Designing database schemas without a systematic approach leads to redundant data, slow queries, and painful migrations. This Skill provides concrete patterns for ER modeling, normalization, indexing, partitioning, and schema evolution across Postgres, MySQL, MongoDB, and multi-database architectures. ## Core Features & Use Cases - ER Modeling & Normalization: Design one-to-many, many-to-many, and self-referencing relationships, then normalize to 3NF/BCNF with worked SQL examples. - Index & Query Optimization: Apply B-tree, partial, composite, GIN, and JSONB index strategies, plus monitoring queries to find unused or missing indexes. - Schema Evolution & Scaling: Execute zero-downtime migrations with the expand-migrate-contract pattern, partition large tables by range or list, and implement soft deletes with audit trails. - Use Case: When building an order management system, use this Skill to model users and orders, add composite indexes for common queries, cache aggregates via triggers, and plan a safe migration path as the schema evolves. ## Quick Start Ask the AI to design a normalized Postgres schema for your application's entities, including indexes and a migration plan.

Frequently Asked Questions about Database Design

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I design a many-to-many relationship in SQL?▼

Create a junction table with foreign keys referencing both entities and a composite primary key on the pair. For example, an enrollments table linking students and courses with student_id and course_id columns, plus indexes on each foreign key.

When should I denormalize a database schema?▼

Denormalize for read-heavy workloads where joins hurt performance, such as caching aggregate counts or flattening frequently joined columns. Normalize first for write-heavy workloads and data integrity, then denormalize selectively using triggers or materialized views.

Should I use MongoDB embedding or referencing for documents?▼

Embed when data is accessed together, the relationship is one-to-few, and documents stay under the 16MB limit. Reference when data is accessed independently, changes frequently, or the relationship is one-to-many or many-to-many.

How do I perform zero-downtime schema migrations in Postgres?▼

Use the expand-migrate-contract pattern: add the new column as nullable, update application code to write both columns, backfill existing rows, then drop old columns after all instances are updated. Avoid adding NOT NULL columns without defaults on large tables.

Why does my unique constraint fail with soft deletes?▼

A standard unique index blocks reusing a value from a soft-deleted row. Use a partial unique index with WHERE deleted_at IS NULL so only active rows must be unique, or a composite index on the value plus deleted_at.

What data type should I use for money in Postgres?▼

Use DECIMAL(p,s) or NUMERIC for exact decimal arithmetic on monetary values. Never use FLOAT or DOUBLE, which introduce rounding errors. Use TIMESTAMPTZ rather than TIMESTAMP for timezone-aware timestamps.