You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2.9 KiB
2.9 KiB
About the database schema
Collections
trainers collection
- _id: ObjectId
- name: string
- (indexed: would often be queried in a dashboard situation)
- dob: date
- wins: int
- losses: int
- pastOpponents: array of ObjectId (references to other trainers)
- (indexed: reflexivity would make deep queries quite slow, so it seems worthwhile)
- pokemongs: array of ObjectId (references to owned pokemongs) + denormalizing on "nickname" and "species"
- (indexed: to improve speed when querying non-denormalized fields)
pokemongs collection
- _id: ObjectId
- nickname: string?
- dob: date
- level: int
- pokedexId: int
- evoStage: int
- (indexed: "species" is calculated as evoTrack[evoStage], and would often be queried)
- evoTrack: array of strings (therefore "species" is evoTrack[evoStage], and "evoBase" is evoTrack[0])
- (indexed: "species" is calculated as evoTrack[evoStage], and would be queried often)
- trainer: ObjectId? (reference to a trainer) (but can be "wild" instead, if ref is null)
- (indexed: could be queried often in a dashboard situation)
- types: embedded type, or array of embedded types
- (indexed: would often be queried in a dashboard situation)
- moveSet: array of ObjectId (references to known moves) + denormalizing on "name"
moves collection
- _id: ObjectId
- name: string
- (indexed: would often be queried in a dashboard situation)
- category: string (can be "physical", "special", or "status")
- power: int
- (indexed: would often be used in sorts, in a dashboard situation)
- accuracy: int
- type: embedded type
- (indexed: would often be queried in a dashboard situation)
types collection
- _id: ObjectId
- name: string
- (indexed: would often be queried in a dashboard situation)
- weakAgainst: array of strings (denormalized type names)
- effectiveAgainst: array of strings (denormalized type names)
Relationships
- Trainer
- trainers.pastOpponents: one-to-many and reflexive
- => referencing
- trainers.pokemongs: one-to-many
- => referencing + denormalizing on "nickname" and "species"
- trainers.pastOpponents: one-to-many and reflexive
- Pokemong
- pokemongs.trainer: many-to-one
- => referencing
- pokemongs.types: one-to-few [1;2]
- => embedding
- pokemongs.moveSet: one-to-few [0;4] but will also need to be queried independently
- => referencing + denormalizing on "name"
- pokemongs.trainer: many-to-one
- Move
- moves.type: one-to-one [1;1]
- => embedding
- moves.type: one-to-one [1;1]
- Type
- types.weakAgainst & types.effectiveAgainst: one-to-few, but reflexive
- => denormalizing on "name"
- types.weakAgainst & types.effectiveAgainst: one-to-few, but reflexive
Cascades
- Pokemong
- delete ~> trainer.pokemongs
- update ~> trainer.pokemongs (denormalizing on "nickname" and "species")
- create ~> trainer.pokemongs
- Trainer
- delete ~> pokemong.trainer
- create ~> pokemong.trainer
- Move
- delete ~> pokemong.moveSet
- update ~> pokemong.moveSet (denormalizing on "name")