Modeling Relational Data in DynamoDB (nested relationship)

Lon*_*yen 3 hierarchical-data amazon-dynamodb dynamodb-queries amazon-dynamodb-index amazon-dynamodb-data-modeling

Entity Model:

在此处输入图片说明

I've read AWS Guide about create a Modeling Relational Data in DynamoDB. It's so confusing in my access pattern.

Access Pattern

+-------------------------------------------+------------+------------+
| Access Pattern                            | Params     | Conditions |
+-------------------------------------------+------------+------------+
| Get TEST SUITE detail and check that      |TestSuiteID |            |
| USER_ID belongs to project has test suite |   &UserId  |            |
+-------------------------------------------+------------+------------+
| Get TEST CASE detail and check that       | TestCaseID |            |
| USER_ID belongs to project has test case  |   &UserId  |            |
+-------------------------------------------+------------+------------+
| Remove PROJECT ID, all TEST SUITE         | ProjectID  |            |
| AND TEST CASE also removed                |   &UserId  |            |
+-------------------------------------------+------------+------------+
Run Code Online (Sandbox Code Playgroud)

So, I model a relational entity data as guide.

+-------------------------+---------------------------------+
|       Primary Key       |            Attributes           |
+-------------------------+                                 +
|     PK     |     SK     |                                 |
+------------+------------+---------------------------------+
|   user_1   |    USER    |    FullName    |                |
+            +            +----------------+----------------+
|            |            | John Doe       |                |
+            +------------+----------------+----------------+
|            |   prj_01   |   JoinedDate   |                |
+            +            +----------------+----------------+
|            |            | 2019-04-22     |                |
+            +------------+----------------+----------------+
|            |   prj_02   |   JoinedDate   |                |
+            +            +----------------+----------------+
|            |            | 2019-05-26     |                |
+------------+------------+----------------+----------------+
|   user_2   |    USER    |    FullName    |                |
+            +            +----------------+----------------+
|            |            | Harry Potter   |                |
+            +------------+----------------+----------------+
|            | prj_01     |   JoinedDate   |                |
+            +            +----------------+----------------+
|            |            | 2019-04-25     |                |
+------------+------------+----------------+----------------+
| prj_01     | PROJECT    |      Name      |   Description  |
+            +            +----------------+----------------+
|            |            | Facebook Test  | Do some stuffs |
+            +------------+----------------+----------------+
|            | t_suite_01 |                |                |
+            +            +----------------+----------------+
|            |            |                |                |
+------------+------------+----------------+----------------+
| prj_02     | PROJECT    |      Name      |   Description  |
+            +            +----------------+----------------+
|            |            | Instagram Test | ...            |
+------------+------------+----------------+----------------+
| t_suite_01 | TEST_SUITE |      Name      |                |
+            +            +----------------+----------------+
|            |            | Test Suite 1   |                |
+            +------------+----------------+----------------+
|            | t_case_1   |                |                |
+            +            +----------------+----------------+
|            |            |                |                |
+------------+------------+----------------+----------------+
| t_case_1   | TEST_CASE  |      Name      |                |
+            +            +----------------+----------------+
|            |            | Test Case 1    |                |
+------------+------------+----------------+----------------+
Run Code Online (Sandbox Code Playgroud)

If I just have UserID and TestCaseId as a parameter, how could I get TestCase Detail and verify that UserId has permission.

I've thought about storing complex hierarchical data within a single item. Something likes this

+------------+-------------------------+
| t_suite_01 | user_1#prj_1            |
+------------+-------------------------+
| t_suite_02 | user_1#prj_2            |
+------------+-------------------------+
| t_case_01  | user_1#prj_1#t_suite_01 |
+------------+-------------------------+
| t_case_02  | user_2#prj_1#t_suite_01 |
+------------+-------------------------+
Run Code Online (Sandbox Code Playgroud)

Question: What is the best way for this case? I appreciate if you could give me some suggestion for this approach (bow)

Ric*_*han 5

我认为以下架构可以满足您的需求。在“ GSIPK”属性上创建仅分区密钥GSI并查询,如下所示:

  1. 获取测试套件详细信息并验证用户:查询GSI-PK == ProjectId,FilterCondition [SK == TestSuiteId || PK == UserId]

  2. 获取测试用例详细信息并验证用户:查询GSI-PK == TestCaseId,FilterCondition [SK = TestSuiteId:TestCaseId || PK = UserId]

  3. 删除项目:查询GSI-PK == ProjectId,删除所有返回的项目。

查询1和2返回1或2。一个是详细信息,另一个是测试套件或测试用例的用户权限。如果仅返回一项,则显示其明细项,并且用户无权访问。

在此处输入图片说明

在此处输入图片说明