How do you structure config data in a database?

后端 未结 18 1281
后悔当初
后悔当初 2021-01-31 04:37

What is people\'s prefered method of storing application configuration data in a database. From having done this in the past myself, I\'ve utilised two ways of doing it.

18条回答
  •  长发绾君心
    2021-01-31 05:16

    Since configuration typically can be stored in a text file, the string data type should be more than enough to store the configuration values. If you're using a managed language, it's the code that knows what the data type should be, not the database.

    More importantly, consider these things with configuration:

    • Hierarchy: Obviously, configuration will benefit from a hierarchy
    • Versioning: Consider the benefit of being able to roll back to the configuration that was in effect at a certain date.
    • Distribution: Some time, it might be nice to be able to cluster an application. Some properties should probably be local to each node in a cluster.
    • Documentation: Depending on if you have a web tool or something, it is probably nice to store the documentation about a property close to the code that uses it. (Code annotations is very nice for this.)
    • Notification: How is the code going to know that a change has been made somewhere in the configuration repository?

    Personally, i like an inverted way of handling configuration, where the configuration properties is injected into the modules which don't know where the values came from. This way, the configuration management system can be very complex or very simple depending on your (current) needs.

提交回复
热议问题