SQL · maintainability
no-pg-enum
sql:no-pg-enum CREATE TYPE ... AS ENUM — use TEXT + CHECK constraint instead.
- Code
- SARJ103
- Default
- error
- Fix
- none
- Languages
- sql
Why
PostgreSQL enums make ordinary value changes operationally awkward and couple application evolution to database type migrations.
Fix
Store the value as TEXT and constrain the allowed values with an explicit CHECK expression.
Before / after
Executed by this rule’s unit tests.
Before
PostgreSQL enum type
CREATE TYPE call_status AS ENUM ('pending', 'active', 'completed');
After
Text column with an explicit value constraint
CREATE TABLE call (
status TEXT NOT NULL CHECK (status IN ('pending', 'active', 'completed'))
);
Limits
- PostgreSQL dump files are excluded.
- Generated migrations still report, but diagnostics direct the edit to the owning schema model.