Why this matters
Keeps filters consistent and reduces errors when changing criteria.
Extract reusable SQL fragments/builders for commonly repeated WHERE/ORDER clauses.
Keeps filters consistent and reduces errors when changing criteria.
Side-by-side examples engineers can pattern-match during review.
$sql = 'SELECT * FROM orders WHERE status = ? AND created_at >= ?'; // copy-pastedfunction buildOrderFilterSql(): string { return 'status = ? AND created_at >= ?'; }
$sql = 'SELECT * FROM orders WHERE '.buildOrderFilterSql();duplicate WHERE ... in filesbuildFilterSql()From the same buckets as this rule.
Review SQL/database migrations for operations that can lock large tables or cause downtime. Examples: creating indexes without CONCURRENTLY (Postgres), ALTER COLUMN TYPE on big tables, adding NOT NULL without backfill, long-running updates without batching. Require an online migration strategy (CONCURRENTLY, backfill in batches, dual-write/expand-contract) and a rollback plan.