safe-migrations
Skill1 starsChanged 41 days agoMITView on GitHub
Use when writing or reviewing a database schema migration, backfill, or data fix, especially on a table that is large or in constant use
1 other project uses a version of this.
Adopted by
Most recently taken up by
- TylerAkins/ai-agent-skillstheir own version, first seen Oct 15, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- TylerAkins/ai-agent-skills★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository5 other files it gives its agents.
- snippets/CLAUDE.mdCLAUDE.md
- idempotencySkill
- money-handlingSkill
- timeouts-and-retriesSkill
- transaction-boundariesSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
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 21
Use expand and contract. Add the new column, deploy code that writes both, backfill, switch reads, and drop the old column in a later …
- Very specific: line 76
Run it in a loop. After each batch set :last_id to the largest returned id, pause briefly, and stop when it returns no rows.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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
Safe migrations
Most migration outages are not wrong SQL. They are correct SQL that takes a lock the application cannot live without, or that runs for an hour. This skill assumes PostgreSQL. Check your version where noted.
When to use
- Any
ALTER TABLE,CREATE INDEX,UPDATE, orDELETEshipped as a migration. - Adding a constraint, changing a type, renaming or dropping a column.
Checklist
- Set
lock_timeout(and usuallystatement_timeout) in the migration, so it fails fast instead of queueing behind a long query and blocking everything behind it. - Build indexes with
CREATE INDEX CONCURRENTLY. It cannot run inside a transaction block, so the migration tool must run it outside one. For a unique constraint, buildCREATE UNIQUE INDEX CONCURRENTLYfirst, thenADD CONSTRAINT ... UNIQUE USING INDEX. A failed concurrent build leaves an INVALID index behind: drop it and retry. - Add CHECK and foreign-key constraints in two steps: add
NOT VALIDfirst, thenVALIDATE CONSTRAINT. Validation takes a weaker lock that does not block reads or writes, but only if it commits separately from theADD CONSTRAINT. Flyway (per migration) and Liquibase (per changeset) wrap the statements in one transaction by default, which would hold the strong lock fromADD CONSTRAINTthrough the whole validation scan. Run the two statements in separate transactions (or in autocommit). SET NOT NULLscans the whole table under a strong lock. On PostgreSQL 12 and later it skips the scan if a validatedCHECK (col IS NOT NULL)already exists, so add that first.- Use expand and contract. Add the new column, deploy code that writes both, backfill, switch reads, and drop the old column in a later release. Never rename or drop in the same release that stops using the column.
- Backfill in small batches with keyset pagination, throttled and resumable, outside the schema migration. One
UPDATEover a whole table is one huge transaction. - State the rollback. If the migration is forward-only, say so and say why.
- Time it against production-sized data, not a dev database with 200 rows.
Bad example
CREATE INDEX idx_payments_status ON payments (status);
UPDATE payments SET status = 'DONE' WHERE settled_at IS NOT NULL;
ALTER TABLE payments ALTER COLUMN reference SET NOT NULL;What to flag
CREATE INDEXwithoutCONCURRENTLYblocks all writes topaymentswhile it builds.- The
UPDATErewrites every matching row in one transaction: long locks, table bloat, replication lag. SET NOT NULLdoes a full scan under an exclusive lock.- No
lock_timeout, so any of these can queue behind a long-running query and stall the whole table.
Good example
-- Start every migration below with: SET lock_timeout = '3s';
-- migration 1, run outside a transaction block
CREATE INDEX CONCURRENTLY idx_payments_status ON payments (status);
-- migration 2
ALTER TABLE payments
ADD CONSTRAINT payments_reference_nn CHECK (reference IS NOT NULL) NOT VALID;
-- migration 3, a separate transaction: validation scans the table without blocking writes
ALTER TABLE payments VALIDATE CONSTRAINT payments_reference_nn;
-- migration 4
ALTER TABLE payments ALTER COLUMN reference SET NOT NULL; -- PostgreSQL 12+: no full scan
ALTER TABLE payments DROP CONSTRAINT payments_reference_nn;Backfill as a separate, repeatable job:
WITH batch AS (
SELECT id FROM payments
WHERE id > :last_id AND settled_at IS NOT NULL AND status IS DISTINCT FROM 'DONE'
ORDER BY id
LIMIT 5000
)
UPDATE payments p SET status = 'DONE'
FROM batch
WHERE p.id = batch.id
RETURNING p.id;Run it in a loop. After each batch set :last_id to the largest returned id, pause briefly, and stop when it returns no rows. It is safe to stop and restart.
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.

