cadasto/pgsql-coding-plugin/pgsql-migrations

Claude Code and agent skill by cadasto/pgsql-coding-plugin

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

This skill should be used when a task writes or reviews a migration or DDL that runs against a live PostgreSQL 18 table, such as ALTER TABLE, ADD COLUMN, SET NOT NULL, ADD CONSTRAINT or a foreign key, CREATE INDEX, DROP INDEX or REINDEX on a populated or partitioned table, an INVALID index left by a failed concurrent build, a column type change, a rename or drop, ALTER TYPE ADD VALUE, a backfill, a goose or golang-migrate SQL file, lock_timeout or statement_timeout, a squawk finding, a deploy w…

Install

npx vskill@latest install cadasto/pgsql-coding-plugin/pgsql-migrations

SKILL.md

The same SKILL.md was published earlier as cadasto/pgsql-coding-plugin/pgsql-migrations.

pgsql-migrations: zero-downtime schema changes

Scope: applying DDL to a PostgreSQL 18 table that live traffic reads and writes, so that no statement stalls that traffic or leaves the schema half-changed.

Deterministic backstop: squawk 'migrations/*.sql' on every migration file, with the config from /pgsql-lint-setup; each finding names a rule id from the squawk rules. A clean squawk run is not a safe run: squawk cannot see whether the deploy retries the migration when its lock timeout fires (squawk: applying migrations safely).

Rules

  • Set `lock_timeout` before DDL that takes `ACCESS EXCLUSIVE`, `SHARE ROW EXCLUSIVE` or `SHARE`, and retry on timeout. A statement waiting for a lock also blocks every later request that conflicts with it (`pg_blocking_pids`). An ALTER TABLE queued behind one long transaction therefore stops every SELECT on the table. SET lock_timeout = '1s'; makes it fail fast instead; rerun until it succeeds (`lock_timeout`). Add a statement_timeout too. squawk: require-lock-timeout, require-statement-timeout.
  • Give each slow step its own transaction. A lock is held until the transaction ends (13.3.1), so a quick ACCESS EXCLUSIVE step followed by a table scan in the same transaction holds the strong lock for the whole scan. squawk constraint-missing-not-valid flags NOT VALID and VALIDATE CONSTRAINT in one transaction.
  • Add constraints `NOT VALID`, then `VALIDATE CONSTRAINT` in a later migration. NOT VALID works for foreign-key, CHECK and not-null constraints. Inserts and updates are checked from then on; only the scan of existing rows is skipped. Validation takes only SHARE UPDATE EXCLUSIVE, so reads and writes continue (ALTER TABLE notes). squawk: constraint-missing-not-valid, adding-foreign-key-constraint.
  • Make an existing column NOT NULL after the backfill, through a `NOT VALID` not-null constraint (PG 18). Deploy code that writes the column on every insert and update, backfill, then ADD CONSTRAINT t_c_not_null NOT NULL c NOT VALID, then VALIDATE CONSTRAINT. Added before the backfill, the constraint rejects every update of a row still NULL (ADD CONSTRAINT). A bare SET NOT NULL scans the table under ACCESS EXCLUSIVE (SET NOT NULL, release notes 18). squawk: adding-not-nullable-field.
  • Build, drop and rebuild indexes `CONCURRENTLY`, outside a transaction block. A plain CREATE INDEX blocks writes for the whole build. CONCURRENTLY does not, but it cannot run inside a transaction block, and it waits for every older transaction. Its file sets lock_timeout = 0 and statement_timeout = 0: a short lock_timeout aborts it on a busy system, while its waiting blocks no reads or writes, and a timeout set by an earlier file stays on the session (lock-levels.md). A failure leaves an INVALID index that still slows writes and that IF NOT EXISTS keeps; drop it before a rerun (CREATE INDEX). A partitioned table builds its index ON ONLY the parent, then per partition (5.12.2.2). squawk: require-concurrent-index-creation, require-concurrent-index-deletion, require-concurrent-reindex, ban-concurrent-index-creation-in-transaction.
  • Create a unique or primary key from a concurrent index. CREATE UNIQUE INDEX CONCURRENTLY, then ADD CONSTRAINT ... UNIQUE USING INDEX (ALTER TABLE). squawk: disallowed-unique-constraint, adding-serial-primary-key-field.
  • Know which change rewrites the table. A volatile default, a stored generated column, an identity column, a domain with constraints, or a type change that is not binary coercible rewrites the table and its indexes under ACCESS EXCLUSIVE. A non-volatile default, a virtual generated column and varchar(n) to text do not (ALTER TABLE notes). Turn a rewrite into a new column, a backfill and a switch. squawk: adding-field-with-default, changing-column-type.
  • Rename and drop in two deploys: expand, then contract. While a deploy rolls out, the old application version still runs, and a rename or drop breaks it. Ship code that stops using the old name first; rename or drop in a later migration (squawk `renaming-column`, `ban-drop-column`). DROP COLUMN is quick but frees no space until rows are rewritten (ALTER TABLE notes).
  • Backfill in batches, one transaction per batch, outside the schema migration. Row locks taken by UPDATE last until the transaction ends (13.3.2), so one UPDATE over the whole table holds them all and can outrun statement_timeout. Walk the primary key in ranges (squawk `adding-field-with-default`).
  • Add an enum value in its own migration, before code writes it. A value added inside a transaction block cannot be used until that transaction commits, and there is no DROP VALUE (ALTER TYPE). Give BEFORE or AFTER when the order matters. squawk: require-enum-value-ordering.
  • Match the migration tool's transaction handling. goose runs a file in one transaction unless the file carries -- +goose NO TRANSACTION (goose annotations). golang-migrate sends a file as one Exec, which PostgreSQL runs as one implicit transaction (golang-migrate postgres). A file that runs outside a transaction must be safe to rerun. squawk: prefer-robust-stmts, transaction-nesting.

