sql-review
Skill1 starsChanged 40 days agoMITView on GitHub
SQL code-review rubric for PostgreSQL — migrations (the lock each ALTER form takes, what rewrites a table since PG 11, NOT NULL without a default, CREATE INDEX without CONCURRENTLY, large backfills, rollout order between the old code and the new schema, reversibility, migration-number conflicts between branches) and queries (match with the schema's types and NULLs, joins, transactions and isolation level, an index for a new query, N+1, injection), in .sql files and in query strings embedded in Rust (sqlx, diesel, postgres) or any other code; severity by harm from review-rules. Use when reviewing a migration or a query, asking whether a migration is safe to deploy, or rating a SQL finding. Triggers: review this migration, is this migration safe, ALTER TABLE lock, table rewrite, CREATE INDEX CONCURRENTLY, NOT NULL column, backfill, migration conflict, N+1, sqlx query, isolation level. Not for Rust code beside the query (rust-review) nor for the review workflow itself (craft:review).
- Deletes or force-pushes
13 other projects use a version of this.
Adopted by
Most recently taken up by
- XData-si/xdata-agenthubtheir own version, first seen Nov 22, 2026
- DataArt/artisyn-log-hubtheir own version, first seen Nov 22, 2026
- Smaui94/ClaudeSkillCollectiontheir own version, first seen Nov 8, 2026
- polardb/polardbx-skillstheir own version, first seen Nov 8, 2026
- Lanqiao-Luca/ai-java-workflowtheir own version, first seen Nov 8, 2026
- z-Zihan/Evirtheir own version, first seen Oct 13, 2026
Used with
Projects with it also use security-review and code-review.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
SentrySkillsecurity-review
Finds exploitable application security vulnerabilities in code changes. Use for Warden security scans, appsec review, OWASP-style checks, authentication or authorization bugs, injection, XSS, SSRF, path traversal, secrets, unsafe crypto, webhook verification, open redirects, or sensitive data exposure.
Also in 3 projects that use this
GoogleSkillcode-review
Adversarial systems, concurrency, memory-model, and architecture code review protocol. Use this skill whenever asked to review code, PRs, diffs, or branches in Filament.
Also in 4 projects that use this
Other versions13 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 13
- Lanqiao-Luca/ai-java-workflow★ 340same name
- kyle-chalmers/streamsnow★ 17same name
- DataArt/artisyn-log-hub★ 12same name
- z-Zihan/Evir★ 11same name
- polardb/polardbx-skills★ 8same name
- analyticsengineering/ae-toolkit★ 3same name
- gmanch94/claude-code-aidlc-template★ 2same name
- Jiplet/transformation-os★ 2same name
- dennisrongo/claude-skills★ 1same name
- GabrielHenriqueCA/cortex-ai★ 1same name
3 more not listed
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 repository42 other files it gives its agents.
- AGENTS.mdAGENTS.md
- addressing-findingsSkill
- auditSkill
- codebase-onboardingSkill
- codex-reviewSkill
- compatibilitySkill
- debuggingSkill
- developSkill
- distributed-racesSkill
- memorySkill
- nix-dev-envSkill
- nix-flakesSkill
- nixosSkill
- nix-packagingSkill
- nix-reviewSkill
- refactoringSkill
- retroSkill
- review-initSkill
- review-rulesSkill
- rust-architecture-reviewSkill
- rust-architectureSkill
- rust-cliSkill
- rust-cloud-nativeSkill
- rust-concurrencySkill
- rust-ecosystemSkill
- rust-embeddedSkill
- rust-errorsSkill
- rust-fintechSkill
- rust-idiomsSkill
- rust-macrosSkill
- rust-mlSkill
- rust-navigationSkill
- rust-ownershipSkill
- rust-performanceSkill
- rust-pluginsSkill
- rust-reviewSkill
- rust-securitySkill
- rust-testingSkill
- rust-traitsSkill
- rust-unsafeSkill
- rust-webSkill
- specsSkill
The file
We split this skill into the rules it gives an agent
1 rule. 0 are common, 0 are distinctive, and 1 is very specific to this project.
0
Common
Most of the 11 edited versions we read keep these.
0
Distinctive
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
- Very specific: line 68
CHECK, VALIDATE and SET NOT NULL sequence) in one migration the tool runs as one transaction — the first step's lock is held through the …
“Common” is measured: kept by at least 6 in 10 of the 11 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
SQL Review
The rubric for reviewing SQL: schema migrations and queries, against PostgreSQL semantics unless the
repository names another engine. Severity, finding classes and sweeps come from review-rules; this
skill keeps what is specific to SQL. Each item below has a catalog ID in rules.md.
The review entry point is the craft:review workflow. It sends every changed .sql file to the SQL
profile, whose two lenses — sql-migrations and sql-queries — always run, on the host's default
agent. A Rust or other source file whose changed lines hold a query string (a sqlx::query,
query!, query_as!, sql_query call, or a string literal opening with SELECT, INSERT INTO,
UPDATE … SET, DELETE FROM or WITH) also gets the sql-queries lens in its own profile's
review. There is no mechanical SQL gate: the verdict rests on the lenses and their verifiers.
Facts the checklist rests on
Lock levels (PostgreSQL docs, "Explicit Locking" and ALTER TABLE):
| Statement | Lock on the table | Work done while the lock is held |
most ALTER TABLE forms (ADD/DROP COLUMN, ALTER TYPE, SET/DROP DEFAULT, SET/DROP NOT NULL, ADD CHECK, ADD UNIQUE/PRIMARY KEY, RENAME) | ACCESS EXCLUSIVE — blocks reads and writes | any scan or rewrite the form does |
ADD FOREIGN KEY | SHARE ROW EXCLUSIVE on both tables | the validating scan, unless NOT VALID |
VALIDATE CONSTRAINT | SHARE UPDATE EXCLUSIVE — reads and writes go on | the scan |
CREATE INDEX | SHARE — blocks writes | the whole build |
CREATE INDEX CONCURRENTLY | SHARE UPDATE EXCLUSIVE | the build; it cannot run in a transaction block, nor on a partitioned table's parent; a failed build leaves an INVALID index to drop |
DROP INDEX, DROP TABLE, TRUNCATE | ACCESS EXCLUSIVE | — (DROP INDEX CONCURRENTLY avoids it) |
A table lock is held until the end of the transaction that took it, not the statement. The
safe two-step forms — ADD CONSTRAINT … NOT VALID, then VALIDATE CONSTRAINT; CHECK (col IS NOT
NULL) NOT VALID, then VALIDATE, then SET NOT NULL; on PG 18+, ADD CONSTRAINT … NOT NULL col NOT
VALID, then VALIDATE CONSTRAINT — need the NOT VALID step to commit before VALIDATE runs.
Migration tools wrap each file in one transaction by default (sqlx, diesel), so the two in one file
keep the NOT VALID step's ACCESS EXCLUSIVE (SHARE ROW EXCLUSIVE on both tables for a foreign key)
through the whole validating scan: the safe form is no safer than the plain one. Put the NOT VALID
step in its own migration file, or opt the file out of the transaction. VALIDATE and the SET NOT
NULL after it may share one transaction: the scan runs under SHARE UPDATE EXCLUSIVE, and the ACCESS
EXCLUSIVE SET NOT NULL then takes is brief, its scan skipped. Likewise, every statement after a
lock-taking one in the same transaction runs under that lock.
Any lock waits in the queue behind the transactions already holding a conflicting one, and every
later query on the table waits behind it: a brief ACCESS EXCLUSIVE behind one long transaction stops
the table. A migration on a hot table sets lock_timeout (and retries) for that reason.
What rewrites the table and its indexes:
| Change | Rewrite? |
ADD COLUMN with no default, or a non-volatile default (a constant, now()) | no, since PG 11 |
ADD COLUMN with a volatile default (gen_random_uuid(), clock_timestamp(), a serial or identity), or a STORED generated column | yes |
ALTER COLUMN TYPE to a binary-coercible type (varchar(n) → varchar(m), m > n, or → text) | no |
ALTER COLUMN TYPE otherwise (int → bigint, text → int, varchar narrowed) | yes |
timestamp ↔ timestamptz | no rewrite from PG 12 when the session time zone is UTC; a rewrite otherwise |
SET NOT NULL | no rewrite, but a full scan under ACCESS EXCLUSIVE — skipped (PG 12+) when a validated CHECK (col IS NOT NULL) exists; on PG 18+ a NOT NULL constraint can instead be added NOT VALID and validated under SHARE UPDATE EXCLUSIVE |
DROP COLUMN | no (the column is only marked dropped) |
Migrations checklist
- Lock (MIG-001): a statement that holds ACCESS EXCLUSIVE or SHARE through a scan, a rewrite or
an index build on a table that has traffic — and the lock lasts to the end of its transaction, so
everything after it in the same file runs under it. The safe forms:
CREATE INDEX CONCURRENTLY, thenADD CONSTRAINT … USING INDEX;ADD CONSTRAINT … NOT VALID, thenVALIDATE CONSTRAINT. - Two steps, one transaction (MIG-009): the
NOT VALIDstep and itsVALIDATE CONSTRAINT(or the CHECK, VALIDATE andSET NOT NULLsequence) in one migration the tool runs as one transaction — the first step's lock is held through the scan. Must-fix on a large table with traffic. - Rewrite (MIG-002): a type change or added column from the rewrite table above, on a large table.
- NOT NULL (MIG-003):
ADD COLUMN … NOT NULLwithout aDEFAULTfails on a table with rows;SET NOT NULLwithout the validated CHECK scans under ACCESS EXCLUSIVE. The safe routes: the CHECK trick (CHECKNOT VALID,VALIDATE,SET NOT NULL, drop the CHECK), or on PG 18+ADD CONSTRAINT … NOT NULL col NOT VALID, thenVALIDATE CONSTRAINT— each with itsNOT VALIDstep committed first (MIG-009). - Index (MIG-004):
CREATE [UNIQUE] INDEXon an existing table withoutCONCURRENTLY. With it: a migration tool that wraps the file in a transaction (sqlx: opt out with a-- no-transactionfirst line; diesel:run_in_transaction = falsein the migration'smetadata.toml); and, opted out, a file with any other statement beside it — several statements sent as one query string run as an implicit transaction block and fail with "cannot run inside a transaction block", so the concurrent build is the file's only statement. On a partitioned tableCONCURRENTLYis refused on the parent: build the index concurrently on each partition, thenCREATE INDEX … ON ONLYthe parent andALTER INDEX … ATTACH PARTITIONeach one. - Backfill (MIG-005): one
UPDATEorINSERT … SELECTover a large table, or a backfill in the same transaction as DDL — long row locks, any DDL lock held to the end, WAL and replica lag. Batch it, outside the schema migration. - Rollout order (MIG-006): during a deploy the old code runs against the new schema (and the new code against the old when migrations run after the rollout). A dropped or renamed column or table still used on the base, a new NOT NULL column old INSERTs omit, a type old code decodes, an enum value old code cannot parse. Expand first, migrate the code, contract in a later release. Grep the repository's code in every language for the object.
- Reversibility (MIG-007): a down migration missing where the repository keeps them, or one that cannot restore what the up removed.
- Migration numbers (MIG-008): the base's and the trunk's migrations are listed with
git ls-tree --name-only <ref> -- <migrations dir>/; a version this diff reuses, one that sorts before the latest on the trunk (refused by tools that forbid out-of-order, never applied by tools that record only the current version), or an edit to a migration the base already holds (a checksum mismatch, or a change no applied database ever sees).
A statement on a table the same branch creates has no lock or rollout harm.
Queries checklist
- Schema match (QRY-001): read the table's migrations at HEAD; every column exists with the type the code binds and decodes; a nullable column (an outer join's side included) decoded into a non-optional type.
- NULL and joins (QRY-002):
= NULL;NOT IN (subquery)over a NULL; SUM/MAX over no rows returning NULL; a WHERE on a LEFT JOIN's right table; a join on an incomplete key multiplying rows. - Transactions (QRY-003): a read-then-write outside one transaction, or at READ COMMITTED (the
default) without
FOR UPDATE, a conditional UPDATE, a unique constraint orON CONFLICT; a serialization failure (40001) or deadlock (40P01) never retried; a statement sent on the pool instead of the transaction (&poolfor&mut *txin sqlx); a transaction held across a slow call. - Index (QRY-004): a new WHERE/JOIN/ORDER BY on a growing table with no index whose leading columns serve it; a function or cast on the column, or a leading-wildcard LIKE, defeating a b-tree.
- N+1 (QRY-005): a query per row or per loop item; one query with a JOIN or
= ANY($1)instead. - Injection (QRY-006): query text built from a value instead of a bind parameter; an
identifier not quoted with
quote_ident/format('%I').
Severity
By the harm cap of review-rules (severity.md), never above it:
- must-fix —
outage: a table locked or rewritten under traffic (a two-step safe form run in one transaction included), a migration that fails on deploy, old code broken by the new schema;data-loss: data dropped, truncated or corrupted that no durable source restores;security: injection from outside input;intent-unmet: a query that does not do what the change says. - should-fix — a missing index or an N+1 whose traffic is not named; a non-reversible down
migration where the repository keeps them (a
repo-rulewhen its rule is written down). - not a finding — keyword case, formatting, alias or constraint naming, style.
Table size and traffic are premises: cite where they were seen, or say they are unknown.
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.

