Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store site wide settings in a database?

I'm debating three different approaches to to storing sitewide settings for a web application.

A key/value pair lookup table, each key represents a setting.

  • Pros Simple to implement
  • Cons No Constraints on the individual settings

A single row settings table.

  • Pros Per setting defaults and constraints
  • Cons - Lots of settings would mean lots of columns. Not sure if Postgres would have an issue with that

Just hard code it since the settings won't change that often.

  • Pros Easy to setup and add more settings.
  • Cons Much harder to change

Thoughts on which way to go?

like image 850
chotchki Avatar asked Aug 01 '11 02:08

chotchki


1 Answers

Since your question is tagged with database/sql I presume you'd have no problem accessing an sql table for both lookup and management of settings... Guessing here, but I'd start with a table like:

settingName  value   can_be_null   minvalue maxvalue  description
TheAnswer      42       no            1       100     this setting does...
...

If you think about managing a large number of settings, there's more information you need about each one of them than just their current value.

like image 144
TonyWilk Avatar answered Oct 25 '22 23:10

TonyWilk