Skip to content
Sarj Code Standards

no-application-schema-check

Review JSON shape validation duplicated in database CHECK constraints.

Why

A database CHECK that repeats an application-owned JSON schema creates two validators that can drift and turn an otherwise valid application deployment into failed writes.

Fix

If the application owns the contract, validate the JSON payload with the typed application boundary before changing its CHECK. Preserve database-owned validation and checks needed by other writers; use an exact SARJ118 suppression explaining ownership. Keep relational constraints such as foreign keys, uniqueness, nullability, and cross-column invariants in the database.

Examples

Before — flagged Database duplicates a JSON array schema
supabase/migrations/001_execution_plan.sql
CREATE TABLE execution_plan (
outcomes JSONB NOT NULL CHECK (
JSONB_TYPEOF(outcomes) = 'array'
AND JSONB_ARRAY_LENGTH(outcomes) BETWEEN 1 AND 10
)
);
After — preferred Application schema owns the JSON document contract
supabase/migrations/001_execution_plan.sql
CREATE TABLE execution_plan (
call_id UUID PRIMARY KEY REFERENCES
CALL (id),
outcomes JSONB NOT NULL
);