Make User#user_type not nullable
Summary
Currently "human" user type has value of NULL
which works poorly in query conditions and indexes. E.g. instead of user_type IN (0,5,6)
we have to write user_type IS NULL OR user_type IN (5,6)
which is not covered by index (user_type)
.
Proposal
Make value 0
as "human" user type too so it can be indexed and mentioned in IN
clauses.
- Create indexes with
user_type = 0
in addition touser_type IS NULL
where needed. - Make the app aware about
0
value as human value too. - Make column default to 0 instead of
NULL
- Migrate all rows with
user_type = NULL
to 0 - Prohibit
nil
as enum value at Ruby level. Leave only0
as user type for humans. - Enforce NOT NULL constraint on
user_type
field. - Update indexes, remove the
IS null
condition. (post migrate)
Edited by Pavel Shutsin