I would like to sync the DynamoDB table with a pre-defined data structure. I am using Enum represents each item.
public enum Key {
NOTIFICATION_ENABLED(false),
ARTICLES_PER_PAGE(2),
private final Object defaultValue;
private Key(Object defaultValue) {
this.defaultValue = defaultValue;
}
public Object getDefaultValue() {
return this.defaultValue;
}
}
By saying sync, I mean if I add a new key/value into enum or remove an existing key/value from enum, the table will sync with the structure.
These key/value is the application settings key/value pair, so they are not exposable for users to add/remove. Only admin could modify the value for the keys through the UI.
With this structure, adding a new key works fine. While removing an existing key/value from enum, I am doing this work flow:
Get all items in table -> Get all items in pre-defined enum -> remove the items in table but not in enum
Say we remove ARTICLES_PER_PAGE(2). In the first step, when getting all the items in table, DynamoDB will throw exceptions because we remove the enum key/value it is trying to map to.
How should I come over this?