本文へ移動
cccskills
無料GitHub で公開

database-schema-design

Design database schemas with normalization, relationships, and constraints. Use when creating new database schemas, designing tables, or planning data models for any database paradigm.

インストール方法を見る

含まれるファイル(2)

  • SKILL.md8.3 KB
  • references/relational.md5.1 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Database Schema Design

Overview

Design scalable, well-structured database schemas with proper relationships, constraints, and data types. This skill covers universal data modeling principles. For paradigm-specific patterns, see references.

When to Use

  • New database schema design
  • Data model planning
  • Relationship design (1:1, 1:N, N:N, graph edges)
  • Normalization or denormalization analysis
  • Constraint and validation planning
  • Performance optimization at schema level
  • Cross-store entity consistency

Paradigm-Specific References

After reading the methodology below, read the reference matching your surface's Databases column in the surface stack map (.claude/instructions/tech-stack.md):

ParadigmReferenceExample Stores
Relationalreferences/relational.mdPostgreSQL, MySQL, SQLite
Documentreferences/document.mdMongoDB, Firestore, CouchDB
Graphreferences/graph.mdSurrealDB, Neo4j, ArangoDB
Key-Valuereferences/key-value.mdRedis, DynamoDB, Memcached

Universal Data Modeling Principles

1. Entity Identification

Start with the domain:

  1. Identify nouns — these become entities/tables/collections
  2. Identify relationships — how entities connect
  3. Identify attributes — what data each entity holds
  4. Identify cardinality — one-to-one, one-to-many, many-to-many

2. Normalization vs Denormalization

