DEV Community

Cover image for What's your favorite way to manage system-wide settings? (except .env)

Posted on

What's your favorite way to manage system-wide settings? (except .env)

I'm fallen in situation, when users MUST edit system-wide settings from the web interface, i.e. audio message, that should be played for all incoming customer calls. I have a lot of little configurable things like that, and ended up with simple key-value table in database, (which is crappy solution, 🤦‍♂️).

So, i'm kinda curious, how others handle that? Maybe i miss something more elegant & reliable? Share some of your experience.

Top comments (4)

tux0r profile image

Key-value pairs are exactly made for this IMO.

bozhkos profile image

Yeah, that's right on one hand.

On the other hand, keeping all that into single database table, feels terribly wrong. What about different types of config variable, when it(variable) can be string, or boolean, or integer? I forced to keep all that as strings, and wrote crunch to realize type of variable on runtime.

Thing works fine, but feeling, that something done ridiculously wrong, eat me from behind.

avalander profile image

If you need to keep an arbitrarily long set of settings that the users can update, I think there aren't many things more convenient than a key-value table in the database.

In past projects, we have used a similar configuration, but we added a type column to the table and then used that to parse and validate the value when reading and writing the configuration to avoid runtime errors due to invalid values.

dmfay profile image
Dian Fay

You could set up your table like this:

key value_str value_int value_bool ...
one a string null null

and use check constraints to ensure that only one value column is ever filled (as long as you're not using MySQL which doesn't actually implement them). But that's still probably overkill if you don't have to retrieve values that frequently. Simple kludges are the best kludges.