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

software-database-design

Designs database schemas, migrations, and data models for PostgreSQL, MySQL, MongoDB, and Redis. Use when planning tables, relationships, indexes, or ORM-backed schema changes.

インストール方法を見る

含まれるファイル(16)

  • SKILL.md17.0 KB
  • agents/openai.yaml371 B
  • data/sources.json11.4 KB
  • learnings.consolidated.md600 B
  • learnings.md356 B
  • references/indexing-strategy.md2.7 KB
  • references/migration-strategies.md14.5 KB
  • references/mongodb-atlas-ai-context.md3.8 KB
  • references/nosql-modeling.md5.3 KB
  • references/orm-framework-guide.md1.9 KB
  • references/partitioning-and-pooling.md4.2 KB
  • references/schema-design-patterns.md30.1 KB
  • references/schema-design-scenarios.md5.9 KB
  • references/sharding-decision-framework.md14.6 KB
  • references/storage-paradigm-selection.md5.9 KB
  • references/transactions-and-storage-engines.md31.5 KB

SKILL.md(原文)

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

Database Design

Schema design, data modeling, migration safety, and ORM patterns. This skill covers structural decisions — what tables exist, how they relate, how schemas evolve. For tuning queries on an existing schema, use data-sql-optimization.

Quick Reference

TaskDefault PicksNotes
Relational databasePostgreSQL (a supported stable major)Transactions, complex queries, JSON support; verify the supported major at https://www.postgresql.org/support/versioning/
Relational (MySQL family)A supported MySQL LTS seriesUse an LTS series for production, not an Innovation release; Innovation releases use calendar versioning, so the version number alone does not tell you the track. Check which series are LTS and their support end dates at https://dev.mysql.com/doc/mysql-lts-innovation-release-model/en/ before naming a version
Embedded / edge relationalSQLiteRelease train moves fast (monthly point releases); pin a version, don't chase latest blindly
Flexible schemaMongoDB (a supported major)Rapid iteration, embedded relationships; verify the major at https://www.mongodb.com/docs/manual/release-notes/
Caching / sessionsRedisEphemeral data, counters, pub/sub
Graph traversalsNeo4jRelationship-heavy queries (social, fraud)
Time-seriesTimescaleDB, InfluxDBMetrics, IoT, event streams
Managed app backend../software-baas-platforms/SKILL.mdUse when auth, realtime, storage, and functions are part of the platform choice
Schema migrationsexpand-contract patternZero-downtime changes
ORMPrisma, Drizzle, SQLAlchemy, EF CoreMatch stack; review generated SQL
Vector similaritypgvector (co-located with PostgreSQL)Start with exact search; add HNSW when measured latency requires ANN, then test recall under filters. See storage selection.
Full-text search as the productElasticsearch / OpenSearchFor relevance and facets beyond the database's text search; see software-search.

When to Use This Skill

  • Design table/collection schemas and normalization strategies
  • Model relationships (1:N, M:N, polymorphic associations)
  • Plan zero-downtime migrations (expand-contract)
  • Define indexing strategies based on access patterns
  • Configure ORMs and avoid common anti-patterns
  • Choose between relational, document, key-value, and graph databases

When NOT to Use This Skill

ProblemGo here
Query optimization on existing schemasdata-sql-optimization
Backend service implementationsoftware-backend
Managed app backend platform (Supabase, Convex, Firebase, Appwrite, PocketBase)software-baas-platforms
SwiftData/Core Data schemas mirrored to CloudKitsoftware-ios-native
On-device iOS semantic/vector retrievalsoftware-ios-ai-engine
Data lake or warehouse architecturedata-lake-platform
Streaming or real-time pipelinesdata-streaming
System-level data architecture decisionssoftware-architecture-design

Workflow

  1. Define the entities, access patterns, integrity constraints, and migration constraints first.
  2. Route query tuning, backend implementation, or lakehouse design to the adjacent skill when schema design is not the real problem.
  3. Choose the data model and normalization stance from the decision tree.
  4. Apply the migration, indexing, and ORM guidance needed for the target stack.
  5. Validate current engine-specific behavior with the navigation references before final recommendations.

Decision Tree

1) Identify entities and their relationships
2) Choose data model:
   - Relational (PostgreSQL, MySQL) for structured data with complex joins
   - Document (MongoDB) for flexible schemas with embedded relationships
   - Key-value (Redis) for caching, sessions, counters
   - Graph (Neo4j) when variable-depth traversals or path queries dominate
3) Normalize to 3NF by default; denormalize with justification
4) Define primary keys, foreign keys, and constraints
5) Plan indexing strategy based on access patterns
6) Design migration path (can it be applied with zero downtime?)

For the full relational vs. graph vs. vector decision matrix, see references/storage-paradigm-selection.md.