Normalization reduces data duplication at the cost of join complexity:

  • 1NF — Eliminate repeating groups (no arrays/CSVs in a single field)
  • 2NF — Remove partial dependencies (every non-key attribute depends on the WHOLE key)
  • 3NF — Remove transitive dependencies (non-key attributes don't depend on each other)

Denormalization trades storage for read performance:

  • Embed frequently co-read data together
  • Pre-compute aggregates for dashboards
  • Duplicate data intentionally (with consistency strategy)

Decision framework:

  • Write-heavy, consistency-critical → normalize
  • Read-heavy, latency-sensitive → denormalize
  • Mixed → normalize core, denormalize read models

3. Relationship Patterns

PatternRelationalDocumentGraph
One-to-OneForeign key with UNIQUEEmbed subdocumentEdge with cardinality constraint
One-to-ManyForeign key on childEmbed array OR referenceEdge from parent to children
Many-to-ManyJunction/join tableArray of references on both sidesDirect edges
HierarchicalSelf-referencing FKNested documentsRecursive graph traversal

4. Access Pattern Design

Schema design is driven by how data is queried, not just how it's structured:

  1. List your read queries — what does the UI need to display?
  2. List your write queries — what creates/updates data?
  3. Design schema to serve the reads — not the other way around
  4. Index for query patterns — not for every possible query

5. Constraint Strategy

Every schema must enforce:

  • Required fields — NOT NULL / required validators
  • Uniqueness — unique constraints on natural keys (email, SKU, slug)
  • Referential integrity — foreign keys, references, or application-level checks
  • Domain constraints — CHECK constraints, enums, value ranges
  • Cascade behavior — what happens when parent is deleted (CASCADE, SET NULL, RESTRICT)

6. ID Strategy

StrategyWhen to Use
UUID v4Default choice. No ordering, globally unique, no collision
UUID v7When you need time-sortable UUIDs (better index performance)
Auto-incrementSimple cases, single-database, non-distributed
ULIDTime-sortable, lexicographically sortable, URL-safe
Natural keyWhen domain provides a unique identifier (ISBN, SSN) — use with caution

Schema Design Checklist

  • Identify entities and relationships
  • Choose ID strategy
  • Apply normalization rules (or consciously denormalize with rationale)
  • Define primary keys for all entities
  • Create foreign keys / references for relationships
  • Add constraints for data integrity
  • Select appropriate data types
  • Plan indexes for common queries
  • Design for scalability
  • Document entity purposes and relationships
  • Plan for schema evolution

Common Pitfalls

❌ Don't skip normalization for convenience ❌ Don't use unbounded text types for all string fields ❌ Don't forget referential integrity constraints ❌ Don't use mutable natural keys as primary keys ❌ Don't store computed values without a cache invalidation strategy ❌ Don't design schema without knowing query patterns

✅ DO use UUIDs or equivalent for primary keys ✅ DO normalize data unless you have a measured performance reason not to ✅ DO add validation constraints at the schema level ✅ DO index foreign keys and common query fields ✅ DO use timestamps for audit trails


Persistence Map Interview

This interview runs during /create-prd-stack Sub-steps A–E. It maps every feature to its query types, then selects the right store for each query type.

Sub-step A — Feature-to-Query Table

Walk through every major feature in ideation-index.md and ask: "What does this feature need to find, store, relate, and rank/search?"

Build the following table:

FeatureFindStoreRelateRank/Search
(from ideation-index.md)…………

Present and confirm the table with the user before proceeding to Sub-step B.

Sub-step B — Registry-First Skill Search

Before presenting any store options, read .claude/skills/find-skills/SKILL.md and run npx skills find [query type or store name] for each query type that appeared in the table.

If the registry returns a skill, install it first. The bundled skill library is a fallback only.

Sub-step C — Store Selection Per Query Type

Present store options only for query types that appeared in the table:

  • Skip DATABASE_VECTOR if no Rank/Search requirement appeared.
  • Skip DATABASE_GRAPH if no Relate requirement appeared.

Use constraint-first per-axis flow: constraint questions → filter → present → confirm.

Sub-step D — Bootstrap Per Confirmed Store

For each confirmed store, fire bootstrap with its specific sub-key:

  • e.g., DATABASE_PRIMARY=PostgreSQL, DATABASE_VECTOR=Qdrant
  • One bootstrap call per sub-key.
  • Each confirmation adds a database skill to the Databases column of the relevant surface row in the surface stack map.

Sub-step E — Write Persistence Map

After all stores are confirmed, write to .memory/wiki/specs/architecture-draft.md as a locked section titled ## Persistence Map.

Must include:

  • The feature-to-query table from Sub-step A
  • A mapping of each query type to its canonical store with rationale

Cross-Store Entity Consistency Protocol

Triggering Rule

This protocol runs for every entity that spans more than one store.

The 4 Questions

For each cross-store entity, answer the following in order:

  1. Canonical ID — Single identifier tying representations together. Must be the primary store's UUID stored as a property in every other store — never the graph store's or vector store's internal ID.

  2. Creation sequence — Which store is written first. Recovery mechanism for partial write failures (Saga pattern, compensating transaction, or async retry queue — name which).

  3. Deletion cascade — Cleanup order, mechanism (application-layer sequential deletes, DB-level triggers, or background job — name which).

  4. Read strategy — Whether a read requires data from multiple stores. Name the application-layer join pattern explicitly.

Skill Instruction

Read all database skills listed in the Databases column of the surface stack map (.claude/instructions/tech-stack.md) for advice on each store's transaction semantics and consistency guarantees before completing this step.

Output

Write the completed cross-store consistency table to architecture-draft.md as part of the ## Data Strategy section.

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Audit and improve web accessibility following WCAG 2.1 guidelines. Use when asked to "improve accessibility", "a11y audit", "WCAG compliance", "screen reader support", "keyboard navigation", or "make accessible".

日本語の概要は準備中です。原文の説明を表示しています。

RepairYourTech/cfsa-antigravity62026年8月16日 更新

Structured methodology for adversarial thinking — generating attack scenarios, abuse cases, race conditions, and security edge cases against specs and implementations. Produces spec-level gap items, not code-level fixes.

日本語の概要は準備中です。原文の説明を表示しています。

RepairYourTech/cfsa-antigravity62026年8月16日 更新

Orchestrate multiple Antigravity skills through guided workflows for SaaS MVP delivery, security audits, AI agent builds, and browser QA.

日本語の概要は準備中です。原文の説明を表示しています。

RepairYourTech/cfsa-antigravity62026年8月16日 更新

Master REST and GraphQL API design principles to build intuitive, scalable, and maintainable APIs that delight developers. Use when designing new APIs, reviewing API specifications, or establishing API design standards.

日本語の概要は準備中です。原文の説明を表示しています。

RepairYourTech/cfsa-antigravity62026年8月16日 更新

Manage API versioning and evolution with URL/header/query strategies, deprecation workflows, breaking change classification, sunset headers, and consumer-driven contract testing. Use when designing versioning strategy, deprecating endpoints, or evolving API contracts.

日本語の概要は準備中です。原文の説明を表示しています。

RepairYourTech/cfsa-antigravity62026年8月16日 更新

Analyzes codebase structure, data flow, module relationships, and key patterns to generate and maintain a living architecture document (ARCHITECTURE.md).

日本語の概要は準備中です。原文の説明を表示しています。

RepairYourTech/cfsa-antigravity62026年8月16日 更新

RepairYourTech のスキルをすべて見る

このスキルの問題を報告する