Relational database is mostly used for storing editable user data.
But how about storing non-editable lists of information? Possible examples are:
- GUI-related: main menu items, selectbox options, list of links, set of UI colors
- application logic: list of user types and their privileges, default table view configuration (default applied filters, columns...), internal application config
We usually don't call these items "data", they are rather part of the application itself and their definitions are hard-coded directly in the source code. It is however technically possible to e.g. store menu items in a database table and construct the menu by running SQL query and iterating through the rows.
Advantages of storing information in db. include:
- list of items stored in a database table has solid structure and can be manipulated with SQL - queried, sorted and filtered
- items can be edited directly in the database, you don't have to commit to Git and run CI/CD process every time an edit happens, you can even build special admin interface (possibly web-based) above the database so even non-programmers can edit the items
- if the list of items is large, it is effective to store it in the database and share the data across multiple app instances rather than have it separately in the source code of every app instance
Disadvantages of storing information in db. include:
- performance overhead when querying the database
- when modifying the information stored in a database, you must use database migrations to keep record of these changes, which is much more inconvenient than modifying only the source code where you can easily use Git to keep versions history and sync changes between environments
- it is inconvenient for programmer to work with both source code and database data all the time, it is more convenient to have all information in the source code only
- in contrast to source code, with items stored in database you can't freely use programming language features like storing native programming language objects, function callbacks or constants/variables in the database (e.g. for displaying/hiding menu item based on some boolean variable or constant etc.)
- storing data in database is more insecure than storing it in source code, as everybody with credentials to the database can edit the items and possibly ruin the application, moreover it is hard to find out who and when has made the editing
- if you develop frontend app and some UI parts (like menu items) are stored in database, your frontend needs to make an API call to get those items and subsequently construct the UI
I have come across an opinion that everything which is a structured list of information (even non-editable) should be stored in a database. Given the reasons above, would you consider this to be a good concept in respect to:
- code clarity
- performance
- flexibility
- common programming techniques (we don't want programmers to experience "WTF moment" when dealing with the project)