Skip to content

Instantly share code, notes, and snippets.

@leonardovillela
Last active October 6, 2023 12:15
Show Gist options
  • Save leonardovillela/8ffa8ac9fac17d8eb970e55ebdd401dc to your computer and use it in GitHub Desktop.
Save leonardovillela/8ffa8ac9fac17d8eb970e55ebdd401dc to your computer and use it in GitHub Desktop.
Data Model DynamoDB

Data Model

Table Dynamo

Single table desing

Base Object Commom Properties

{
  type: "RULE_SET" | "ENTITY_ID_RULE_SET_RELATIONS"
}

Rule Set Spefic Propertiers

... Rule set props

Entity ID Rule Set Relations

Primary Key or Wathever indexed propertier is entity id

  "type": "ENTITY_ID_RULE_SET_RELATIONS"
  "entity_id": ["rule_set_id_1", "rule_set_id_2", ...] 

Data Access

Get All Rule Sets by Entity ID

  1. Read item with entity ID passed as argument and type equals "ENTITY_ID_RULE_SET_RELATION"
  2. Batch read items by rule_sets_ids of item retrieved on step 1.

Data Examples

[
  {
    "type": "RULE_SET",
    "id": 1,
    "allocations": [
      {
        "entity_id": 123,
        "other_field": "bla bla"
      }
    ]
    //... other rule set props
  },
  {
    "type": "RULE_SET",
    "id": 2,
    //... other rule set props
    "allocations": [
      {
        "entity_id": 123,
        "other_field": "bla bla"
      },
      {
        "entity_id": 321,
        "other_field": "bla bla2"
      }
    ]
  },
  {
    "type": "ENTITY_ID_RULE_SET_RELATIONS",
    "id": 123,
    "rule_sets_ids": [1, 2]
  },
  {
    "type": "ENTITY_ID_RULE_SET_RELATIONS",
    "id": 321,
    "rule_sets_ids": [2]
  },
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment