Przejdź do treści
Biblioteka skilli
Programowanie · Przegląd i audyt

migration-review

/migration-review

Sprawdza migracje PostgreSQL pod kątem blokad, przepisywania tabel i ryzyka utraty danych, a ryzykowne kroki zamienia na bezpieczne sekwencje.

Licencja
MIT
Ostatnia zmiana repozytorium
30.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
2
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 30.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Sprawdza migracje PostgreSQL pod kątem blokad, przepisywania tabel i ryzyka utraty danych, a ryzykowne kroki zamienia na bezpieczne sekwencje.

Oryginalny opis (EN)

Reviews PostgreSQL schema migrations for locks, table rewrites, downtime and data-loss risks, and rewrites risky steps into safe expand/contract sequences. Use when a change adds or edits a SQL, Prisma, Drizzle, Knex or Rails migration that targets Postgres.

Jak działa

  1. Steps
  2. Checks
  3. Report format
Sekcje z nagłówków SKILL.md, w oryginale · 54 linii, 623 słów
Podgląd SKILL.md
---
name: migration-review
description: Reviews PostgreSQL schema migrations for locks, table rewrites, downtime and data-loss risks, and rewrites risky steps into safe expand/contract sequences. Use when a change adds or edits a SQL, Prisma, Drizzle, Knex or Rails migration that targets Postgres.
license: MIT
---

# Migration review (PostgreSQL)

A migration is risky when it takes a strong lock on a busy table, rewrites the table, or changes the schema in a way the currently deployed code can't handle. Review every statement against the checks below, then report.

## Steps

1. Find the migration files in the change and read every statement, including ones generated by the ORM.
2. For each statement, look up the lock it takes in [the lock reference](references/postgres-locks.md) and ask: how big is this table, and how hot is it?
3. Run the checks below. For each problem, propose the safe rewrite, not just the warning.
4. Check deploy order: will the app version running *during* the deploy still work against the new schema?
5. Report using the format at the end.

## Checks

**Locks and rewrites**

- `CREATE INDEX` on an existing table blocks writes for the whole build. Use `CREATE INDEX CONCURRENTLY`. It can't run inside a transaction, so if the tool wraps each migration in one, put it in its own non-transactional migration. A failed concurrent build leaves an `INVALID` index: drop it and retry.
- `ADD COLUMN ... DEFAULT <constant>` is metadata-only since PG 11. A **volatile** default (`gen_random_uuid()`, `clock_timestamp()`, `random()`) rewrites the whole table. Add the column without a default, then backfill in batches.
- `ALTER COLUMN ... TYPE` usually rewrites the table under `ACCESS EXCLUSIVE`. Exceptions are binary-compatible changes like widening `varchar(n)` or `varchar` to `text`. Otherwise: add a new column, dual-write, backfill, switch reads, drop the old one.
- `SET NOT NULL` scans the table under `ACCESS EXCLUSIVE`. Safe sequence (PG 12+): `ADD CONSTRAINT c CHECK (col IS NOT NULL) NOT VALID`, then `VALIDATE CONSTRAINT c`, then `SET NOT NULL` (skips the scan), then drop `c`.
- New foreign keys and check constraints: add them `NOT VALID`, then `VALIDATE CONSTRAINT` in a separate step, which only takes `SHARE UPDATE EXCLUSIVE`.

**Lock queueing**

- Any `ACCESS EXCLUSIVE` statement waits behind long-running queries, and every query behind it waits too. That's how a "fast" `ALTER TABLE` takes a site down. Require `SET lock_timeout = '5s'` (or similar) before it, and a retry plan.
- Large `UPDATE`/`DELETE` backfills must run in batches (for example 1-10k rows per transaction, keyed by primary key), never as one statement.

**Compatibility with running code**

- Renaming a column or table breaks the old app version mid-deploy. Use expand/contract: add the new name, write to both, migrate reads, drop the old name in a later release.
- Dropping a column or table: ship the code that stops using it first, drop in a later release. With an ORM, make sure the model no longer selects it.
- Adding a `NOT NULL` column without a default fails if the table has rows, and breaks old code that inserts without it.

**Data loss**

- `DROP`, `TRUNCATE`, type narrowing (`bigint` to `int`, `text` to `varchar(50)`) and `USING` casts can destroy data. Ask whether a backup or a reversible path exists.
- Down migrations that drop data are fine to flag but rarely run. Focus on the up path.

## Report format

```markdown
### Migration review: <file>

| # | Statement | Risk | Lock / effect | Fix |
|---|-----------|------|---------------|-----|
| 1 | CREATE INDEX idx_orders_user ON orders(user_id) | high | SHARE, blocks writes during build | CREATE INDEX CONCURRENTLY in its own migration |

**Deploy order:** <safe as is / needs a code release first because ...>
**Verdict:** safe to merge / safe with the fixes above / needs a redesign
```

Rate risk by table size and traffic: a blocking lock on a 500-row lookup table is low; the same on `orders` is high. Say which assumption you made if you don't know the table size.
Pliki w paczce (2)
  • SKILL.md 4 KB
  • references/postgres-locks.md 2 KB

Wersje

RepozytoriumWynikLicencja
Ta strona · Urthella/backend-agent-skills100MIT
adobe/spectrum-web-components90Apache-2.0

Migawka bazy z 13.11.2026 · wersja paczki 414ee5ebfe39 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 1 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100safe-migrations
    Przegląda i pisze migracje bazy bez blokad tabel, w etapach expand i contract dla PostgreSQL i MySQL. Przydaje się przed komendą resetującą lub usuwającą bazę.
  • 100migration-helper
    Pisze bezpieczne migracje schematu i danych z planem wycofania i sprawdzeniem blokad dla Postgres i MySQL.
  • 90db-migration-safety
    Sprawdza migracje schematu pod kątem bezpieczeństwa produkcji: blokad, przepisywania tabel, backfilli i kolejności wdrożenia.
  • 100database-migrations
    Stosuje bezpieczne migracje baz: zmiany tylko do przodu, etapowe zmiany nazw, indeksy współbieżne i partie uzupełniania danych dla PostgreSQL i Prisma.
  • 84analyze-migrations
    Sprawdza pliki migracji bazy danych pod kątem blokad, utraty danych i przestojów, zanim trafią na produkcję.
  • 100migration-safety-review
    Sprawdza migrację bazy przed wdrożeniem pod kątem blokad tabel, przepisywania wierszy i błędów w działającej aplikacji.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.