agentleFS
tadoEngtadoEng/web-starter/.claude/skills/db-migration/SKILL.md

db-migration

Skill2 starsChanged 4 months agoMITView on GitHub

Change this product's database schema safely via Alembic. Use when asked to add or alter a table or column, add an index or constraint, backfill data, or drop something from the database.

6 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

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

  • 0

    Common

    Most of the 5 edited versions we read keep these.

  • 4

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

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

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

    Check docs/DECISIONS.md. If it says Google Sheets, this skill does not apply — there is no Alembic and no app/models/.

    line 13
  2. Distinctive:

    Alembic is the only path: Never run DDL against a database by hand, and never against production regardless of who asks.

    line 22
  3. Distinctive:

    Add or update the affected tests.

    line 44
  4. Distinctive:

    Expand/contract for any table with real data: Add the column, backfill, switch reads — then drop in a *later* migration.

    line 51
  5. Distinctive:

    Every query stays bounded: If this migration enables a new read path, check it paginates.

    line 56
  6. Very specific:

    Add an entry to the destructive migration log in docs/OPERATIONS.md: what data is lost, whether it is recoverable, and the rollback …

    line 64
  7. Very specific:

    Test against a branch, not production.

    line 71

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

Database migration

First: which persistence profile is this repo on?

Check docs/DECISIONS.md. If it says Google Sheets, this skill does not apply — there is no Alembic and no app/models/. A schema change is: add the column to the sheet, update the header resolver in app/store/sheets.py, update the Pydantic schema, regenerate the client. Record any rename in docs/OPERATIONS.md — it is a breaking change even without a migration, and the header resolver is what makes it survivable. Then stop; the rest of this file is Postgres-only.

Postgres

Alembic is the only path. Never run DDL against a database by hand, and never against production regardless of who asks.

Steps

  1. Change the SQLAlchemy model in backend/app/models/.
  2. Generate:

    cd backend && alembic revision --autogenerate -m "describe the change"
  3. Read the generated file before committing it. Autogenerate reliably gets enum changes, server defaults, and index names wrong. This step is not a formality.
  4. Apply locally and confirm:

    alembic upgrade head
  5. Add or update the affected tests. A migration with no test touching the new column is a column nobody has proven works.
  6. ./scripts/verify.sh

Safety rules

  • Expand/contract for any table with real data. Add the column, backfill, switch reads — then drop in a later migration. Two safe deploys beat one clever one.
  • Multi-step invariants go in one transaction, inside a service function. If two writes must both land or neither, they are one unit of work.
  • Indexes ship with the migration that creates the query pattern, not later.
  • Every query stays bounded. If this migration enables a new read path, check it paginates.

Destructive changes

Dropping a column or table is a data deletion, even if the code stopped reading it last week. Before writing one:

  1. Confirm nothing reads it — search the whole repo, not just the obvious module.
  2. Add an entry to the destructive migration log in docs/OPERATIONS.md: what data is lost, whether it is recoverable, and the rollback procedure.
  3. Confirm the Neon restore window covers the mistake you might be about to make.
  4. Say plainly in your summary that the change is destructive and irreversible. Don't bury it.

Neon branches

Test against a branch, not production. Branches are instant and cheap — that is what they are for. If the Neon plugin is installed, create the branch through it and point your local DATABASE_URL at it.

Deploying

Migrations run as a deliberate step before the revision that needs them — never at container start, where concurrent Cloud Run instances race each other.

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.