agentleFS
kennguyen887kennguyen887/agent-foundation/skills/database-migrations/SKILL.md

database-migrations

Skill1 starsChanged 5 months agoMITView on GitHub

Use when adding or changing a DB migration or schema, running migrations, or debugging null/missing response fields after a migration — the migration rules (additive, reversible, immutable, seed-vs-migration, push filters into SQL) and the "null fields = unapplied migration" gotcha.

52 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use deployment-patterns, postgres-patterns and 10 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.
  • royaluniondesign-sysSkill

    deployment-patterns

    Deployment workflows, CI/CD pipeline patterns, Docker containerization, health checks, rollback strategies, and production readiness checklists for web applications.

    Also in 6 projects that use this

  • nek1987Skill

    postgres-patterns

    PostgreSQL patterns for reviewing migrations and writing efficient queries. Use when reviewing Alembic migrations, optimizing queries, or debugging database issues.

    Also in 7 projects that use this

  • nek1987Skill

    redis-patterns

    Upstash Redis patterns for caching and rate limiting.

    Also in 3 projects that use this

  • HABUBUSSSkill

    backend-patterns

    Backend architecture patterns, API design, database optimization, and server-side best practices for Node.js, Express, and Next.js API routes.

    Also in 9 projects that use this

  • seikaikyoSkill

    fastapi-patterns

    FastAPI + SQLModel + Neon PostgreSQL 後端開發最佳實踐。適用於 Render 部署的 API 服務。涵蓋路由設計、資料庫操作、錯誤處理、認證授權。

    Also in 3 projects that use this

  • SentrySkill

    react-testing

    Write and review React/TypeScript tests for Sentry's frontend using Jest and React Testing Library. Use when adding or editing tests in static/ (*.spec.tsx), writing component/hook tests, mocking API responses with MockApiClient, testing routing or network requests, or when asked to "write a frontend test", "add a React test", "test this component", or "fix a flaky RTL test".

    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, 3 are distinctive, and 4 are very specific to this project.

  • 0

    Common

    Most of the 48 edited versions we read keep these.

  • 3

    Distinctive

    This author's own choices. Worth a look.

  • 4

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    NEVER alter database schema manually — always generate a migration file.

    line 11
  2. Very specific:

    Every migration MUST be reversible — implement both up and down.

    line 13
  3. Distinctive:

    After generating a migration, verify it runs clean on a fresh DB before committing.

    line 14
  4. Distinctive:

    NEVER seed production-specific data inside migration files.

    line 15
  5. Very specific:

    When API response fields appear as null for a specific record type, check whether the migration that adds those columns has actually been …

    line 23
  6. Very specific:

    Rule: before testing/debugging any feature that reads new DB columns, run pnpm migration:run (or equivalent) on the local DB first.

    line 31
  7. Very specific:

    Before a schema-touching feature is "done": all DB changes have migration files that run on a clean DB.

    line 42

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

Migration rules

  • NEVER alter database schema manually — always generate a migration file.
  • Migration files are IMMUTABLE once merged to main; create a new one to fix, never edit an existing migration.
  • Every migration MUST be reversible — implement both up and down.
  • After generating a migration, verify it runs clean on a fresh DB before committing.
  • NEVER seed production-specific data inside migration files; use dedicated seed scripts. (Migrations = schema/DDL or transforming existing data; seeds = initial/reference or test data/DML — keep them apart.)
  • Push row filters into the SQL WHERE — never fetch broadly and post-filter in application code (rows.filter(...) on a status/type/date condition the DB could evaluate). If the repository helper can't express the condition, extend the helper with an optional query/selector param; don't work around it in the service layer.

Null fields after migration (debugging gotcha)

When API response fields appear as null for a specific record type, check whether the migration that adds those columns has actually been applied before assuming the data was never saved.

Root cause: a new nullable column is added via migration, but the migration hasn't run on the environment being tested. JavaScript's undefined != null evaluates to false (loose equality), so an absent column (undefined) looks identical to a null column in guards like ctx.doc.field != null ? ... : null — both silently return null. Invisible until you inspect the schema.

Rule: before testing/debugging any feature that reads new DB columns, run pnpm migration:run (or equivalent) on the local DB first. If response fields are unexpectedly null, check SHOW COLUMNS FROM <table> before investigating code or data.

Before concluding there's a deployment/CI bug, verify whether the migration file itself was actually merged to a deployed branch. Run git log origin/rc..HEAD --oneline (or equivalent base) — if the migration commit appears there, the columns are absent simply because the PR hasn't merged yet, not because of a pipeline failure. Don't add CI/deployment changes to fix a missing migration that's still on a feature branch.

Migration-related release readiness

Before a schema-touching feature is "done": all DB changes have migration files that run on a clean DB; pending migrations have been applied on the local DB before testing schema-dependent features. (Full release checklist → release-safety skill.)

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.