Storing enum-like values

Back to list2025-06-19
You

Database enum, lookup table or plain text?

ChatGPT

A lookup table with a foreign key, unless the set is genuinely fixed forever. Database enums require a migration to add a value and cannot carry attributes; plain text accepts typos silently and then you have three spellings of the same status in production.

You

Is a deleted_at column a good idea?

ChatGPT

It is, provided every query filters on it, which is the part that fails. A partial index plus a view is the version that survives:

CREATE VIEW active_users AS SELECT * FROM users WHERE deleted_at IS NULL;
CREATE INDEX users_active_idx ON users (id) WHERE deleted_at IS NULL;

Then application code selects from the view and forgetting the filter becomes impossible rather than merely discouraged.