Normalization Decision Table

SituationApproachRationale
Transactional data (orders, users)Normalize to 3NFData integrity, reduce anomalies
Read-heavy dashboardsDenormalize or materialized viewsQuery performance
Audit logsAppend-only, denormalizedImmutability, query speed
User preferences/settingsJSON column or documentFlexible schema, rarely joined
Hierarchical data (categories, org charts)Adjacency list or materialized pathQuery pattern determines choice
Many-to-many with attributesJunction table with columnsClean modeling

When to stop normalizing. Keep independently managed entities separate. If measured queries repeatedly rejoin fields with no independent lifecycle, consider a combined table or a cached field with an explicit invalidation owner. Treat denormalization as an operational decision because copies can drift.

The "one big table + JSON" failure mode. JSON is useful for variable, rarely joined attributes. Repeated filters on an inner field may need an expression or GIN index, but JSON keys still lack ordinary foreign-key integrity; if an attribute becomes central to joins or constraints, promote it to a typed column. Validate the real predicates with EXPLAIN before changing the model.

Migration Safety Checklist

  • Migration runs while the application serves traffic
  • Lock level and duration checked for each DDL operation; PostgreSQL ALTER TABLE subcommands do not all take the same lock (see migration strategies)
  • Every DDL statement runs with SET lock_timeout (a few seconds) and SET statement_timeout, plus a retry loop — lock requests queue in arrival order, so even a fast ACCESS EXCLUSIVE request queues behind, and then blocks, every later reader/writer if it waits behind a long-running transaction. Check pg_stat_activity for long-running transactions on the target table before running DDL.
  • New columns are nullable, or have a constant default (metadata-only since Postgres 11 — no table rewrite), or a volatile/expression default (this one does rewrite the table and holds ACCESS EXCLUSIVE for the duration — treat as high-risk)
  • Schema change is backward-compatible with current application code
  • Rollback plan exists (reverse migration or expand-contract)
  • No already-applied migration edited (fix forward); concurrent index builds outside a transaction; no imports of current application models (rules)
  • Data backfill runs as a separate step, not inside the migration
  • Migration tested against production-sized dataset
  • Foreign key constraints added after data is consistent
  • Migration SQL linted with a tool suited to the stack; generated SQL and online-DDL limitations reviewed (tool choices)

Rule: rules/sql/safety.md loads this invariant when Claude edits a matching file.

Zero-Downtime Migration Pattern (Expand-Contract)

Compatibility Invariant

Write the compatibility matrix before the change: old code on old schema, old code on expanded schema, new code on expanded schema, and rollback code after partial backfill. The expand phase must preserve old reads and writes; backfills must be restartable and observable; the contract phase begins only after production evidence shows no caller depends on the old shape. Treat destructive DDL as final cleanup, not the migration itself.

Phase 1: EXPAND
  - Add new column/table (nullable, no constraints yet)
  - Deploy app code that writes to both old and new
  - Backfill existing data into new structure

Phase 2: MIGRATE
  - Deploy app code that reads from new structure
  - Verify data consistency between old and new
  - Add constraints and indexes on new structure

Phase 3: CONTRACT
  - Deploy app code that only uses new structure
  - Remove old column/table in a follow-up migration
  - Each phase is a separate deployment — never combine

Indexing Strategy

Choose index types from measured access patterns: B-tree by default, GIN/GiST/BRIN only for the query shapes they serve. In composite indexes put equality columns first, then sort, then range (Equality → Sort → Range); do not order by cardinality. Full access-pattern table and indexing rules (partial, covering, BRIN, fillfactor/HOT): references/indexing-strategy.md.

ORM Patterns

Use eager loading to prevent N+1, keep domain logic out of persistence models, review generated SQL, and drop to raw SQL for bulk work and reports. Pattern and anti-pattern tables: references/orm-framework-guide.md.

Partitioning and Connection Pooling

Partition only on measured signals (maintenance time, scheduled retention drops, consistent filtering on the partition key), not because a table "feels big". Transaction-mode poolers break session-scoped state (search_path, advisory locks, session SET), so run migrations over a direct connection. Decision gates and pooler traps: references/partitioning-and-pooling.md.

Known Traps

  • Adding NOT NULL, uniqueness, or foreign-key constraints before a data cleanup and backfill plan exists.
  • Treating a nullable "temporary" column or JSON blob as a harmless stopgap — it becomes permanent schema debt.
  • Planning partitioning, sharding, or exotic indexes before real access patterns and retention rules are measured — see Partitioning Decision Gates.
  • Rolling out schema changes in an order that breaks mixed-version application deployments during blue/green or rolling releases.
  • Assuming ORM migration generators understand operational rollout safety without a manual expand-contract review.
  • For MongoDB retrieval and graph-model traps, load MongoDB Atlas context or NoSQL modeling. For vector-index consistency, load storage selection.

