用于监控应用程序状态的数据库设计功能

发布于 2024-08-23 01:39:03 字数 1293 浏览 5 评论 0原文

我正在创建数据库来监视应用程序功能的状态。逻辑如下:

每个应用程序都有自己正在监视的特定功能列表。每一项功能仅属于一个应用程序。有一个功能表,其中包含应用程序的外键

每个应用程序都在一台或多台计算机上运行。每台机器可以运行一个或多个应用程序。这是MTM连接,因此存在ApplicationInstance表连接Applications与Machines。

实际的监控是查询ApplicationInstance。如果出现问题,有关该问题的信息将转到 AppInstanceError 表,该表保存 ApplicationInstance 的外键。如果查询成功,我们将获得每个功能的状态列表。因此,我们有一个FunctionalityStatus 表,其中包含ApplicationInstance 和ApplicationInstance 的外键。功能性。

我认为这是一种糟糕的设计 - 为什么我们对应用程序有多个引用?什么保证两者都指向同一个应用程序?或者有什么办法可以保证这一点吗?

所以我的修复建议是将功能状态与外键连接到机器和机器。功能性。但在这种情况下,他们定义了 ApplicationInstance,那么每对都有 ApplicationInstance 的保证是什么?他们不应该以某种方式联系起来吗?在现实世界中,连接是存在的并且是显而易见的,那么数据库中不存在它可以吗?

是否有“正确的方法”来解决这个问题,或者确保连接在数据设计中不可见?

为了更清楚地说明,我准备了我现在拥有的数据库设计: DB design

唯一缺少的是从FunctionalityStatus 到Machine 的连接。我看到两种建立这种连接的方法:

  1. 将外键添加到 ApplicationInstance - 那么我的疑问是:
    • 如何确保功能中的 ApplicationId 与 ApplicationInstance 中的相同?
    • 真的需要这种数据复制吗?
  2. 将外键添加到机器 - 和疑问:
    • 每个FunctionalityStatus 记录都会有一个适当的ApplicationInstance 记录吗?
    • 如果ApplicationInstance和FunctionalityStatus之间存在明显的联系(在第一个疑问中提到),我们在数据库中看不到它吗?
    • 再次出现数据冗余,因为所有 ApplicationInstance 记录在(或应该)在 FunctionityStatus 表中可见

或者也许整个设计搞砸了,我应该找出完全不同的东西?

I'm creating the database for monitoring status of applications' functionalities. The logic is following:

Each application has its own, specific list of functionalities that I'm monitoring. Each functionality belongs to only one application. There is a Functionality table that has foreign key to Application

Each application runs on one or more machines. Each machine can run one or more applications. This is MTM connection, so there is ApplicationInstance table connection Applications with Machines.

The actual monitoring is about querying ApplicationInstance. If there is a problem, information about it goes to AppInstanceError table, wich holds foreign key to ApplicationInstance. If the query is successful, we get a list of statuses of each functionality. So we have a FunctionalityStatus table with foreign keys to ApplicationInstance & Functionality.

I think this is kind of bad design - why do we have multiple reference to Application? What guarantees that both will point to the same Application? Or is there any way to ensure this?

So my proposition of fix is to connect FunctionalityStatus with foreign keys to Machines & Functionality. But in this case they define ApplicationInstance so what is the guarantee of having ApplicationInstance for each pair? Shouldn't they be connected somehow? In the real world connection exists and is obvious, so is it OK not to have it in database?

Is there a "propper way" of solving this problem, or of ensuring connections invisible from data design?

To make it more clear I prepared design of DB that I have now:
DB design

The only thing that is missing is a connection from FunctionalityStatus to Machine. I see two ways ow making such a connection:

  1. Add foreign key to ApplicationInstance - then my doubts are:
    • How to make sure that ApplicationId from Functionality is the same that one from ApplicationInstance?
    • Isn this data duplication really needed?
  2. Add foreign key to Machine - and doubts:
    • Will there be a propper ApplicationInstance record for every FunctionalityStatus record?
    • If there is an obvious connection between ApplicationInstance and FunctionalityStatus (mentioned in first doubt) whu can't we see it in database?
    • Again data redundancy becouse all ApplicationInstance records are (or should be) visible in FunctionalityStatus table

Or maybe the whole design is screwed up and I should figure out something totally else?

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

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

发布评论

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

