agentleFS
tejastn10tejastn10/workbench/skills/design/design-schema/SKILL.md

design-schema

Skill1 starsChanged 2 months agoMITView on GitHub

Design a table or collection before the migration — model the entities and relationships, pick keys and indexes for the real access patterns, decide normalization vs denormalization, name columns to match the domain and the wire layer. Postgres / Mongo / Prisma. Use when adding a feature that needs new storage, when asked to "design the schema / data model", or before writing a migration.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Do this before deployment/data-migration.

    line 8

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “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

Design a schema

Do this before deployment/data-migration. Start from the access patterns, not the entities — how will this data be read and written, how often, by what.

Work through

  1. Entities & relationships — what are the nouns, how do they relate (1:1, 1:N, N:M), what owns what. Draw it.
  2. Keys — natural vs surrogate. Prefer a surrogate PK (id), add unique constraints for the natural keys. UUID vs auto-increment: UUID if IDs are exposed or generated client-side or across services; sequential otherwise.
  3. Access patterns → indexes — for each query the feature needs, name the WHERE / ORDER BY / join columns. Composite index column order = equality columns first, then range/sort. Don't index speculatively; do index the patterns you know.
  4. Normalize by default; denormalize deliberately. A denormalized/derived column is fine when the read path is hot and the write path can keep it consistent — say so in a comment. isNewAccount doesn't need a column if it's created_at > X.
  5. Nullability & defaults — NULL means "unknown/absent", not "zero". Every non-null column needs a default or a value at insert. Timestamps: store UTC, timestamptz.
  6. Constraints in the DB — FKs, CHECK, UNIQUE, NOT NULL. The DB is the last line; don't rely only on app validation.
  7. Enums — a lookup table or a native enum, values matching the domain vocabulary and the wire layer (snake_case at the wire/DB layer, don't mix).
  8. Mongo — embed when the sub-doc is always loaded with the parent and bounded in size; reference when it's large, unbounded, or queried independently. Set the indexes explicitly (MONGO_AUTO_INDEX=false in prod).
  9. Growth — will this table need partitioning / archival / a TTL? Note it now even if you don't build it.

Output

The schema (DDL or Prisma model or Mongo schema), the indexes with the query each serves, and any denormalization decision with its rationale. Hand to deployment/data-migration to sequence the change.

Anti-patterns

  • ❌ Designing entities without listing the queries first.
  • ❌ Indexing every column, or no columns.
  • ❌ Denormalizing with no plan to keep the copy consistent.
  • ❌ Naming that doesn't match the domain language (CONTEXT.md glossary).
  • ❌ Validation only in the app, none in the schema.

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.