agentleFS
vekzz-devvekzz-dev/opencode-skills/skills/database-design/SKILL.md

database-design

Skill4 starsChanged 40 days agoMITView on GitHub

General database design principles: modeling, normalization, indexing, naming conventions, migrations, and query optimization. Trigger: Database design, data modeling, schema design, table design, or migration planning.

58 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use intelligent-routing, bash-linux and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • SKB3002Skill

    intelligent-routing

    Automatic agent selection and intelligent task routing. Analyzes user requests and automatically selects the best specialist agent(s) without requiring explicit user mentions.

    Also in 6 projects that use this

  • xenitV1Skill

    bash-linux

    Bash/Linux terminal patterns. Critical commands, piping, error handling, scripting. Use when working on macOS or Linux systems.

    Also in 7 projects that use this

  • xenitV1Skill

    red-team-tactics

    Red team tactics principles based on MITRE ATT&CK. Attack phases, detection evasion, reporting.

    Also in 7 projects that use this

  • pepebot-spaceSkill

    llm-application-dev

    Building applications with Large Language Models - prompt engineering, RAG patterns, and LLM integration. Use for AI-powered features, chatbots, or LLM-based automation.

    Also in 4 projects that use this

  • +8 more from xenitV1

The file

Show its rules and text

We split this skill into the rules it gives an agent

13 rules. 0 are common, 7 are distinctive, and 6 are very specific to this project.

  • 0

    Common

    Most of the 55 edited versions we read keep these.

  • 7

    Distinctive

    This author's own choices. Worth a look.

  • 6

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Before writing any DDL, map the business entities and their relationships.

    line 24
  2. Distinctive:

    Denormalize only: when query performance demands it, and *document why*

    line 47
  3. Distinctive:

    Use the smallest type that fits the data range

    line 51
  4. Very specific:

    Prefer standardized types: TIMESTAMPTZ over TIMESTAMP, UUID or IDENTITY over natural keys

    line 52
  5. Very specific:

    Avoid TEXT/VARCHAR(255) as a default — size columns appropriately

    line 53
  6. Very specific:

    Use DECIMAL for money, not FLOAT

    line 54
  7. Distinctive:

    Prefer database constraints over application-level validation:

    line 67
  8. Very specific:

    Every migration must be reversible (have a down/rollback)

    line 78
  9. Distinctive:

    Never modify a migration that has already been applied to production

    line 80
  10. Very specific:

    Use timestamp-based or sequential naming: 20250531_create_users.sql

    line 81
  11. Distinctive:

    Use EXPLAIN ANALYZE before optimizing

    line 86
  12. Distinctive:

    Prefer set-based operations over row-by-row (cursors)

    line 87
  13. Very specific:

    Use LIMIT / OFFSET for pagination, but prefer keyset pagination for large datasets

    line 88

“Common” is measured: kept by at least 6 in 10 of the 55 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

When to Use

  • Designing a new database schema
  • Reviewing or refactoring existing schemas
  • Planning migrations or data model changes
  • Choosing data types, indexes, or constraints
  • Defining naming conventions for tables, columns, or relationships

Instructions

1. Understand the Domain First

Before writing any DDL, map the business entities and their relationships. Use the conceptual → logical → physical flow:

  1. Conceptual: Entities, relationships, business rules (ER diagram)
  2. Logical: Attributes, keys, normal forms (independent of technology)
  3. Physical: Data types, indexes, partitions, engine-specific features

2. Naming Conventions

ElementConventionExample
Tablessnake_case, pluralusers, order_items
Columnssnake_case, singularcreated_at, email
PKidid BIGSERIAL PRIMARY KEY
FK{singular_table}_iduser_id, order_id
Join table{table1}_{table2}users_roles
Indexesidx_{table}_{column(s)}idx_users_email
Unique constraintuq_{table}_{column(s)}uq_users_email

