Constraints: a Developer's Secret Weapon
summary
Argues that Postgres constraints turn the DB into the last line of defense, showing concrete wins: a system with 71 migrations vs 1,200 releases (then 20 migrations vs 200 releases) proves app code changes far faster than schema, so put checks in the DB. Demonstrates practical tools: unique/partial unique indexes, NOT NULL, enums, JSON + check casts, range types and a gist-backed exclusion constraint on time ranges to prevent overlapping billing periods. Notes insert-time cost on heavy ingestion workloads and that constraints can be relaxed later for performance.
AI-written summary · about
