Skip to content
Sarj Code Standards

declared-column-bounds

Encode explicitly declared numeric and interval ranges in SQL CHECK constraints.

Why

A column comment declaring a range does not reject out-of-range writes. Encoding that explicit contract in CHECK constraints keeps every writer subject to the same bounds.

Fix

Replace the range comment with an inline CHECK that enforces the declared bounds. Preserve units, inclusive endpoints and nullability. Do not invent a positive bound from a column name.

Examples

Before — flagged A comment cannot enforce a declared numeric range
supabase/migrations/001_retry.sql
CREATE TABLE retry (
attempts INTEGER NOT NULL -- required; capped 1..10
);
After — preferred CHECK encodes the permitted range without commentary
supabase/migrations/001_retry.sql
CREATE TABLE retry (
attempts INTEGER NOT NULL CHECK (attempts BETWEEN 1 AND 10)
);