英文:
DynamoDB Single Table many to many to many
问题
我有一个多对多的数据关系,其中包括多个用户、多个角色和多个权限。用户到角色的多对多关系在一个表中处理,使用不同的索引来表示你所处的多对多关系的哪一侧。我正在尝试找出如何表示权限。以下是我想要通过一次 DynamoDB 调用得到的结果。
{
username: '用户名',
roles: [
{
roleName: '角色名',
permissions: [{ permissionName: '权限名' }],
},
],
}
我可以使用单表原则在角色和权限之间建立相同的关系,但是如何将用户与权限关联起来呢?
另一种选择是将权限冗余存储在每个角色中。我对此不太满意,因为当角色的权限发生变化时,我需要更新与用户关联的每个角色。
那么如何在 DynamoDB 中表示这种关系并且仍然保持一次调用呢?
英文:
I have a data relationship of many Users to many Roles to many Permissions. The Users to Roles many to many relationship is handled in a single table using different indexes to represent which side of the many to many relationship you are on. I am trying to figure out how to get the permissions represented. Here is what I want to end up with using just one call to DynamoDB.
{
username: 'User Name',
roles: [
{
roelName: 'Role Name',
permissions: [{ permissionName: 'Permission Name' }],
},
],
}
I can make the same relationship between roles and permissions using the single table principle but how do I link the user all the way to the permissions.
Another option would be to keep the permissions denormalized and living with each role. I am not too found of this because I would have to update every role linked to a user when the roles permissions changed.
So how do you represent this relationship in DynamoDB and still keep the calls down to one ?
答案1
得分: 1
尝试将模型建模为邻接表。
> 当应用程序的不同实体之间存在多对多的关系时,可以将关系建模为邻接表。在这种模式中,所有顶级实体(类似于图模型中的节点)都使用分区键表示。与其他实体的任何关系(图中的边)都表示为分区内的项目,通过将排序键的值设置为目标实体的ID(目标节点)来表示。
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-adjacency-graphs.html
英文:
Try modelling as an adjacency list
> When different entities of an application have a many-to-many relationship between them, the relationship can be modeled as an adjacency list. In this pattern, all top-level entities (synonymous to nodes in the graph model) are represented using the partition key. Any relationships with other entities (edges in a graph) are represented as an item within the partition by setting the value of the sort key to the target entity ID (target node).
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-adjacency-graphs.html
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论