0

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 ?

Warren
  • 735
  • 7
  • 19

1 Answers1

1

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

Leeroy Hannigan
  • 11,409
  • 3
  • 14
  • 31
  • Yes, this is what I am currently doing. I am trying to figure out how to get the permissions when I have a user. I can keep the permissions on the role but would have to update the permissions on every User-Role combination when the permissions changed on the role. – Warren Aug 09 '23 at 14:06