Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

postgres-migrations

БесплатноБез исполняемых скриптовНе проверен

Use when changing the database schema - detect the repo's migration tool, ship a new migration in its layout, never edit an applied one, and avoid lock-unsafe…

makifbaysalот makifbaysal★ 123 звезды на GitHub

Об этом скилле

PostgreSQL Migrations

Overview

Migrations are append-only history that must replay identically on every environment, forever. The cardinal sin is editing a migration that has already run somewhere — it makes environments diverge silently. The second most common mistake is DDL that locks a live table for longer than the app can tolerate.

Core principle: a wrong migration is fixed by a NEW migration, never by editing the old one; and rollback_release reverts code only, so the schema your migration leaves behind must keep working with the previous release's code until a later task removes what it replaced.

Detect the repo's migration tool first

Tool How to recognise it Down migration Outside a transaction
golang-migrate *.up.sql / *.down.sql pairs its own .down.sql file each CONCURRENTLY statement needs its own migration file (no implicit transaction wrapping across files)
goose -- +goose Up / -- +goose Down in one file same file, Down section -- +goose NO TRANSACTION directive
Flyway V<n>__name.sql none in the open-source edition follow Flyway's own non-transactional DDL rules
Liquibase changesets (XML/YAML/SQL) rollback block per changeset runInTransaction
Atlas atlas.hcl + versioned migrations — —
Up-only numbered SQL plain numbered .sql files, no down files (e.g. this repo's own server/migrations/) none exists — don't invent one —

Never introduce a different migration tool into a repo that already has one, and never add down files to a repo that has none — follow what's there (rule repo-conventions-win).

Rules

  • Never edit an applied migration. History replays; a divergent edit corrupts environments that already ran it. A wrong migration gets a new one that corrects it.
  • Never rely on Hibernate/JPA auto-DDL (hbm2ddl=update, Quarkus schema generation) outside tests — schema comes from migrations only (java-persistence).
  • Idempotent where it matters: IF NOT EXISTS, ON CONFLICT, WHERE guards on backfills so a re-run does no harm.
  • Add an explicit index for every new query path the code introduces — Postgres does not auto-index foreign-key columns.
  • Start DDL in a live-table migration with SET lock_timeout = '5s'; so a blocked ALTER fails fast and visibly instead of queueing behind other locks and blocking every other statement on the table.

Rollback reality: what rollback_release actually does

rollback_release reverts the application code only — it never runs a down migration. Two consequences:

  1. Expand/contract. Ship additive changes first (new nullable/defaulted column, new table, dual-write) so the schema works with both the old and new code; drop what's no longer needed in a later task once the old code is gone everywhere.
  2. rollback_plan must say whether the down migration is actually safe to run, because by the time anyone reaches for it, the new schema may already hold data the down migration would silently drop. Write what you'd tell the human, e.g. "Migration 045 is additive; reverting the code is enough. Do NOT run its down migration — it drops the priority column and any values written to it since deploy." A migration that is purely additive needs no down-migration caveat at all; say that instead.
  3. golang-migrate caveat: if a commit is reverted and that removes migration 045's files, a database already at version 45 then fails migrate up with "no migration found for version 45" — decide whether to keep the schema (most common) and run migrate ... force 44 to re-sync the tool's bookkeeping, rather than trying to re-apply a file that no longer exists.

Lock-safety: unsafe vs safe DDL on a live table

Change Unsafe (locks / rewrites the table) Safe
Add index CREATE INDEX CREATE INDEX CONCURRENTLY IF NOT EXISTS (its own migration, outside a transaction)
Foreign key ADD CONSTRAINT ... FOREIGN KEY ... (validates existing rows under lock) ... NOT VALID, then VALIDATE CONSTRAINT in a later migration
NOT NULL on an existing column ALTER COLUMN ... SET NOT NULL (full scan under lock on PG <12) CHECK (col IS NOT NULL) NOT VALID → VALIDATE CONSTRAINT → SET NOT NULL (PG ≥12 skips the re-scan once validated); PG 18 also has SET NOT NULL ... NOT VALID directly
Add column A volatile default (DEFAULT now(), DEFAULT random()) rewrites the table A constant default is metadata-only since PG 11; for a volatile default, add the column nullable, backfill, then add the default/constraint
Change column type ALTER COLUMN ... TYPE ... (table rewrite) New column + backfill + switch reads/writes, drop the old one later
Rename or drop column/table RENAME breaks the previous release's code immediately Expand/contract: add the new name, dual-write/read, switch, drop later
Backfill existing rows A single large UPDATE (lo
Полный SKILL.md на GitHub

Установить postgres-migrations в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл postgres-migrations?

Use when changing the database schema - detect the repo's migration tool, ship a new migration in its layout, never edit an applied one, and avoid lock-unsafe DDL on a live table

Как установить скилл postgres-migrations?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл postgres-migrations запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить postgres-migrations с