评论(3

默嘫て 2024-08-30 01:39:03

你的设计对我来说似乎不错。我会选择选项 1,将外键从 FunctionalStatus 添加到 ApplicationInstance

如果您想确保 FunctionalStatusApplicationStatus 引用同一个应用程序,您可以添加一个新列 FunctionalStatus.ApplicationId,并将外部从 FunctionalStatusApplicationStatus 的键包含 ApplicationId。对于从 FunctionalStatusFunctionality 的外键也是如此。

换句话说,就像

CREATE TABLE application
    ( application_id          INT PRIMARY KEY
    /* Other columns omitted */
    );
CREATE TABLE application_instance
    ( application_instance_id INT PRIMARY KEY
    , application_id          INT REFERENCES application(application_id)
    , machine_id              INT REFERENCES machine(machine_id)
    /* Other columns omitted */
    );
CREATE TABLE functionality
    ( functionality_id        INT PRIMARY KEY
    , application_id          INT REFERENCES application(application_id)
    /* Other columns omitted */
    );
CREATE TABLE functionality_status
    ( functionality_status_id INT PRIMARY KEY
    , application_id          INT REFERENCES application(application_id)
    , functionality_id        INT /* Part of composite foreign key, see below */
    , application_instance_id INT /* Part of composite foreign key, see below */
    /* Other columns omitted */
    FOREIGN KEY (functionality_id, application_id) 
      REFERENCES functionality(functionality_id, application_id)
    FOREIGN KEY (application_instance_id, application_id) 
      REFERENCES application_instance(application_instance_id, application_id)
    );

Your design seems fine to me. I would go for option 1, adding a foreign key from FunctionalStatus to ApplicationInstance.

If you want to ensure that FunctionalStatus and ApplicationStatus refer to the same application, you could add a new column FunctionalStatus.ApplicationId, and make the foreign key from FunctionalStatus to ApplicationStatus include ApplicationId. Likewise for the foreign key from FunctionalStatus to Functionality.

In other words, something like

CREATE TABLE application
    ( application_id          INT PRIMARY KEY
    /* Other columns omitted */
    );
CREATE TABLE application_instance
    ( application_instance_id INT PRIMARY KEY
    , application_id          INT REFERENCES application(application_id)
    , machine_id              INT REFERENCES machine(machine_id)
    /* Other columns omitted */
    );
CREATE TABLE functionality
    ( functionality_id        INT PRIMARY KEY
    , application_id          INT REFERENCES application(application_id)
    /* Other columns omitted */
    );
CREATE TABLE functionality_status
    ( functionality_status_id INT PRIMARY KEY
    , application_id          INT REFERENCES application(application_id)
    , functionality_id        INT /* Part of composite foreign key, see below */
    , application_instance_id INT /* Part of composite foreign key, see below */
    /* Other columns omitted */
    FOREIGN KEY (functionality_id, application_id) 
      REFERENCES functionality(functionality_id, application_id)
    FOREIGN KEY (application_instance_id, application_id) 
      REFERENCES application_instance(application_instance_id, application_id)
    );
绳情 2024-08-30 01:39:03

您可能遇到的最大问题是,同一台计算机上同一应用程序的两个不同实例始终可能具有相同的实例 ID。它们不能同时出现,随着时间的推移,实例 ID 会被重复使用,并且您的应用程序极有可能再次获得相同的 ID。

当我做这种事情时,我会在每个应用程序启动时为其分配一个 GUID,这使得两个应用程序不可能具有相同的 GUID,然后我使用该 GUID 来建立关系。您甚至不需要在关系中包含机器信息,因为每台机器永远不会与任何其他机器创建相同的 GUID。

回答完这个问题我才发现我真的没有回答你真正的问题。如果您想查看某些功能是否以某种方式工作,最好将其与机器和应用程序相关联,其中该功能未按您想要的方式运行,或者您很难找到哪个功能正常工作,哪个功能正常工作一错。

拥有三个表,一张用于机器,一张用于应用程序,一张用于功能将是最好的数据库设计。根据您正在执行的操作,软件可能会更轻松、更快速地复制您正在使用的每组功能的所有应用程序和机器信息,特别是如果有关机器和应用程序的信息只是一个字段的话。如果可以的话,您确实不想减慢记录此信息的功能,因此您希望快速完成它。

Biggest problem you might have is that it is always possible to have the same Instance IDs for two different instances of the same application on the same machine. The can't be at the same time, Instance IDs are reused over time and there is a small chance that your app will get the same one again.

When I do this kind of thing, I assign each application a GUID when it starts that makes it impossible to have two applications with the same GUID and I then use that GUID for the relationships. You don't even need to have the machine information in the relationship as each machine will never make the same GUID as any other machine.

I realized after answering this that I really did not answer your real question. If you are looking to see if certain functionality is working in a certain way, it is best to related it to the machine and the application where the functionality is not going the way you want or you have trouble finding which one is working right and which one wrong.

Having three tables one for machines, one for applications and one for functionality would be the best database design. Depending on what you are doing, it might be easier and faster for the software to duplicate all the application and machine information for each set of functionality you are working with, especially if the information about the machine and application is just one field anyway. You really don't want to slow down the functionality for the logging of this information if you can help it, so you want to have it done quickly.

超可爱的懒熊 2024-08-30 01:39:03

如果是我,我会这样做:

  1. 创建 5 个表,机器,
    应用、功能、
    应用程序池和日志。
  2. 在功能中放置 FK 列,
    这是应用程序的 ID
    该功能存在的目的。
  3. ApplicationPool 将有一台机器
    ID 列、应用程序 ID 列、
    主键可以是 GUID 或
    种子身份,
    ApplicationInstance ID 这将
    是您的应用程序名称 + PK。如果可以的话,我会用它来命名您的应用程序和机器。
  4. 最后,我将制作日志表
    并给出一个 FK 列
    参考PK
    应用程序池。然后,每次您记录某些内容时,您都可以将其添加到日志表中,并且有关应用程序的所有信息都将单独存储。

如果这还不够,请告诉我,因为我可能误解了您要寻找的内容。

If it was me this is how I would do it:

  1. Create 5 tables, Machine,
    Application, Functionality,
    ApplicationPool, and Log.
  2. Put a FK column in Functionality,
    that is the ID of the Application
    the Functionality exists for.
  3. ApplicationPool would have a Machine
    ID column, an Application ID column,
    Primary Key that is either a GUID or
    a Seeded Identity, an
    ApplicationInstance ID which would
    be your ApplicationName + PK. If you can this is what I would use to name your applications your machines.
  4. Finally, I would make the Log table
    and give an FK Column that
    references the PK of
    ApplicationPool. Then every time you logged something you could add it to the Log table and all of your information about the application would be stored separately.

If this isn't close let me know because I could have misunderstood what you are looking for.

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