I am not sure if this is correct place to ask this question.
I am new to dynamodb and trying to figure my way out to create a small web application. I've read the best practices here http://docs.amazonwebservices.com/amazondynamodb/latest/developerguide/BestPractices.html
My tables will be:
- Buildings
- Tenants (a building can have as many tenants, identified by floor number)
- Recipients (each floor can be as many recipients, basically an alias of a tenant)
- Couriers
- Deliveries (a courier tied with the particular recipient)
My approach currently to design the schema looks like this:
// Tables
// PK: Building Id, SK: name
- Building ID : {
name: <Building Name>
Tenants: [
{ TenantId: { Receipients: [{Receipient Id 1, Receipient Id 2...}] }
]
}
// PK: Courier Id, SK: createdAt
- CourierId : {
name: <Courier name>
...
}
//PK: Not Sure, SK: Not Sure <-- This is where I messed up, looks relational, defeats the purpose?
- Deliveries: {
receipient id: Courier id
}
In order to list out all deliveries along with recipient details, I will be needing recipient details by recipient Id. That, according to the LSI docs, will mean making recipient Id as a sort key in the in the Building table.
Since you can only have top-level elements of the table (recipient not being the one), this seems impossible as per guideline https://docs.amazonaws.cn/en_us/amazondynamodb/latest/developerguide/GSI.html
The index key attributes can consist of any top-level String, Number, or Binary attributes from the base table; other scalar types, document types, and set types are not allowed.
So, I am hopeless this can be achieved without making another table, where I should copy all the recipients, updating them everything update happens in the table. Is there any other alternative or better approach?
Since a deliveries seems one to one relation of couriers with the recipient, is it okay to keep the ids and to iterate over all the recipient and couriers it at the time of listing all the deliveries?