I have an User model with statuses that represent yes/no flags for the following states
- active
- email verified
- phone verified
- KYC passed
- MFA set up
- may purchase
- account suspended
- account closed
Most developers will store this state into separate database fields. I'd like to store this in a single 8bit integer so I can do things like:
status & 0b10000000 == 128 # email verified
status & 0b01000000 == 64 # phone verified
status & 0b00100000 == 32 # KYC passed
status & 0b00010000 == 16 # MFA set up
status & 0b00001000 == 8 # may transact
status & 0b00000100 == 4 # active
status & 0b00000010 == 2 # suspended
status & 0b00000001 == 1 # closed
The advantages I can think of would be:
- less DB clutter (1 field instead of 8+)
- easier querying (just a comparison between 2 ints rather than a .where longer than my keyboard cable)
- single index for all this and it will be fast
- can add more information as a 2nd byte (and so on) if needed
Before actually implementing this I'd just like to hear from more experienced developers if this is a good idea (yeah let's have a laugh: rate it 0 to 10) or a big no-no and in that case why not rather than plain simple "no" or vote to close/flag simply because it doesn't fit opinionated simple active/inactive state scenarios.