Skip to content
Sarj Code Standards

combine-alter-table

Combine compatible adjacent ALTER TABLE actions.

Why

Repeating ALTER TABLE for compatible changes to one relation obscures a single schema operation and adds avoidable statements. PostgreSQL supports comma-separated subcommands, including multiple drops.

Fix

Combine the reported adjacent statements into one ALTER TABLE with comma-separated actions, preserving their order, guards, table modifiers, and drop behavior. Keep deployment checkpoints and operations whose ordering, expression evaluation, or lock contracts differ in separate statements.

Examples

Before — flagged Drop a legacy foreign key and its column together
supabase/migrations/001_retire_version.sql
ALTER TABLE
CALL
DROP CONSTRAINT IF EXISTS call_scenario_version_fkey;
ALTER TABLE
CALL
DROP COLUMN IF EXISTS scenario_version_id;
After — preferred One statement retains the drop order and guards
supabase/migrations/001_retire_version.sql
ALTER TABLE
CALL
DROP CONSTRAINT IF EXISTS call_scenario_version_fkey,
DROP COLUMN IF EXISTS scenario_version_id;