migrations-data-integrity
Skill12 starsChanged 7 days agoMITView on GitHub
ALWAYS when you do drizze migrations of something that touch data schema or data
In this repository28 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- adlc-scriptingSkill
- architect-assistantSkill
- big-prod-e2e-testSkill
- ceSkill
- changelogSkill
- check-fix-buildSkill
- db-state-updateSkill
- git-branchingSkill
- github-issuesSkill
- hook-debuggingSkill
- morning-checkSkill
- nodejs-scriptSkill
- pocSkill
- post-impl-check-client-component-sizeSkill
- post-impl-check-cost-calc-no-autoSkill
- post-impl-check-indexesSkill
- post-impl-check-kb-actualSkill
- post-impl-check-migrationsSkill
- post-impl-check-performance-no-autoSkill
- post-impl-check-security-no-autoSkill
- security-checkSkill
- server-e2e-testsSkill
- session-kb-suggestSkill
- sql-reviewSkill
- ui-componentsSkill
- update-install-instructionsSkill
- use-playwrightSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 5 are distinctive, and 1 is 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.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 6
If you change drizzle migrations - update schema or you do some data migrations.
- Distinctive: line 12
Do this on implementation plan stage
- Distinctive: line 26
When a plan contains one:
- Distinctive: line 39
If it ships: make it resumable and batched (a crash or an OOM mid-way must not lose work or restart from zero), bounded in memory per …
- Distinctive: line 53
Keep all logic in the application code.
- Very specific: line 66
Never edit, rename or delete a migration .sql file (or an existing meta/_journal.json entry) once it is committed — not even a comment, and …
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 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.
Files
If you change drizzle migrations - update schema or you do some data migrations. Analyze - can this break production data base schema or data.
You do not have access to it directly. So do additional analysis turn of this particular case Try to figure out possible edge cases in data and if it can break data
Do this on implementation plan stage
Heavy migrations: call them out, ask, look for a way around
A migration is heavy when deploying it makes the server rework a large share of the existing data, at migration time or in the background after start. Examples:
- a full-table
UPDATE/INSERT … SELECTover a big table (logs,logs_otel,otel_calls, …); - bumping a version stamp that re-queues work for every row (
OTEL_PROJECTION_VERSION, a re-extraction / re-classification / backfill version) — this one is easy to miss, because the migration file itself can be empty; - building an index or rewriting a column on a big table;
- an irreversible drop of tables or columns that still hold data.
When a plan contains one:
- Write it down separately — its own
### Heavy migrationsubsection in the plan (and one line in the chat when you present the plan), not a bullet buried in External surface → DB. Say what is reworked, how many rows on a large install, and an estimate of time, CPU, memory and disk on the smallest install Log Hub supports (a Raspberry Pi-class box: 1 GB RAM, slow SD card, a memory-limited app container with several workers), not on the dev machine. - Look for a way without it first and write down what you considered: a targeted pass that touches only the rows that need the new data, reading the value lazily on read, writing it only for new data and leaving history as it is, a cheaper extraction that does not redo the whole pipeline. Choose the heavy path only when none of these works.
- Ask the user to confirm explicitly that the heavy migration is wanted, quoting the estimate — never let it ship as a side effect of another change.
- If it ships: make it resumable and batched (a crash or an OOM mid-way must not lose work or restart from zero), bounded in memory per batch, and logged with progress, so an operator can see it is moving.
Observed 2026-11-25 (2026-11-24-otel-session-tags): bumping OTEL_PROJECTION_VERSION 2 → 3 only
to backfill session tags re-queued all 21 k OTEL chunks of a small install; on a Pi-class box that
meant hours of 100 % Postgres CPU, a 12 s session list and one worker heap OOM, while reading only
the resource attributes would have been enough.
Once a new migration is applied to the local dev DB, follow the db-state-update skill: comment
new tables / non-obvious columns with COMMENT ON and regenerate docs/knowledgebase/db_state.sql.
No stored procedures, functions or triggers
Keep all logic in the application code. A migration must not create a stored procedure, a
plpgsql/SQL function, or a trigger — and a plan must not design one. Anything a trigger would
enforce (revision counters, hash invalidation, audit columns, cascades beyond FK ON DELETE) is
written explicitly in the SQL of every write path. One-off DO $$ … $$ blocks for idempotent DDL
inside a migration are fine — they create no persistent DB object.
Temporary exception: logs_body_guard() and its trigger logs_body_guard on logs (with the
sequence logs_body_rev_seq), added in migration 0096_logs_streaming_skip_tombstones.sql by task
2026-11-23-session-logs-streaming. They are scheduled for removal in a separate task — do not
copy the pattern, and do not add new logic that depends on the trigger.
Migrations are immutable
Never edit, rename or delete a migration .sql file (or an existing meta/_journal.json entry)
once it is committed — not even a comment, and not in an unpushed commit (no --amend fix).
The same holds for an uncommitted migration once it has been locked and applied anywhere (dev DB,
scenario stand, a check's throw-away DB): treat it as shipped. A wrong text inside the file — a
-- comment, a stale class name — just stays as it is. A wrong COMMENT ON TABLE/COLUMN that
needs fixing in the DB ships as a new comments-only migration (COMMENT ON replaces the old text),
never as an edit of the old one.
Drizzle does not re-check applied migrations: on an already-migrated database the edit is never
applied, while a clean database gets a different schema. Every DB change is a new migration,
followed by npm run migrations:lock (from server/) to append its row to
server/drizzle/migrations/meta/migrations.lock.json (append-only, never hand-edited).
Enforced three ways, with no bypass flag: the .githooks/pre-commit hook
(scripts/migrations-lock.js --pre-commit), the reconciliation test
scripts/__tests__/migrations-lock.test.js (npm run test:scripts) and the server startup check
(server/src/database/migration-lock-check.ts), which refuses to start when an applied migration's
hash is not in the manifest.
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
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.

