【发布时间】:2021-04-09 14:17:59
【问题描述】:
我已经阅读了很多关于如何在 DynamoDB 单表设计中建模多对多关系的指南/最佳实践,但我找不到关于如何建模多对多关系的实用指南——对多“通过”关系。
具体来说,假设我有 3 个实体:Employees, Teams and Rules
在关系方面,我们假设:
- Employees must follow many Rules that are specific for each employee (one-to-many).
- Teams must follow many Rules (many-to-many).
- Employees can be part of different Teams (many-to-many).
我的主要访问模式是Get all the Rules that an Employee should follow,这意味着获取他的特定规则以及他所在团队继承的规则。
我开始像这样对表结构进行建模:
| PK | SK | Attributes... |
|---|---|---|
| EMPLOYEE#one | METADATA | |
| EMPLOYEE#one | RULE#one | |
| EMPLOYEE#one | RULE#two | |
| TEAM#one | RULE#three | |
| TEAM#one | RULE#four |
有了使用反向索引来创建 GSI 的想法,我需要处理我的访问模式,但是我碰壁了..
我如何为我的数据建模(单表设计)以有效地检索员工应遵循的所有规则?
我认为我需要在 PK 和 SK 上移动 Employee 和 Teams 之间的关系,例如:
| PK | SK | Attributes... |
|---|---|---|
| ... | ||
| EMPLOYEE#one | TEAM#one | |
| ... |
但是我不知道如何能够建立正确的索引来检索我需要的所有信息..
【问题讨论】:
标签: amazon-web-services nosql amazon-dynamodb