Anti-Patterns

AvoidDo Instead
EAV (Entity-Attribute-Value) tablesJSON columns or document store
Storing money as floatsUse DECIMAL / NUMERIC or integer cents
Soft deletes everywhereUse only when audit trail required; otherwise hard delete
UUID v4 as clustered primary keyUUID v7 (RFC 9562; time-ordered, uuidv7() built in since PostgreSQL 18) or BIGINT GENERATED ALWAYS AS IDENTITY
Storing files in the databaseStore in object storage; keep metadata/URL in DB
No foreign keys "for performance"FK constraints prevent data corruption; index the FK column
One migration per PR with schema + dataSeparate schema migration from data backfill
Graph: indexing every property on every labelIndex only properties used in WHERE/MATCH lookup positions
Graph: generic relationship types (CONNECTED_TO, RELATED)Use specific typed edges (FOLLOWS, OWNS, REPORTS_TO)

Primary-key choice. Default to BIGINT GENERATED ALWAYS AS IDENTITY when one database generates IDs. Use UUIDv7 when clients or multiple services must generate IDs before insertion; its time ordering improves index locality compared with UUIDv4, but exposes approximate creation time. InnoDB's clustered-primary-key trade-off differs from PostgreSQL; see MySQL schema notes.

Scenarios

Worked scenarios S1-S5 (multi-tenant shared vs schema-per-tenant, Postgres expand-contract with online backfill and version-specific NOT NULL steps, high-cardinality index design, soft-delete vs archival, JSONB versioning): references/schema-design-scenarios.md.

S6 — MongoDB Atlas as context layer for AI agents

Full pattern (collection topology, vector index, memory schema, operational checklist): see references/mongodb-atlas-ai-context.md.

Navigation

References

Related Skills

SkillRelationship
data-sql-optimizationQuery tuning on existing schemas
software-backendData access patterns in backend services
software-baas-platformsManaged app-backend platform choice and migration boundaries
software-csharp-backendEF Core data access and migration patterns
software-architecture-designSystem-level data architecture decisions
data-lake-platformAnalytical storage and lakehouse design
software-ios-nativeSwiftData/Core Data + CloudKit persistence in native iOS apps
software-ios-ai-engineOn-device iOS semantic search and local vector retrieval

Primary sources live in data/sources.json.

Verification Gate

Before delivering output:

  • Every referenced table, collection, index, and migration step is internally consistent with the proposed schema.
  • If the repo already contains migration tooling, name the exact validation command; otherwise mark migration validation as unverified.
  • Expand-contract guidance includes rollout order and rollback notes for breaking schema changes.
  • Every referenced schema file, migration path, or ORM config path exists in the repo or is explicitly marked as proposed.

Learnings Loop

When prior decisions or pitfalls are relevant, consult learnings.consolidated.md if present; use learnings.md only for needed history or as the available fallback. Otherwise skip both.

After applying it, if you encountered a pattern worth remembering, a mistake worth preventing, or a domain fact that surprised you, append one dated bullet to learnings.md via agents-skills-feedback-loop/scripts/append_learning.py. Do not modify SKILL.md itself.

レビュー

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

同じリポジトリのスキル

概要と使いどころ

Configures Claude Code hooks and Codex hooks.json/notify. Use when adding PreToolUse guards, Stop hooks, managed hooks, format-on-save, preflight, audits, or worktree/budget hooks.

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

vasilyu1983/AI-Agents-public932026年10月12日 更新

Configures and hardens Claude Code and Codex MCP servers. Use when connecting databases, APIs, SaaS, building servers, or serving a clearance-filtered knowledge base.

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

vasilyu1983/AI-Agents-public932026年10月12日 更新

Owns instruction files: AGENTS.md, CLAUDE.md, personal and repo rules. Use when writing, pruning, auditing them, sharing rules across Claude and Codex, or fixing ignored rules.

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

vasilyu1983/AI-Agents-public932026年10月12日 更新

Creates and audits agent skills: SKILL.md, references, scripts, runtime metadata. Use when writing, validating, or security-reviewing a skill, or fixing truncated skill listings.

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

vasilyu1983/AI-Agents-public932026年10月12日 更新

Adds per-skill learnings loops for dated patterns, mistakes, and domain facts. Use when wiring skill memory, consolidation, or drift audits.

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

vasilyu1983/AI-Agents-public932026年10月12日 更新

Chooses subagent, team, workflow, or debate and launches it on Claude Code or Codex. Use when delegating, running agent review boards, or installing shared agents.

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

vasilyu1983/AI-Agents-public932026年10月12日 更新

vasilyu1983 のスキルをすべて見る

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