数据库设计——一个数据库,多个站点

发布于 2024-11-07 06:51:57 字数 732 浏览 0 评论 0原文

我知道这个问题以前已经被问过很多次了,但我找不到我的确切答案。所以请让我在这里问一下。

我们构建了一个 CMS 来控制一个站点。现在公司正在扩张,我们有几个核心结构几乎相同的站点。为了便于以后维护,我们决定使用一个数据库。

我们大约有10张桌子。例如,页面、新闻、设置(每个站点都不同)...

如果我们向每个表添加一个 App_ID(或 Site_ID)列,以便我们知道其中的哪些记录,这听起来不是一个好主意我们应该撤出的特定网站。

例如,

PAGES:
PageID   |   Body   |   SiteID
1        | abc      |   1
2        | cde      |   1
3        | aafd     |   2
4        | gsgs     |   2
5        | feg      |   3

我认为将这个 SiteID 列添加到该数据库中的每个表中是非常丰富的。

我仔细查看了多租户架构 但我不知道如何将其应用到我们网站的 CMS 中。

遇到这种情况,最好的处理方法是什么,请帮忙。任何启发都值得赞赏。

简单的代码

I know this question has been asked so many times before but I couldn't find the exact answer for mine. So please let me ask it here.

We built a CMS to control one site. Now the company is expanding and we have a couple more sites with almost identical core structure. We decided to go with one database for easy maintenance later on.

We have about 10 tables. For example, Pages, News, Settings (different for each site), ...

It doesn't sound like a good idea if we add one App_ID (or Site_ID) column to every each of these tables so we know what records from which particular site we should pull out.

For instance,

PAGES:
PageID   |   Body   |   SiteID
1        | abc      |   1
2        | cde      |   1
3        | aafd     |   2
4        | gsgs     |   2
5        | feg      |   3

I think it is very abundant to add this SiteID Column to every table in this Database.

I looked carefully at the Multi-Tenant Architecture but I don't know how to apply it to our sites CMS.

What is the best way to handle this situation, please help. Any enlightenment is appreciated.

Simple Code

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

谜泪 2024-11-14 06:51:57

我们最近一直在审查多租户单一数据库的各种策略。

如果您不想将站点标识符添加到表中,那么您可以为每个租户提供自己的架构和表集。每个租户都可以拥有自己的连接字符串,该字符串仅提供对其架构的访问(您显然需要在运行时切换连接(如果您使用这些,那么使用 EF 和 NH 就足够简单了)。

但是,我们选择的选项是引入在我们的应用程序中添加一个附加级别,以便应用程序的每个组件(在您的情况下是新闻、页面等)都表示为数据库中的一个功能,

然后每个站点都有一个功能“实例”的集合以及为每个实例存储的数据。这些功能(博客可能有帖子、标签、类别)引用了功能实例(而不是网站),

这确实增加了额外的复杂性,但我们发现它非常灵活,并且将我们的功能数据与网站分离(使 )。如果我们愿意,可以在站点之间移动功能实例)。

We've recently been reviewing various strategies for multi-tenant single database.

If you don't want to add a Site identifier to your tables then you could give each tenant their own schema and set of tables. Each tenant could have their own connection string which only provides access to their schema (you would obviously need to switch connection at runtime (easy enough with both EF and NH if you are using these).

However, the option we opted for was to introduce an additional level into our application such that each component of the application (in your case News, Pages etc.) was represented as a feature in the database.

Each site then has a collection of feature "instances" and the data stored for each of those features (a blog might have posts, tags, categories) has a reference to the feature instance (not the site).

This does add additional complexity but we have found it to be extremely flexible and decouples our feature data from the site (make it possible to move feature instances between sites if we wanted to).

留一抹残留的笑 2024-11-14 06:51:57

答案不一。在类似的项目、相同的数据库结构、多个站点中工作。

我们尝试了几种东西。

我们是“最佳实践”、“数据库规范化”、“设计模式”的粉丝,但是,我们最终使用的是实用方法,而不是理论方法。

我们为每个站点/公司都有一个或多个数据库,每个数据库表都有一个“site_id”,并且它有效。

我们遇到过一些情况,一家公司决定为每个部门拆分其数据库站点,因此一个数据库变成了多个数据库,有时位于同一数据库服务器中,有时位于不同的数据库服务器中。

我们有一个案例,一家只有一个站点的公司,收购了一家较小的公司,添加了一个具有相同数据库结构的新站点,五年后,他们合并了数据。

几个站点加上“site_id”,效果很好。

Mixed answer. Work in a similar project, same database structure, several sites.

We tried several stuff.

We are fan of "best practices", "database normalization", "design patterns", but, we ended using a practical approach, more than theorical.

We had one or more databases for each site / company, and each database table had a "site_id", and it worked.

We had some cases where a single company decided to split their database site for each division, so one database become several databases sometimes within the same database server, sometimes different database server.

We had a case where a company with a single site, buy a smaller company, added a new site with same database structure, and after 5 yeas, they merge the data.

The several sites plus "site_id", worked well.

断舍离 2024-11-14 06:51:57

推荐使用多个数据库,因为它可以更简单地备份和恢复单个站点。此外,如果您发现需要引入复制从属服务器,则使用单独的数据库可以提高复制效率。据我所知,大多数多站点托管解决方案都使用多个数据库。

但是,如果您打算使用单个数据库,则另一个选项是复制表,并使用指示其所属站点的前缀。

Multiple databases would be the recommended way since it allows simpler backup and restoration of a single site. Also, if you find you need to introduce replication slaves, replication can be more efficient with the use of separate databases. Most multi-site hosting solutions I know of, use multiple databases.

However, if you are intent on a single database, the other option is to duplicate the tables with a prefix indicating which site it belongs to.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文