3. Normalization Quick Reference

  • 1NF: Atomic columns, no repeating groups
  • 2NF: 1NF + all non-key columns depend on the whole PK
  • 3NF: 2NF + no transitive dependencies (non-key → non-key)
  • Denormalize only when query performance demands it, and document why

4. Data Type Selection

  • Use the smallest type that fits the data range
  • Prefer standardized types: TIMESTAMPTZ over TIMESTAMP, UUID or IDENTITY over natural keys
  • Avoid TEXT/VARCHAR(255) as a default — size columns appropriately
  • Use DECIMAL for money, not FLOAT
  • Dialect matters — see references/postgresql.md for pg-specific types (arrays, JSONB, intervals), references/mysql.md / references/mariadb.md for engine quirks, and references/sqlite.md for type affinity rules

5. Indexing Strategy

  1. PKs and FKs — always index FK columns
  2. Query-driven — index columns in WHERE, JOIN, ORDER BY, not arbitrary columns
  3. Composite indexes — leftmost prefix rule applies; order by selectivity
  4. Covering indexes — include columns to avoid table heap lookups
  5. Avoid over-indexing — every index slows writes

6. Constraints Over Code

Prefer database constraints over application-level validation:

CHECK (price > 0)           -- domain integrity
NOT NULL                    -- required fields
UNIQUE                      -- uniqueness
FOREIGN KEY ... ON DELETE   -- referential integrity

7. Migration Patterns

  • Every migration must be reversible (have a down/rollback)
  • One migration = one logical change (add column, create table, etc.)
  • Never modify a migration that has already been applied to production
  • Use timestamp-based or sequential naming: 20250531_create_users.sql

8. Query Design

  • Avoid SELECT * — always name columns
  • Use EXPLAIN ANALYZE before optimizing
  • Prefer set-based operations over row-by-row (cursors)
  • Use LIMIT / OFFSET for pagination, but prefer keyset pagination for large datasets
  • See references/query-optimization.md for execution plans, join strategies, CTEs vs subqueries, N+1, and dialect-specific tips

9. Decision Table

NeedApproach
Simple CRUDNormalized relational model
Reporting / analyticsStar schema (fact + dimension tables)
Time-series dataPartition by time, consider specialized DB
Full-text searchDedicated index (GIN, or external search)
Hierarchical dataAdjacency list, nested sets, or LTREE
Multi-tenantRow-level security or tenant discriminator column

Commands

# Generate migration
migrate create -ext sql -dir migrations create_users

# Run migrations
migrate -database "$DATABASE_URL" up

# Rollback last migration
migrate -database "$DATABASE_URL" down 1

# Review dry-run
migrate -database "$DATABASE_URL" up 1 --dry-run

Dialect References

DatabaseFileKey Differentiators
PostgreSQLreferences/postgresql.mdArrays, JSONB, GIN/GIST, CTEs, window functions, extensions, MVCC
MySQLreferences/mysql.mdStorage engines, AUTO_INCREMENT, locking quirks, EXPLAIN variants
MariaDBreferences/mariadb.mdSequences, WITH optimizations, JSON vs LONGTEXT, thread pool
SQLitereferences/sqlite.mdType affinity, no ALTER COLUMN, WAL mode, embedded constraints

Choose Your Database

RequirementRecommended DB
Complex queries, analytics, JSONPostgreSQL
High-traffic web app, read-heavyMySQL / MariaDB
Embedded, mobile, testing, localSQLite
Need MariaDB-specific features (sequences, thread pool)MariaDB
Full ACID with advanced indexingPostgreSQL
Minimum ops overheadSQLite (embedded) or managed MySQL/PostgreSQL

Anti-Patterns

  • EAV (Entity-Attribute-Value) — almost never the right choice; prefer JSONB or separate tables
  • Polymorphic associations — breaks referential integrity; use concrete join tables
  • Natural keys as PK — they change; use surrogate keys
  • One table for everything — violates 1NF; split by entity
  • Indexes on every column — write performance degrades

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.