agentleFS
arjunprabhulalarjunprabhulal/agent-skills/skills/data/data-modeling/SKILL.md

data-modeling

Skill4 starsChanged 4 months agoMITView on GitHub

Designs the shape of stored data — tables, keys, relationships, constraints, and what the database should enforce rather than the application. Use this whenever the user is creating tables, designing a schema, choosing keys or column types, asking how to represent something in a database, or picking between SQL and a document store. For changing an existing schema safely, use data-migration; for querying it, use sql-queries.

11 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use accessibility, git-workflow and 1 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.
  • ElasticSkill

    accessibility

    Accessibility guidance for Kibana. Use this skill when working with or reviewing EUI components, resolving a11y-related (@elastic/eui) ESLint issues, and ensuring proper use of ARIA attributes, focus management, keyboard interactions, and accessible naming conventions.

    Also in 4 projects that use this

  • Microsoft AzureSkill

    git-workflow

    Squad branching model: dev-first workflow with insiders preview channel

    Also in 3 projects that use this

  • NVIDIASkill

    testing

    Run Python and Rust tests for physicsnemo-curator using uv + pytest with coverage reporting via pytest-cov, and cargo-nextest for Rust tests. Includes benchmark workflows with pytest-benchmark and criterion.

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

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

  • 0

    Common

    Most of the 10 edited versions we read keep these.

  • 7

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Push correctness into the database: Every rule the schema enforces is a rule the application cannot violate, including from a script …

    line 14
  2. Distinctive:

    Ask whether it is *really* one-to-one or one-to-many.

    line 27
  3. Distinctive:

    Money is never a float: Use a decimal type or integer minor units.

    line 37
  4. Distinctive:

    Done when: no column can hold a value that is meaningless for it.

    line 49
  5. Distinctive:

    UUID v7 or ULID over v4: if you use UUIDs — random keys fragment index locality and hurt insert performance at scale

    line 73
  6. Distinctive:

    Done when: every duplicated value has an owner and a sync path.

    line 89
  7. Distinctive:

    History: do you need to know what a value *was*?

    line 95

“Common” is measured: kept by at least 6 in 10 of the 10 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

Data modeling

Schema outlives application code, usually by years. Code gets rewritten; the data stays, and everything written since inherits whatever shape you chose. Wrong data is also far harder to fix than wrong logic — you can deploy a fix for logic, but bad rows are permanent unless you can reconstruct the truth.

Push correctness into the database. Every rule the schema enforces is a rule the application cannot violate, including from a script someone runs at 2am.

1. Model the real relationships

Get cardinality right before anything else — it determines the whole structure.

  • One-to-many: a foreign key on the many side
  • Many-to-many: a join table. Give it its own key and any attributes of the relationship itself
  • One-to-one: usually the same table, unless you are genuinely splitting for access or size reasons

Ask whether it is really one-to-one or one-to-many. "A user has one address" becomes false the moment someone needs a billing address, and retrofitting is a migration. The question to ask is whether the business could ever say "actually, two" — if so, model it as many now.

Done when: each relationship's cardinality reflects the domain, not the current feature.

2. Choose types precisely

The type is a constraint, and a loose type is a bug that has not happened yet.

  • Money is never a float. Use a decimal type or integer minor units. Floating point silently loses cents and the errors accumulate
  • Timestamps with timezone, stored UTC. A naive timestamp is ambiguous forever, and you cannot recover the intent later
  • Dates when it is a date: a birthday is not an instant
  • Native enum or a lookup table, not a free string. A status column with 'active', 'Active', and 'ACTIVE' is inevitable otherwise
  • Text over varchar(n) unless the limit is a real business rule. An arbitrary 255 is a future truncation bug
  • JSON columns only for genuinely unstructured data. JSON is where schema design goes to hide, and you cannot constrain or index it as well

Done when: no column can hold a value that is meaningless for it.

3. Constrain everything you can

  • NOT NULL by default. Make nullability the exception you justify. A nullable column has a third state every query must handle
  • Foreign keys with explicit ON DELETE behaviour. Decide cascade, restrict, or set null deliberately — the default is rarely what you want
  • Unique constraints on anything that must be unique. Application-level uniqueness checks lose the race under concurrency, always
  • Check constraints for ranges and invariants — a quantity that cannot be negative, an end date after a start date
  • Defaults for columns with an obvious one

Nearly every "how did this row get like that?" is a missing constraint.

Done when: an invalid row cannot be inserted by any path.

4. Choose keys carefully

  • A surrogate primary key: auto-increment or UUID — for almost everything. Natural keys change, and a changing primary key is painful
  • Still add the unique constraint on the natural key. The surrogate is for joins; the constraint is for correctness
  • UUID v7 or ULID over v4 if you use UUIDs — random keys fragment index locality and hurt insert performance at scale
  • Never expose sequential IDs in URLs where enumeration matters. See security-analysis

Done when: keys are stable and uniqueness is enforced.

5. Normalise first, denormalise on evidence

Normalise until each fact lives in one place. Then denormalise only where a measured problem requires it, and write down which copy is authoritative and how it stays in sync.

Duplicated data without a stated sync mechanism will diverge. Not might — will.

Legitimate exceptions: a value that must be historically frozen — the price at time of order is genuinely not the current product price, and copying it is correct modelling, not denormalisation.

Done when: every duplicated value has an owner and a sync path.

6. Design for time and deletion

Two things retrofitted painfully:

  • History: do you need to know what a value was? Decide now. Adding history later means you have lost everything before the change. Options: audit table, event log, or valid-from and valid-to columns
  • Deletion: hard delete, or soft delete with a flag? Soft deletes leak into every query and every unique constraint. Choose deliberately, and know your retention and erasure obligations

Done when: the answers to "what was this last month?" and "what does deleted mean?" are explicit.

Report

State the entities, their relationships and cardinality, what the database enforces, and what you deliberately left to the application. Note what would be expensive to change later — that is the part worth a second opinion before it ships.

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.