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 = 0in addition touser_type IS NULLwhere needed. - Make the app aware about
0value as human value too. - Make column default to 0 instead of
NULL - Migrate all rows with
user_type = NULLto 0 - Prohibit
nilas enum value at Ruby level. Leave only0as user type for humans. - Enforce NOT NULL constraint on
user_typefield. - Update indexes, remove the
IS nullcondition. (post migrate)
Edited by Pavel Shutsin