-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[docs] add dynamodb schema document #9
Conversation
docs/dynamodb.md
Outdated
- `can_be_partner`, Boolean => flag for a pokemon that be able to be choose as a partner | ||
- `can_be_enemy`, Boolean => flag for a pokemon that be able to become an enemy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these fields should be replaced with following field:
type
, String => the pokemon type, valid values: PARTNER
, ENEMY
Then we could use this field as partition key in global secondary index (GSI).
So when we want to query for available Pokemon partners, we could query this GSI with type=PARTNER
or type=ENEMY
if we want to query enemies.
If we are still using can_be_partner
& can_be_enemy
fields, we need to scan the whole table first then apply the filter. We should avoid scan operation in DynamoDB since it is usually very expensive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we make a Pokemon support both of the types?
e.g. Pikachu can be either partner or enemy. Or this is a case that we do not need to support currently?
Maybe we can put the roles (PARTNER, ENEMY) in a set and make it indexable? I'm totally newbie with DynamoDB here.. 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we can. You can make the type
field optional. So in Pikachu we could set type=PARTNER
.
When we want to query partner, we could use the type
index. If we want to query enemy we could use scan table operation.
Maybe we can put the roles (PARTNER, ENEMY) in a set and make it indexable?
No, in DynamoDB this is not possible. Index in DynamoDB only support scalar types.
I'm totally newbie with DynamoDB here.. 😅
No problem, this common pitfall for someone who just use DynamoDB. 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aaah, understood, that's how the index query works. Okay, lemme update necessary things
docs/dynamodb.md
Outdated
- `partner.health`, Number => remaining health of player's partner | ||
- `enemy.id`, String => identifier of opposite partner | ||
- `enemy.health`, Number => remaining health of opposite partner | ||
- `last_damage.partner`, Number => last inflicted damage to player's partner | ||
- `last_damage.enemy`, Number => last inflicted damage to opposite partner |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing the definition of last_damage
, partner
, and enemy
field. It should be Map
type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it 👌
docs/dynamodb.md
Outdated
- `battle_stats.max_health`, Number => maximum health (on battle start) of a pokemon | ||
- `battle_stats.attack`, Number => number of damage that can be inflicted by a pokemon | ||
- `battle_stats.defense`, Number => number of damage reducer for a pokemon (damage = enemy.attack - your_partner.defense) | ||
- `battle_stats.speed`, Number => chance for getting a turn in battle, higher means more likely to get a turn in battle RNG |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing the definition of battle_stats
field. It should be Map
type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
noted 👌
docs/dynamodb.md
Outdated
- `battle_stats.max_health`, Number => maximum health (on battle start) of a pokemon | ||
- `battle_stats.attack`, Number => number of damage that can be inflicted by a pokemon | ||
- `battle_stats.defense`, Number => number of damage reducer for a pokemon (damage = enemy.attack - your_partner.defense) | ||
- `battle_stats.speed`, Number => chance for getting a turn in battle, higher means more likely to get a turn in battle RNG |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better if you add 1 indentation here. This is to make it clear max_health
, attack
, defense
, & speed
is under battle_stats
. In think it is okay too if you remove the battle_stats
prefix.
Here is what I mean:
battle_stats
, Map => holds battle stats related information of a pokemonmax_health
, Number => maximum health (on battle start) of a pokemonattack
, Number => number of damage that can be inflicted by a pokemondefense
, Number => number of damage reducer for a pokemon (damage = enemy.attack - your_partner.defense)speed
, Number => chance for getting a turn in battle, higher means more likely to get a turn in battle RNG
docs/dynamodb.md
Outdated
- `battle_stats.max_health`, Number => maximum health (on battle start) of a pokemon | ||
- `battle_stats.attack`, Number => number of damage that can be inflicted by a pokemon | ||
- `battle_stats.defense`, Number => number of damage reducer for a pokemon (damage = enemy.attack - your_partner.defense) | ||
- `battle_stats.speed`, Number => chance for getting a turn in battle, higher means more likely to get a turn in battle RNG | ||
- `avatar_url`, String => url for avatar image of a pokemon | ||
- `can_be_partner`, Boolean => flag for a pokemon that be able to be choose as a partner | ||
- `can_be_enemy`, Boolean => flag for a pokemon that be able to become an enemy | ||
- `type`, String => the pokemon type, valid values: `PARTNER`, `ENEMY` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you don't want to make it possible for Pikachu to also become possible enemy?
If do you want to do so, write the spec like this:
type
, String, OPTIONAL => the pokemon type, valid values:PARTNER
You can also change the name type
into extra_role
(since this is optional), so the spec would be:
extra_role
, String, OPTIONAL => the pokemon type, valid values:PARTNER
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, I think extra_role
is more fit than type
, also to avoid using reserved words. Noted 👌
docs/dynamodb.md
Outdated
}, | ||
``` | ||
|
||
**Relevant Indexes:** | ||
- `PRIMARY_KEY` => `id` | ||
- `GLOBAL_SECONDARY_INDEX` => `type` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be:
type
=>type
This is the style we usually use to define GSI. Or you could also make it like this:
type
, GSI =>type
This is to make it clear that this index is GSI not LSI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
noted 👌
docs/dynamodb.md
Outdated
- `partner`, Map => holds information of player's pokemon | ||
- `partner.health`, Number => remaining health of player's partner | ||
- `enemy`, Map => holds information of enemy's pokemon | ||
- `enemy.id`, String => identifier of opposite partner | ||
- `enemy.health`, Number => remaining health of opposite partner |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make it like this:
partner
, Map => holds information of player's pokemonhealth
, Number => remaining health of player's partner
enemy
, Map => holds information of enemy's pokemonid
, String => identifier of opposite partnerhealth
, Number => remaining health of opposite partner
Btw, in Like for example the complete data for partner & enemy. By doing this when you are fetching the battle data you could only fetch it one time. No need to lookup from Pokemon Table. This is also the same case with partner data in I think by putting all the data in the object creation it will make the query more efficient. Notice that DynamoDB is key value store similar to Redis. So you cannot have join queries. |
My main concern is data consistency, if a Pokemon get an update in its battle stats, should it be reflected in running games or not? This is a very common concern with NoSQL. If running battles won't reflect Pokemon stats update, I agree filling all necessary data altogether is a much better way |
Hmm.., ok, let say we do some adjustment to Pokemon data. This will affect:
From the context of running battle, I think it's better if we keep the battle data as before the adjustment. By doing this we could keep the consistency for that running battle. For the running game perspective I agree with you. |
Ok, seems good. So, I'll persist states of both partner and enemy into
and when running a new battle, all pokemons data will be re-pulled again from And seems like |
Yup👍🏻
Yup, you are right. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, @harunalfat! 🎉🎉🎉
You may now build the adapter. 👍🏻
Summary: