My application configuration is very hierarchical and fits nicely into a single XML. Soon (YAGNI, Yeh) parts of this information will be consumed by other applications remotely, which calls for a database.
我的应用程序配置非常分层,非常适合单个XML。很快(YAGNI,Yeh)这些信息的一部分将远程被其他应用程序使用,这需要一个数据库。
So, I went into designing DB tables and mapping them back to my application's class hierarchy (using EF). however it became a maintenance nightmare.
因此,我开始设计数据库表并将它们映射回我的应用程序的类层次结构(使用EF)。然而它成了维护的噩梦。
I'd love to hear from others experience considering this issue, thanks.
我很想听听其他人在考虑这个问题时的经验,谢谢。
4 个解决方案
#1
17
We had very good experience with storing the config in a database for long running applications (like web sites and services). Advantages:
我们有很好的经验,可以将配置存储在数据库中,用于长期运行的应用程序(如网站和服务)。优点:
- You can edit the config remotely and securely (user/password)
- 您可以远程安全地编辑配置(用户/密码)
- It is simple for the application to pick up changes (
select max(lmod) from config
) automatically or by a signal (ping a web page or create an empty file somewhere) - 应用程序很容易自动或通过信号(ping某个网页或在某处创建一个空文件)来获取更改(从配置中选择max(lmod))
- The application only needs a single item of configuration per environment (dev, test, prod): The DB to use. If you have an application server, your applications are config free for all environments.
- 应用程序每个环境(dev,test,prod)只需要一个配置项:要使用的DB。如果您有应用程序服务器,则您的应用程序可以免费为所有环境配置。
The main problem is the editing if you have a complex, hierarchical config structure with defaults, lists and inheritance. Our solutions:
主要问题是编辑,如果你有一个复杂的,分层的配置结构,默认,列表和继承。我们的方案:
- The config table has these rows: Application varchar(32), Key varchar(512), Value varchar(4096)
- 配置表包含以下行:Application varchar(32),Key varchar(512),Value varchar(4096)
- One DB per environment (local developer machine, development test, integration test, production)
- 每个环境一个DB(本地开发人员机器,开发测试,集成测试,生产)
- The key is hierarchical (option.suboption....name)
- 关键是层次结构(option.suboption .... name)
- Defaults use "option..name" (for example, "jdbc..driver" since we use only one type of database)
- 默认值使用“option..name”(例如,“jdbc..driver”,因为我们只使用一种类型的数据库)
- Lists are stored as strings, separated by newline.
- 列表存储为字符串,由换行符分隔。
- Maps are stores as strings, "name=value\n"
- 地图以字符串形式存储,“name = value \ n”
- There is an implementation which can read the config from a file (for unit tests). Map each hierarchy of the key to an element (......)
- 有一个实现可以从文件中读取配置(用于单元测试)。将键的每个层次结构映射到元素(......)
Config objects hide these details, so the application just works with objects.
配置对象隐藏这些细节,因此应用程序只适用于对象。
A special class is responsible for re-reading the config in case of a change. Usually, we update the config some time during the day and a timed job will reload it after hours. This way, we never need to synchronize the config methods.
特殊类负责在发生更改时重新读取配置。通常,我们会在一天中的某个时间更新配置,并且定时作业将在数小时后重新加载。这样,我们就不需要同步配置方法了。
Backup and change history were a problem, though. We fixed that by using XML files in the VCS which are then "uploaded" to the DB. This way, we could verify the production config before uploading it (by using it with a special set of unit tests on a developer machine). When it got activated during the night, it usually worked right away and the operator responsible for the app would just have to do a little bit of testing.
但是,备份和更改历史记录是一个问题。我们通过在VCS中使用XML文件来修复它,然后将其“上传”到数据库中。这样,我们可以在上传之前验证生产配置(通过在开发人员计算机上使用一组特殊的单元测试)。当它在夜间被激活时,它通常会立即起作用,负责应用程序的操作员只需要进行一些测试。
#2
7
IMHO config should live in files, files work well for people and they're ok for computers. DBs work well for big data, but they're overkill for human stuff. The two are normally mutually exclusive, and when you do try to combine them you get something like the registry - uggh.
恕我直言的配置应该存在于文件中,文件适用于人们,并且它们对于计算机是可以的。数据库适用于大数据,但它们对于人类的东西来说太过分了。这两者通常是互斥的,当你尝试将它们组合起来时,你会得到类似注册表的内容 - uggh。
Why not leave the config in a file, and build a DAL and service layer around it so that your apps can use it. That assumes you can host onto a central server, if not have multiple copies of the file in the wild.
为什么不将配置保留在文件中,并围绕它构建DAL和服务层,以便您的应用程序可以使用它。假设您可以托管到*服务器,如果没有野外的多个文件副本。
#3
0
Using a database (maybe to store this config xml file, if you wish to retain the format) has advantages - you can log/audit changes to the configuration and also do backup and recovery.
使用数据库(可能存储此配置xml文件,如果您希望保留格式)具有优势 - 您可以记录/审核对配置的更改,还可以进行备份和恢复。
Basically your question (the way I see it) mixes two things,
基本上你的问题(我看到的方式)混合了两件事,
- What format the config should be in (xml, .ini file, etc)
- 配置应该是什么格式(xml,.ini文件等)
- Where it should be stored (flat file on disk, table column in database)
- 应该存储的位置(磁盘上的平面文件,数据库中的表列)
You could easily store the config xml file in a database and provide an interface for editing/displaying the info.
您可以轻松地将config xml文件存储在数据库中,并提供用于编辑/显示信息的界面。
#4
0
Config files should be the most easiest things to handle - so put them into files. This way someone can make changes there even with notepad (if necessary). Database is really an overkill, unless you want your configuration reside in some global server and all instances to share it.
配置文件应该是最容易处理的事情 - 所以将它们放入文件中。这样,即使使用记事本,有人也可以在那里进行更改(如有必要)。除非您希望您的配置驻留在某个全局服务器和所有实例中以共享数据库,否则数据库确实是一种过度杀伤。
#1
17
We had very good experience with storing the config in a database for long running applications (like web sites and services). Advantages:
我们有很好的经验,可以将配置存储在数据库中,用于长期运行的应用程序(如网站和服务)。优点:
- You can edit the config remotely and securely (user/password)
- 您可以远程安全地编辑配置(用户/密码)
- It is simple for the application to pick up changes (
select max(lmod) from config
) automatically or by a signal (ping a web page or create an empty file somewhere) - 应用程序很容易自动或通过信号(ping某个网页或在某处创建一个空文件)来获取更改(从配置中选择max(lmod))
- The application only needs a single item of configuration per environment (dev, test, prod): The DB to use. If you have an application server, your applications are config free for all environments.
- 应用程序每个环境(dev,test,prod)只需要一个配置项:要使用的DB。如果您有应用程序服务器,则您的应用程序可以免费为所有环境配置。
The main problem is the editing if you have a complex, hierarchical config structure with defaults, lists and inheritance. Our solutions:
主要问题是编辑,如果你有一个复杂的,分层的配置结构,默认,列表和继承。我们的方案:
- The config table has these rows: Application varchar(32), Key varchar(512), Value varchar(4096)
- 配置表包含以下行:Application varchar(32),Key varchar(512),Value varchar(4096)
- One DB per environment (local developer machine, development test, integration test, production)
- 每个环境一个DB(本地开发人员机器,开发测试,集成测试,生产)
- The key is hierarchical (option.suboption....name)
- 关键是层次结构(option.suboption .... name)
- Defaults use "option..name" (for example, "jdbc..driver" since we use only one type of database)
- 默认值使用“option..name”(例如,“jdbc..driver”,因为我们只使用一种类型的数据库)
- Lists are stored as strings, separated by newline.
- 列表存储为字符串,由换行符分隔。
- Maps are stores as strings, "name=value\n"
- 地图以字符串形式存储,“name = value \ n”
- There is an implementation which can read the config from a file (for unit tests). Map each hierarchy of the key to an element (......)
- 有一个实现可以从文件中读取配置(用于单元测试)。将键的每个层次结构映射到元素(......)
Config objects hide these details, so the application just works with objects.
配置对象隐藏这些细节,因此应用程序只适用于对象。
A special class is responsible for re-reading the config in case of a change. Usually, we update the config some time during the day and a timed job will reload it after hours. This way, we never need to synchronize the config methods.
特殊类负责在发生更改时重新读取配置。通常,我们会在一天中的某个时间更新配置,并且定时作业将在数小时后重新加载。这样,我们就不需要同步配置方法了。
Backup and change history were a problem, though. We fixed that by using XML files in the VCS which are then "uploaded" to the DB. This way, we could verify the production config before uploading it (by using it with a special set of unit tests on a developer machine). When it got activated during the night, it usually worked right away and the operator responsible for the app would just have to do a little bit of testing.
但是,备份和更改历史记录是一个问题。我们通过在VCS中使用XML文件来修复它,然后将其“上传”到数据库中。这样,我们可以在上传之前验证生产配置(通过在开发人员计算机上使用一组特殊的单元测试)。当它在夜间被激活时,它通常会立即起作用,负责应用程序的操作员只需要进行一些测试。
#2
7
IMHO config should live in files, files work well for people and they're ok for computers. DBs work well for big data, but they're overkill for human stuff. The two are normally mutually exclusive, and when you do try to combine them you get something like the registry - uggh.
恕我直言的配置应该存在于文件中,文件适用于人们,并且它们对于计算机是可以的。数据库适用于大数据,但它们对于人类的东西来说太过分了。这两者通常是互斥的,当你尝试将它们组合起来时,你会得到类似注册表的内容 - uggh。
Why not leave the config in a file, and build a DAL and service layer around it so that your apps can use it. That assumes you can host onto a central server, if not have multiple copies of the file in the wild.
为什么不将配置保留在文件中,并围绕它构建DAL和服务层,以便您的应用程序可以使用它。假设您可以托管到*服务器,如果没有野外的多个文件副本。
#3
0
Using a database (maybe to store this config xml file, if you wish to retain the format) has advantages - you can log/audit changes to the configuration and also do backup and recovery.
使用数据库(可能存储此配置xml文件,如果您希望保留格式)具有优势 - 您可以记录/审核对配置的更改,还可以进行备份和恢复。
Basically your question (the way I see it) mixes two things,
基本上你的问题(我看到的方式)混合了两件事,
- What format the config should be in (xml, .ini file, etc)
- 配置应该是什么格式(xml,.ini文件等)
- Where it should be stored (flat file on disk, table column in database)
- 应该存储的位置(磁盘上的平面文件,数据库中的表列)
You could easily store the config xml file in a database and provide an interface for editing/displaying the info.
您可以轻松地将config xml文件存储在数据库中,并提供用于编辑/显示信息的界面。
#4
0
Config files should be the most easiest things to handle - so put them into files. This way someone can make changes there even with notepad (if necessary). Database is really an overkill, unless you want your configuration reside in some global server and all instances to share it.
配置文件应该是最容易处理的事情 - 所以将它们放入文件中。这样,即使使用记事本,有人也可以在那里进行更改(如有必要)。除非您希望您的配置驻留在某个全局服务器和所有实例中以共享数据库,否则数据库确实是一种过度杀伤。