agentleFS
aniketshukla1aniketshukla1/sdlc-kit/.cursor/rules/40-database-standards.mdc

sdlc-kit / rules

Cursor rule1 starsChanged 10 days agoMITView on GitHub

Database standards for MySQL models, Alembic migrations, repositories and Elasticsearch code.

The file

We split this 40-database-standards.mdc into the rules it gives an agent

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

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

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

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

    Every foreign key has an index.

    line 14
  2. Distinctive:

    Every schema change = one Alembic migration.

    line 17
  3. Distinctive:

    Never edit a migration that already exists on main.

    line 18
  4. Distinctive:

    Never run migrations against staging or production.

    line 26
  5. Distinctive:

    NEVER change mappings, index settings, analyzers or aliases, and never reindex.

    line 30
  6. Distinctive:

    If the ticket needs it: write the proposal under "Human actions required" in PLAN.md and stop for approval.

    line 31
  7. Very specific:

    Always set size and pagination.

    line 33

≈ “Common” is an estimate: at least 1 in 5 of the 6,668 Cursor rule 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
40-database-standards.mdc
---
description: Database standards for MySQL models, Alembic migrations, repositories and Elasticsearch code.
globs: backend/app/models/**,backend/alembic/**,backend/app/repositories/**,backend/app/search/**
paths: backend/app/models/**,backend/alembic/**,backend/app/repositories/**,backend/app/search/**
alwaysApply: false
---
# Database standards (MySQL + Alembic + Elasticsearch)

## MySQL schema
- Tables: plural `snake_case` (`order_items`). Columns: `snake_case`. Foreign keys: `<entity>_id`.
- Names: index `ix_<table>_<cols>`, unique `uq_<table>_<cols>`, FK `fk_<table>_<col>_<ref>`.
- Types: `VARCHAR(n)` with explicit n; `DECIMAL(p,s)` for money; `DATETIME` stored as UTC; `BOOLEAN`; utf8mb4.
- New tables get `id`, `created_at`, `updated_at`.
- Every foreign key has an index. Columns used in new `WHERE`/`ORDER BY` get an index (note it in the plan).

## Migrations (Alembic)
- Every schema change = one Alembic migration. Never change tables by hand.
- Never edit a migration that already exists on `main`. Create a new one instead.
- `downgrade()` must exactly reverse `upgrade()`, and must be tested.
- Adding a NOT NULL column to an existing table: use `server_default`, or 3 steps
  (add nullable → backfill → set NOT NULL). Write which one in the plan.
- Destructive changes (drop/rename column or table, type narrowing) only if the ticket says so, and never in
  place: expand/contract. Add the new column, write both, backfill, switch reads; drop the old one in its own
  later ticket or sub-task, once no code uses it. Mark them as a risk in PLAN.md.
- Large tables: note the lock/downtime risk in PLAN.md "Risks". Data updates inside a migration run in batches.
- Never run migrations against staging or production.

## Elasticsearch (only if the project has `app/search/`)
- MySQL is the source of truth. ES is a copy for search.
- NEVER change mappings, index settings, analyzers or aliases, and never reindex. Humans only.
  If the ticket needs it: write the proposal under "Human actions required" in PLAN.md and stop for approval.
- Queries live only in `app/search/`. Use filter context for exact matches.
- Always set `size` and pagination. Never request unbounded results.
- Handle ES being down using the project's existing pattern (log + fallback or 503).

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.