Skip to content
Sarj Code Standards

no-pg-enum

CREATE TYPE ... AS ENUM — use TEXT with an application enum instead.

Why

PostgreSQL enums make ordinary value changes operationally awkward and couple application evolution to database type migrations.

Fix

Store the value as TEXT and validate its allowed values at the typed application boundary.

Examples

Before — flagged Executable dollar-quoted migration SQL remains checked
supabase/migrations/001_body.sql
DO $$ BEGIN CREATE TYPE status AS ENUM ('ready'); END $$;
After — preferred SQL keywords inside scalar dollar data are not executed
supabase/migrations/001_data.sql
SELECT
$data$CREATE TYPE status AS ENUM ('ready');$data$;
Before — flagged PostgreSQL enum type
supabase/migrations/001_status.sql
CREATE TYPE call_status AS ENUM('pending', 'active', 'completed');
After — preferred Text column whose closed values are application-owned
supabase/migrations/001_status.sql
CREATE TABLE
CALL (status TEXT NOT NULL);
Before — flagged Transactional enum evolution still couples application values to database migrations
supabase/migrations/001_boundary.sql
BEGIN;
ALTER TYPE call_status
ADD VALUE 'archived';
COMMIT;
After — preferred A transaction adds an application-owned text value column
supabase/migrations/001_boundary.sql
BEGIN;
ALTER TABLE
CALL
ADD COLUMN status TEXT;
COMMIT;