agentleFS
DataArtDataArt/artisyn-log-hub/.claude/skills/migrations-data-integrity/SKILL.md

migrations-data-integrity

Skill12 starsChanged 7 days agoMITView on GitHub

ALWAYS when you do drizze migrations of something that touch data schema or data

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

    If you change drizzle migrations - update schema or you do some data migrations.

    line 6
  2. Distinctive:

    Do this on implementation plan stage

    line 12
  3. Distinctive:

    When a plan contains one:

    line 26
  4. Distinctive:

    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 …

    line 39
  5. Distinctive:

    Keep all logic in the application code.

    line 53
  6. Very specific:

    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 …

    line 66

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

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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 … SELECT over 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:

  1. Write it down separately — its own ### Heavy migration subsection 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.
  2. 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.
  3. 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.
  4. 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.

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.