[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M74G77KZ7ER61DVTGAX707ZB":3,"skill-same:01M74G77KZ7ER61DVTGAX707ZB":44},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":14,"repositoryHtmlUrl":27,"repositoryHomepageUrl":6,"ownerHtmlUrl":28,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":29,"install":30,"resources":43},"01M74G77KZ7ER61DVTGAX707ZB","review-migration",null,"Review a Postgres migration for lock surface, online\u002Foffline safety, backfill strategy — flags ACCESS EXCLUSIVE locks and unsafe defaults on large tables.","MohammadBafkar\u002Fpolymath","MohammadBafkar","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F34940462?v=4","01M74G540TQFZWK6KVAPKFVGNR","Mohammad Bafkar","01M74G541HG19QP9V5DQCJVKYE",0,"MIT","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-backend\u002Fskills\u002Freview-migration\u002FSKILL.md",[],[],"2026-11-11 15:11:14",false,"---\nname: review-migration\ndescription: Review a Postgres migration for lock surface, online\u002Foffline safety, backfill strategy — flags ACCESS EXCLUSIVE locks and unsafe defaults on large tables.\n---\n\n# review-migration\n\n> Review a `.sql` migration the way an on-call reviewer would: which lock does each statement need, how long it holds, and whether it's safe to apply against a live, replicating, big-table prod.\n\n**Mode:** analytical — judgment inside a fixed frame. Keep the output shape; every verdict cites its evidence; unknowns are marked `[TBD]` or `[VERIFY]`, never filled in.\n\n## When to use\n\n- A schema migration is in a PR.\n- A long-lived table needs a structural change and someone has drafted SQL.\n- A previous migration timed out and you're trying to figure out why.\n\n## Inputs\n\n- The migration `.sql` file(s) (required). For ORM migrations, review the generated SQL (`rails db:migrate:status` + `--dry-run`, `alembic upgrade --sql`, `prisma migrate diff --script`), not the DSL.\n- The Postgres major version (required — PG 11 fast defaults and PG 12 `NOT NULL`-via-`CHECK` change the verdict). Unknown: ask; unattended, assume the oldest version the repo supports and say so.\n- Table sizes and write rates (optional) — unknown tables are treated as large and hot.\n\n## Related skills\n\n- [`polymath-backend:migration-plan`](..\u002F..\u002F..\u002Fpolymath-backend\u002Fskills\u002Fmigration-plan\u002FSKILL.md)\n  — vendor-agnostic expand-migrate-contract phasing for online\n  migrations. Plan the phases there; review each Postgres-specific\n  statement here.\n- [`polymath-backend:audit-pg-config`](..\u002Faudit-pg-config\u002FSKILL.md)\n  — review the Postgres server configuration the migration will run\n  against.\n\n## Procedure\n\n0. **Deterministic baseline.** If `squawk` (the Postgres migration linter) is available — `squawk \u003Cfile>.sql`, or `npx squawk-cli` — run it first and fold its rule hits into the statement list; never report a statement as safe that it flags without saying why it doesn't apply.\n1. **Parse statements.** For each statement, identify the locks acquired and held:\n   - `CREATE INDEX` — `SHARE` lock (writes blocked).\n   - `CREATE INDEX CONCURRENTLY` — `SHARE UPDATE EXCLUSIVE` lock (writes ok); cannot run inside a transaction.\n   - `ALTER TABLE … ADD COLUMN` (without default) — `ACCESS EXCLUSIVE`, fast (PG 11+ tracks default separately).\n   - `ALTER TABLE … ADD COLUMN … DEFAULT \u003Cvolatile>` — `ACCESS EXCLUSIVE`, rewrites the table (slow + outage on large tables).\n   - `ALTER TABLE … ADD COLUMN … DEFAULT \u003Cconstant>` (PG 11+) — fast; uses fast-default optimization.\n   - `ALTER TABLE … SET NOT NULL` — `ACCESS EXCLUSIVE`, full scan unless a validated `CHECK (col IS NOT NULL)` constraint already exists (PG 12+ uses it to skip the scan; older versions always scan).\n   - `ALTER TABLE … ALTER COLUMN … TYPE` — `ACCESS EXCLUSIVE` and usually a full table rewrite (binary-coercible changes such as widening a `varchar` are the exception).\n   - `ALTER TABLE … ADD CONSTRAINT … UNIQUE \u002F PRIMARY KEY` — builds the index under `ACCESS EXCLUSIVE`; instead `CREATE UNIQUE INDEX CONCURRENTLY`, then `ADD CONSTRAINT … USING INDEX`.\n   - `ALTER TABLE … DROP COLUMN` — `ACCESS EXCLUSIVE`, metadata-only (fast).\n   - `RENAME` — `ACCESS EXCLUSIVE`, but instant. Watch out for app code still using the old name.\n\n   **Even \"instant\" `ACCESS EXCLUSIVE` statements are dangerous on a busy table**: the lock request waits behind any long-running transaction, and every new query queues behind *it* — a metadata-only change can stall all traffic. That is why step 6's `lock_timeout` is non-negotiable.\n2. **Backfill plan.** If the migration rewrites data:\n   - Batch in chunks with explicit commits. Postgres `UPDATE` has no `LIMIT` — batch by primary-key range or a sub-select:\n     `UPDATE refunds SET currency = 'USD' WHERE id IN (SELECT id FROM refunds WHERE currency IS NULL ORDER BY id LIMIT 10000);`\n   - Run outside the schema-migration tool (which usually wraps in a single tx).\n   - Pace by `pg_sleep` or external orchestration so the WAL backlog stays manageable.\n3. **`NOT NULL` rollout (multi-step).** The safe pattern (PG 12+ for the fast step 4). A `NOT VALID` check is still enforced on every new INSERT\u002FUPDATE — so before step 2, the app must already write the column (or the column needs a `DEFAULT`), or new writes start failing:\n   ```sql\n   ALTER TABLE refunds ADD COLUMN currency text;            -- step 1\n   -- deploy app that always writes currency (or: ALTER COLUMN currency SET DEFAULT 'USD')\n   ALTER TABLE refunds ADD CONSTRAINT refunds_currency_not_null\n     CHECK (currency IS NOT NULL) NOT VALID;               -- step 2\n   -- backfill in batches (see step 2), in its own deploy\u002Fjob\n   ALTER TABLE refunds VALIDATE CONSTRAINT refunds_currency_not_null;  -- step 3\n   ALTER TABLE refunds ALTER COLUMN currency SET NOT NULL; -- step 4 (fast because constraint is valid)\n   ALTER TABLE refunds DROP CONSTRAINT refunds_currency_not_null;\n   ```\n4. **Index migrations.** Always `CONCURRENTLY` for production. Note: `CONCURRENTLY` can fail and leave an `INVALID` index — the review should check there's a cleanup statement (`DROP INDEX IF EXISTS … ; CREATE INDEX CONCURRENTLY …`).\n5. **Foreign keys.** `ADD CONSTRAINT … FOREIGN KEY … NOT VALID` then `VALIDATE CONSTRAINT` later — same pattern as NOT NULL.\n6. **Lock timeout.** Recommend `SET lock_timeout = '5s'` at the top of risky migrations so they fail fast under contention instead of holding the queue.\n7. **Statement timeout.** Likewise `SET statement_timeout = '30s'` for individual statements; backfills set their own batch-scoped timeouts.\n\n## Output\n\n```text\nreview-migration\n\nFile:    db\u002Fmigrations\u002F20260523_add_currency.sql\nTarget:  refunds (≈ 50M rows)\n\nStatements\n  1. ALTER TABLE refunds ADD COLUMN currency text;\n     Lock: ACCESS EXCLUSIVE (fast, metadata-only).                ✓\n\n  2. ALTER TABLE refunds ALTER COLUMN currency SET DEFAULT 'USD';\n     Lock: ACCESS EXCLUSIVE (fast on PG 11+).                     ✓\n\n  3. ALTER TABLE refunds ALTER COLUMN currency SET NOT NULL;\n     Lock: ACCESS EXCLUSIVE; full scan on 50M rows.               ✗ unsafe\n\nIssues\n  - Statement 3 holds ACCESS EXCLUSIVE — blocking reads and writes — for the full scan of a 50M-row table.\n    Fix: split into the 4-step NOT VALID → backfill → VALIDATE → SET NOT NULL pattern.\n\n  - No lock_timeout set. Risk: migration holds the queue if contention spikes.\n    Fix: prepend `SET lock_timeout = '5s';`.\n\nRecommendation: split into 3 deploys (constraint+backfill+set-not-null). Block PR until restructured.\n```\n\n## Quality bar\n\n- Every statement classified by lock + cost.\n- Multi-step pattern named when a single statement is unsafe.\n- `CONCURRENTLY` flagged where it should be present (and not inside a transaction).\n- `lock_timeout` \u002F `statement_timeout` recommendations stated.\n\n## Anti-patterns to avoid\n\n- \"Just add NOT NULL, the table isn't that big\" without measuring. Big tables are big at 3 AM, not at code-review time.\n- `CREATE INDEX` (not CONCURRENTLY) on a live table. Writes blocked for the duration.\n- Wrapping CONCURRENTLY in a transaction. Postgres rejects; the migration tool may obscure the error.\n- Running backfill in a single statement on a 50M-row table. WAL bloat, replica lag, undo time after rollback.\n","# review-migration\n\n> Review a `.sql` migration the way an on-call reviewer would: which lock does each statement need, how long it holds, and whether it's safe to apply against a live, replicating, big-table prod.\n\n**Mode:** analytical — judgment inside a fixed frame. Keep the output shape; every verdict cites its evidence; unknowns are marked `[TBD]` or `[VERIFY]`, never filled in.\n\n## When to use\n\n- A schema migration is in a PR.\n- A long-lived table needs a structural change and someone has drafted SQL.\n- A previous migration timed out and you're trying to figure out why.\n\n## Inputs\n\n- The migration `.sql` file(s) (required). For ORM migrations, review the generated SQL (`rails db:migrate:status` + `--dry-run`, `alembic upgrade --sql`, `prisma migrate diff --script`), not the DSL.\n- The Postgres major version (required — PG 11 fast defaults and PG 12 `NOT NULL`-via-`CHECK` change the verdict). Unknown: ask; unattended, assume the oldest version the repo supports and say so.\n- Table sizes and write rates (optional) — unknown tables are treated as large and hot.\n\n## Related skills\n\n- [`polymath-backend:migration-plan`](..\u002F..\u002F..\u002Fpolymath-backend\u002Fskills\u002Fmigration-plan\u002FSKILL.md)\n  — vendor-agnostic expand-migrate-contract phasing for online\n  migrations. Plan the phases there; review each Postgres-specific\n  statement here.\n- [`polymath-backend:audit-pg-config`](..\u002Faudit-pg-config\u002FSKILL.md)\n  — review the Postgres server configuration the migration will run\n  against.\n\n## Procedure\n\n0. **Deterministic baseline.** If `squawk` (the Postgres migration linter) is available — `squawk \u003Cfile>.sql`, or `npx squawk-cli` — run it first and fold its rule hits into the statement list; never report a statement as safe that it flags without saying why it doesn't apply.\n1. **Parse statements.** For each statement, identify the locks acquired and held:\n   - `CREATE INDEX` — `SHARE` lock (writes blocked).\n   - `CREATE INDEX CONCURRENTLY` — `SHARE UPDATE EXCLUSIVE` lock (writes ok); cannot run inside a transaction.\n   - `ALTER TABLE … ADD COLUMN` (without default) — `ACCESS EXCLUSIVE`, fast (PG 11+ tracks default separately).\n   - `ALTER TABLE … ADD COLUMN … DEFAULT \u003Cvolatile>` — `ACCESS EXCLUSIVE`, rewrites the table (slow + outage on large tables).\n   - `ALTER TABLE … ADD COLUMN … DEFAULT \u003Cconstant>` (PG 11+) — fast; uses fast-default optimization.\n   - `ALTER TABLE … SET NOT NULL` — `ACCESS EXCLUSIVE`, full scan unless a validated `CHECK (col IS NOT NULL)` constraint already exists (PG 12+ uses it to skip the scan; older versions always scan).\n   - `ALTER TABLE … ALTER COLUMN … TYPE` — `ACCESS EXCLUSIVE` and usually a full table rewrite (binary-coercible changes such as widening a `varchar` are the exception).\n   - `ALTER TABLE … ADD CONSTRAINT … UNIQUE \u002F PRIMARY KEY` — builds the index under `ACCESS EXCLUSIVE`; instead `CREATE UNIQUE INDEX CONCURRENTLY`, then `ADD CONSTRAINT … USING INDEX`.\n   - `ALTER TABLE … DROP COLUMN` — `ACCESS EXCLUSIVE`, metadata-only (fast).\n   - `RENAME` — `ACCESS EXCLUSIVE`, but instant. Watch out for app code still using the old name.\n\n   **Even \"instant\" `ACCESS EXCLUSIVE` statements are dangerous on a busy table**: the lock request waits behind any long-running transaction, and every new query queues behind *it* — a metadata-only change can stall all traffic. That is why step 6's `lock_timeout` is non-negotiable.\n2. **Backfill plan.** If the migration rewrites data:\n   - Batch in chunks with explicit commits. Postgres `UPDATE` has no `LIMIT` — batch by primary-key range or a sub-select:\n     `UPDATE refunds SET currency = 'USD' WHERE id IN (SELECT id FROM refunds WHERE currency IS NULL ORDER BY id LIMIT 10000);`\n   - Run outside the schema-migration tool (which usually wraps in a single tx).\n   - Pace by `pg_sleep` or external orchestration so the WAL backlog stays manageable.\n3. **`NOT NULL` rollout (multi-step).** The safe pattern (PG 12+ for the fast step 4). A `NOT VALID` check is still enforced on every new INSERT\u002FUPDATE — so before step 2, the app must already write the column (or the column needs a `DEFAULT`), or new writes start failing:\n   ```sql\n   ALTER TABLE refunds ADD COLUMN currency text;            -- step 1\n   -- deploy app that always writes currency (or: ALTER COLUMN currency SET DEFAULT 'USD')\n   ALTER TABLE refunds ADD CONSTRAINT refunds_currency_not_null\n     CHECK (currency IS NOT NULL) NOT VALID;               -- step 2\n   -- backfill in batches (see step 2), in its own deploy\u002Fjob\n   ALTER TABLE refunds VALIDATE CONSTRAINT refunds_currency_not_null;  -- step 3\n   ALTER TABLE refunds ALTER COLUMN currency SET NOT NULL; -- step 4 (fast because constraint is valid)\n   ALTER TABLE refunds DROP CONSTRAINT refunds_currency_not_null;\n   ```\n4. **Index migrations.** Always `CONCURRENTLY` for production. Note: `CONCURRENTLY` can fail and leave an `INVALID` index — the review should check there's a cleanup statement (`DROP INDEX IF EXISTS … ; CREATE INDEX CONCURRENTLY …`).\n5. **Foreign keys.** `ADD CONSTRAINT … FOREIGN KEY … NOT VALID` then `VALIDATE CONSTRAINT` later — same pattern as NOT NULL.\n6. **Lock timeout.** Recommend `SET lock_timeout = '5s'` at the top of risky migrations so they fail fast under contention instead of holding the queue.\n7. **Statement timeout.** Likewise `SET statement_timeout = '30s'` for individual statements; backfills set their own batch-scoped timeouts.\n\n## Output\n\n```text\nreview-migration\n\nFile:    db\u002Fmigrations\u002F20260523_add_currency.sql\nTarget:  refunds (≈ 50M rows)\n\nStatements\n  1. ALTER TABLE refunds ADD COLUMN currency text;\n     Lock: ACCESS EXCLUSIVE (fast, metadata-only).                ✓\n\n  2. ALTER TABLE refunds ALTER COLUMN currency SET DEFAULT 'USD';\n     Lock: ACCESS EXCLUSIVE (fast on PG 11+).                     ✓\n\n  3. ALTER TABLE refunds ALTER COLUMN currency SET NOT NULL;\n     Lock: ACCESS EXCLUSIVE; full scan on 50M rows.               ✗ unsafe\n\nIssues\n  - Statement 3 holds ACCESS EXCLUSIVE — blocking reads and writes — for the full scan of a 50M-row table.\n    Fix: split into the 4-step NOT VALID → backfill → VALIDATE → SET NOT NULL pattern.\n\n  - No lock_timeout set. Risk: migration holds the queue if contention spikes.\n    Fix: prepend `SET lock_timeout = '5s';`.\n\nRecommendation: split into 3 deploys (constraint+backfill+set-not-null). Block PR until restructured.\n```\n\n## Quality bar\n\n- Every statement classified by lock + cost.\n- Multi-step pattern named when a single statement is unsafe.\n- `CONCURRENTLY` flagged where it should be present (and not inside a transaction).\n- `lock_timeout` \u002F `statement_timeout` recommendations stated.\n\n## Anti-patterns to avoid\n\n- \"Just add NOT NULL, the table isn't that big\" without measuring. Big tables are big at 3 AM, not at code-review time.\n- `CREATE INDEX` (not CONCURRENTLY) on a live table. Writes blocked for the duration.\n- Wrapping CONCURRENTLY in a transaction. Postgres rejects; the migration tool may obscure the error.\n- Running backfill in a single statement on a 50M-row table. WAL bloat, replica lag, undo time after rollback.\n",{"name":5,"description":7},"main","23f6e21841a39580c9da2b5ec941f39dda17cd86","plugins\u002Fpolymath-backend\u002Fskills\u002Freview-migration","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath","https:\u002F\u002Fgithub.com\u002FMohammadBafkar","2026-10-29 18:34:59",{"source":8,"skillName":5,"commands":31,"prompt":41,"zipAvailable":42},[32,35,38],{"tool":33,"command":34},"npx","npx skills add MohammadBafkar\u002Fpolymath --skill review-migration",{"tool":36,"command":37},"bunx","bunx skills add MohammadBafkar\u002Fpolymath --skill review-migration",{"tool":39,"command":40},"pnpm","pnpm dlx skills add MohammadBafkar\u002Fpolymath --skill review-migration","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-backend\u002Fskills\u002Freview-migration\u002FSKILL.md",true,[],[45,52,59,66,73,80],{"skillNo":46,"name":47,"nameZh":6,"description":48,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":49,"categories":50,"keywords":51,"publishedAt":19},"01M74GN87EBRHM9N87M7AP1HDD","runbook","Write or refresh an operational runbook for an alert\u002Fsymptom; structured as TL;DR + Pre-checks + Steps + Verification + Rollback + Escalation.","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-writing\u002Fskills\u002Frunbook\u002FSKILL.md",[],[],{"skillNo":53,"name":54,"nameZh":6,"description":55,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":56,"categories":57,"keywords":58,"publishedAt":19},"01M74GN5GPKEC1JEKP2DFQNEQJ","rfc","Draft a lightweight design RFC to docs\u002Frfcs\u002F\u003Cslug>.md; Summary, Motivation, Detailed design, Drawbacks, Alternatives, Unresolved questions. A proposal to debate, not a recorded decision (adr).","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-writing\u002Fskills\u002Frfc\u002FSKILL.md",[],[],{"skillNo":60,"name":61,"nameZh":6,"description":62,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":63,"categories":64,"keywords":65,"publishedAt":19},"01M74GN2F4CWPMV4X09TG4E304","editorial-pass","Review and tighten prose in a Markdown artifact for a target tone (terse, formal, friendly) without dropping information; preserve quotations and load-bearing constraints.","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-writing\u002Fskills\u002Feditorial-pass\u002FSKILL.md",[],[],{"skillNo":67,"name":68,"nameZh":6,"description":69,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":70,"categories":71,"keywords":72,"publishedAt":19},"01M74GMZWGYMZ37C4DYGT6P23G","architecture-review-facilitation","Run an architecture review as a process — entry criteria, reviewer checklist, decision log, and follow-up actions — pairing the design artifact with a red-team pass.","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-writing\u002Fskills\u002Farchitecture-review-facilitation\u002FSKILL.md",[],[],{"skillNo":74,"name":75,"nameZh":6,"description":76,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":77,"categories":78,"keywords":79,"publishedAt":19},"01M74GMXVX0YX3ETDXS527XDGM","architecture-doc","Write a C4-style architecture document; System Context + Containers (+ Components when interesting) with mermaid diagrams. Describes structure, not a decision (adr) or proposal (rfc).","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-writing\u002Fskills\u002Farchitecture-doc\u002FSKILL.md",[],[],{"skillNo":81,"name":82,"nameZh":6,"description":83,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":84,"categories":85,"keywords":86,"publishedAt":19},"01M74GMVG1WSMCK066S3KE6V5K","adr","Write an Architecture Decision Record (Michael Nygard format) to docs\u002Fadrs\u002FNNNN-\u003Cslug>.md; frontmatter validated by the ADR artifact schema. Records a made decision, not a proposal to debate (rfc).","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-writing\u002Fskills\u002Fadr\u002FSKILL.md",[],[]]