agentleFS
pecigonzalopecigonzalo/agent-skills/skills/standards-database/SKILL.md

standards-database

Skill0 starsChanged 4 months agoMITView on GitHub

Use this skill when designing or reviewing database schemas, migrations, indexes, queries, transactions, constraints, backfills, data retention, or data integrity changes, even for a single query or column addition. Use role-data-engineer for analytics pipelines, warehouse models, and event stream design.

The file

Show its rules and text

We split this skill into the rules it gives an agent

16 rules. About 0 are common, 15 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈15

    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. Distinctive:

    Golden Rule: Prefer explicit database integrity over application-only assumptions

    line 12
  2. Distinctive:

    Add constraints where the database can enforce truth

    line 16
  3. Distinctive:

    Put the invariant in the database when the database can express it:

    line 44
  4. Distinctive:

    Prefer expand and contract for live systems.

    line 58
  5. Distinctive:

    Expand: Add the new nullable column, table, or index without touching existing code paths.

    line 60
  6. Distinctive:

    Contract: Remove the old structure in a later, separate change.

    line 64
  7. Distinctive:

    Do not combine steps to save a deploy.

    line 66
  8. Distinctive:

    Check selectivity. An index on a low-cardinality column that the planner skips is maintenance cost with no benefit.

    line 79
  9. Distinctive:

    Verify the index supports the sort and pagination the query uses, not only the filter.

    line 80
  10. Distinctive:

    Check join cardinality. A join that fans out multiplies rows and quietly changes aggregate results.

    line 81
  11. Distinctive:

    Avoid N+1 access patterns unless the loop is bounded and the bound is known.

    line 82
  12. Very specific:

    Look for redundant indexes.

    line 83
  13. Distinctive:

    Keep them short. A transaction is a lock held over time.

    line 86
  14. Distinctive:

    Never hold a transaction open across an HTTP call, a queue publish, or any other network operation.

    line 87
  15. Distinctive:

    Types: Treat time zones, money, and decimal precision as schema concerns.

    line 91
  16. Distinctive:

    Before finalizing database work:

    line 97

≈ “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

Database Standards

Provides: Schema and constraint design decisions, expand/contract migration procedure, query and index review criteria, and transaction safety checks.

Quick Reference

Golden Rule: Prefer explicit database integrity over application-only assumptions

Default Stance:

  • Model the invariant, not just the current UI
  • Add constraints where the database can enforce truth
  • Make migrations incremental, observable, and rollback-aware
  • Index for known access patterns, not guesses

Never: hold a lock across a network call, run an unbounded backfill on a live table, or ship a destructive migration without an explicit decision


Design Decisions

Settle these before changing persistence:

DecisionQuestion to answer
OwnershipSource of truth, lifecycle, retention, deletion semantics
ShapeKeys, uniqueness, nullability, defaults, timestamps, enums
RelationshipsForeign keys, cascade behavior, orphan handling
ConsistencyTransaction boundaries, isolation needs, concurrency conflicts
AccessExpected queries, filters, sort order, cardinality, growth
MigrationDeploy order, backfill plan, rollback, verification
PrivacyPII classification, encryption, masking, audit needs

Application code changes weekly; data outlives it. A missing constraint becomes thousands of rows that violate an invariant nobody can now enforce.


Constraints

Put the invariant in the database when the database can express it:

  • NOT NULL for fields the domain requires.
  • UNIQUE for identity claims, including composite keys that express a grain.
  • Foreign keys with explicit cascade or restrict behavior, chosen deliberately.
  • CHECK constraints for bounded values and cross-field rules.
  • Enum types or check-constrained strings rather than free text for closed sets.

Application-level validation is not a substitute. It runs in one code path; the constraint covers every path, including backfills, admin scripts, and the next service that connects to the same database.


Migration Safety

Prefer expand and contract for live systems. Each step deploys independently and is safe to stop at.

  1. Expand. Add the new nullable column, table, or index without touching existing code paths.
  2. Backfill. Populate in bounded batches, or dual-write from the application while old and new shapes coexist.
  3. Verify. Compare counts, check constraint satisfaction, and confirm application reads return the same results from both shapes.
  4. Switch. Move reads, then writes, to the new shape.
  5. Contract. Remove the old structure in a later, separate change.

Do not combine steps to save a deploy. The value of the pattern is that each step is individually reversible.

Avoid:

  • Long-held locks on tables that serve live traffic. Adding an index or a NOT NULL column can lock writes for the duration; check your engine's behavior and use the concurrent variant where available.
  • Unbounded UPDATE or DELETE statements across large tables.
  • Destructive changes without an explicit decision and a verified backup.
  • Migrations that require old and new application code to be incompatible, because that removes the ability to roll back.

Query and Index Review

  • Confirm the query matches an indexed access path at the expected data volume, using the engine's query plan rather than inspection.
  • Check selectivity. An index on a low-cardinality column that the planner skips is maintenance cost with no benefit.
  • Verify the index supports the sort and pagination the query uses, not only the filter.
  • Check join cardinality. A join that fans out multiplies rows and quietly changes aggregate results.
  • Avoid N+1 access patterns unless the loop is bounded and the bound is known.
  • Look for redundant indexes. An index on (a) is usually unnecessary when (a, b) exists.

Transactions:

  • Keep them short. A transaction is a lock held over time.
  • Never hold a transaction open across an HTTP call, a queue publish, or any other network operation.
  • Choose the isolation level deliberately, and know which anomalies the chosen level allows.
  • Handle serialization failures and deadlocks with a bounded retry, and make the operation safe to repeat.

Types: Treat time zones, money, and decimal precision as schema concerns. Store timestamps with time zone, store money in a decimal or integer minor-unit type, and never in a float.


Checklist

Before finalizing database work:

  • Constraints protect the required invariants
  • The migration runs safely at the target table size, without long locks
  • Old and new application code both work against the intermediate schema
  • Backfill is bounded, resumable, and verifiable
  • Indexes match real read and write paths and do not duplicate existing ones
  • Transactions are short and handle concurrency failures with a safe retry
  • A rollback or forward-fix plan is written down before the change ships
  • Destructive steps are separated into their own later change
  • Tests cover constraints, migration behavior, and representative queries

See also

  • Load standards-security for PII, tenancy, secrets, and audit requirements.
  • Load standards-api-design when persistence choices leak into published contracts.
  • Load role-site-reliability-engineer for production migration and rollback risk.
  • Load role-data-engineer for analytics models, pipelines, and large backfills.
  • Load standards-testing for migration, repository, and integration tests.

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.