Enums that are used in tables need to be stable

(Sam Saffron) #1

Following on

Our internal pattern for defining enums is too risky as it stands, we often use

# table boxes(id, color_id) 

colors = Enum.new(:red, :blue)

This saves on typing but introduces huge amount of risk and tribal knowledge, when someone goes to add a color they may add:

colors = Enum.new(:green, :red, :blue)

Now all our red boxes become green and our blue boxes red, cause enum counts from 1.

To eliminate this risk we should simple change enums to also accept a hash and use it for initialization where stability is required.


colors = Enum.new(red: 1, blue: 2, green: 3)

This makes the code slightly more verbose and significantly less risky.

@techAPJ leaving this one to you :wink:

Old user suspension reasons have gone missing
Old user suspension reasons have gone missing
(Arpit Jalan) #2

Okay, sent a PR:

(Sam Saffron) #3