Column types in new DDL (prefer-identity, prefer-bigint-over-int, prefer-text-field, prefer-timestamptz) belong to pgsql-schema.

Read the reference

The task involvesRead
which lock a statement takes, the lock queue, lock_timeout, statement_timeout, SET versus SET LOCAL, a migration that is waiting right nowlock-levels.md
a recipe for one change: add a column, NOT NULL, CHECK, foreign key, unique or primary key, building or rebuilding an index (also on a partitioned table, and an INVALID leftover), a type change, a rename or drop, an enum value, a backfill, a partition detachpatterns.md
goose or golang-migrate, statements that cannot run in a transaction block, rerunnable files, squawk's assume_in_transactionmigration-tools.md

Sources

  • PostgreSQL 18, explicit locking: <https://www.postgresql.org/docs/18/explicit-locking.html> (checked 2026-10-27)
  • PostgreSQL 18, ALTER TABLE: <https://www.postgresql.org/docs/18/sql-altertable.html> (checked 2026-10-27)
  • PostgreSQL 18, CREATE INDEX: <https://www.postgresql.org/docs/18/sql-createindex.html> (checked 2026-10-27)
  • PostgreSQL 18, ALTER TYPE: <https://www.postgresql.org/docs/18/sql-altertype.html> (checked 2026-10-27)
  • PostgreSQL 18, client connection defaults: <https://www.postgresql.org/docs/18/runtime-config-client.html> (checked 2026-10-27)
  • PostgreSQL 18, session information functions: <https://www.postgresql.org/docs/18/functions-info.html> (checked 2026-10-27)
  • PostgreSQL 18 release notes: <https://www.postgresql.org/docs/18/release-18.html> (checked 2026-10-27)
  • squawk rules and "Applying migrations safely": <https://squawkhq.com/docs/rules>, <https://squawkhq.com/docs/safe_migrations> (checked 2026-10-27)
  • goose annotations: <https://pressly.github.io/goose/documentation/annotations/> (checked 2026-10-27)
  • golang-migrate PostgreSQL driver: <https://github.com/golang-migrate/migrate/blob/master/database/postgres/README.md> (checked 2026-10-27)

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/cadasto/pgsql-coding-plugin/pgsql-migrations/badge)](https://verified-skill.com/skills/cadasto/pgsql-coding-plugin/pgsql-migrations)

Something wrong with this skill or its page? Tell us.