gpt4 book ai didi

database - (疑似)多对多关系的模式设计

转载 作者:搜寻专家 更新时间:2023-10-30 20:43:43 30 4
gpt4 key购买 nike

我正在创建一个用于跟踪网络上机器配置的应用程序。 “配置”广泛定义了系统上安装的产品/服务/操作系统/应用程序。其中任何一个的变化都会导致配置发生变化。信息是使用扫描仪获取的。数据已经解析。我需要找出一种有效存储数据的方法。

基本思路是

  1. 每个 IP 都有一个配置标识符以及时间戳信息和标识数据是当前数据还是历史数据的标志
  2. 每个配置依次包含多种类型的条目。因此对于每个配置标识符,我们最多有三种类型的条目(1-OS、2-Service、3-Applications)
  3. 每种类型的条目可以有多个条目。例如,类型 1(即 - 操作系统)可以有 a) Microsoft Windows XP b) Microsoft Windows 7 等类型的多个条目。

我坚持定义一组合适的表格来帮助我实现以下目标

  1. 了解每个IP的OS/Service.Application信息
  2. 识别 IP 配置的变化/无变化/恢复

我得到的数据是 IP 和条目集及其类型标识符。例如。

IP - x.y.z.w : 
Entries - Microsoft Windows XP :1(Type-OS),
Apache HTTP 2.3 :2(Type-Service),
Mozilla Firefox :3(Type - Application)

早些时候,当我不关心配置而只需要存储条目时,我有以下方案

Table ip_map : id int, ip char #Table that keeps track of IPs
Table ip_ref: id int , ip_id references ip_map(id), t_stamp timestamp, archived bool, type smallint #Table that keeps IPs and type
Table current_network: id int, ip_ref_id references ip_ref(id), port int, vendor, product,version #Table that stores actual entries

即- 我使用 IP 和类型信息识别条目。

如果我需要实现配置,方案应该有点像

ip_map:
+--+-------+
|id|ip |
+--+-------+
|1 |x.y.z.w|
+--+-------+

ip_config:
+--+------+----------+--------+----------+
|id|ip_id |t_stamp |archived|config_num|
+--+------+----------+--------+----------+
|1 |1 |1212231313| 1 | 1 |
|2 |1 |1212299999| 0 | 2 |
+--+------+----------+--------+----------+

我卡在这之后的步骤中了。理想情况下,config_num 是指向配置表主键的外键。但是由于配置是由不同的类型组成的,这似乎是不可能的。这就是我的想法。

config:
+--+---+----+
|id|num|type|
+--+---+----+
|1 | 1 | 1 |
|2 | 1 | 2 |
|3 | 2 | 1 |
|4 | 2 | 2 |
+--+---+----+

entry:
+--+---------+----+-------------+-------------+-------------+
|id|config_id|port|vendor | product | version |
+--+---------+----+-------------+-------------+-------------+
|1 | 1 | 0 | Microsoft | Windows | XP |
|2 | 1 | 0 | Microsoft | Windows | 7 Home |
|3 | 2 | 80 | Apache | HTTP Server | 2.3.19 |
|4 | 3 | 0 | Linux | Linux | 2.6 |
|5 | 3 | 0 | Linux | Linux | 2.4 |
|6 | 4 | 22 | OpenSSH | SSHD | 4.3p1 |
+--+---------+----+-------------+-------------+-------------+

但它破坏了一致性(由于 ip_config 和配置表之间缺少外键)。 IP 可能会被删除,但配置将继续存在。如何更改设计以满足我的要求?

注意:理想情况下,类型信息(针对每个 IP 或配置)应该单独维护,因为这是程序的单独部分所期望的。

最佳答案

我不能说我理解这里的一切,所以这个例子可能会给你一些想法。

ConfigurationType开始,这可以是1- OS; 2- 服务 ...

Configuration 表包含所有可能的(允许的)配置。 ConfigurationTypeNo 是每个 ConfigurationTypeID 的整数 (1,2,3 ...) - 所以有 OS (1,2,3 ..);服务(1,2,3 ...)等

SystemConfiguration 捕获每个系统的配置设置历史。由于 TimeChanged 是 PK 的一部分,因此可以重复相同的配置。

IP_Allocation 跟踪 IP 分配的历史记录。

enter image description here

关于database - (疑似)多对多关系的模式设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9208769/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com