Eagerload PokemonName.language.
[zzz-pokedex.git] / pokedex / db / tables.py
index 177309a..1f6d3e1 100644 (file)
@@ -573,7 +573,7 @@ class MoveDamageClass(TableBase):
     __tablename__ = 'move_damage_classes'
     id = Column(Integer, primary_key=True, nullable=False,
         info=dict(description="A numeric ID"))
-    name = Column(Unicode(8), nullable=False,
+    name = Column(Unicode(16), nullable=False,
         info=dict(description="An English name of the class", format='plaintext'))
     description = Column(Unicode(64), nullable=False,
         info=dict(description="An English description of the class", format='plaintext'))
@@ -589,6 +589,16 @@ class MoveEffect(TableBase):
     effect = Column(Unicode(5120), nullable=False,
         info=dict(description="A detailed description of the effect", format='plaintext'))
 
+class MoveEffectChangelog(TableBase):
+    """History of changes to move effects across main game versions."""
+    __tablename__ = 'move_effect_changelog'
+    effect_id = Column(Integer, ForeignKey('move_effects.id'), primary_key=True, nullable=False,
+        info=dict(description="The ID of the effect that changed"))
+    changed_in_version_group_id = Column(Integer, ForeignKey('version_groups.id'), primary_key=True, nullable=False,
+        info=dict(description="The ID of the version group in which the effect changed"))
+    effect = Column(markdown.MarkdownColumn(255), nullable=False,
+        info=dict(description="A description of the old behavior", format='markdown'))
+
 class MoveFlag(TableBase):
     u"""Maps a move flag to a move
     """
@@ -673,7 +683,7 @@ class Move(TableBase):
         info=dict(description="ID of the damage class (physical/special) of the move"))
     effect_id = Column(Integer, ForeignKey('move_effects.id'), nullable=False,
         info=dict(description="ID of the move's effect"))
-    effect_chance = Column(Integer,
+    effect_chance = Column(Integer, nullable=True,
         info=dict(description="The chance for a secondary effect. What this is a chance of is specified by the move's effect."))
     contest_type_id = Column(Integer, ForeignKey('contest_types.id'), nullable=True,
         info=dict(description="ID of the move's Contest type (e.g. cool or smart)"))
@@ -689,12 +699,18 @@ class MoveChangelog(TableBase):
         info=dict(description="ID of the move that changed"))
     changed_in_version_group_id = Column(Integer, ForeignKey('version_groups.id'), primary_key=True, nullable=False,
         info=dict(description="ID of the version group in which the move changed"))
+    type_id = Column(Integer, ForeignKey('types.id'), nullable=True,
+        info=dict(description="Prior type of the move, or NULL if unchanged"))
     power = Column(SmallInteger, nullable=True,
         info=dict(description="Prior base power of the move, or NULL if unchanged"))
     pp = Column(SmallInteger, nullable=True,
         info=dict(description="Prior base PP of the move, or NULL if unchanged"))
     accuracy = Column(SmallInteger, nullable=True,
         info=dict(description="Prior accuracy of the move, or NULL if unchanged"))
+    effect_id = Column(Integer, ForeignKey('move_effects.id'), nullable=True,
+        info=dict(description="Prior ID of the effect, or NULL if unchanged"))
+    effect_chance = Column(Integer, nullable=True,
+        info=dict(description="Prior effect chance, or NULL if unchanged"))
 
 class Nature(TableBase):
     u"""A nature a pokémon can have, such as Calm or Brave
@@ -1290,8 +1306,25 @@ Ability.changelog = relation(AbilityChangelog,
 Ability.flavor_text = relation(AbilityFlavorText, order_by=AbilityFlavorText.version_group_id, backref='ability')
 Ability.foreign_names = relation(AbilityName, backref='ability')
 Ability.generation = relation(Generation, backref='abilities')
+Ability.all_pokemon = relation(Pokemon,
+    secondary=PokemonAbility.__table__,
+    back_populates='all_abilities',
+)
 Ability.pokemon = relation(Pokemon,
     secondary=PokemonAbility.__table__,
+    primaryjoin=and_(
+        PokemonAbility.ability_id == Ability.id,
+        PokemonAbility.is_dream == False
+    ),
+    back_populates='abilities',
+)
+Ability.dream_pokemon = relation(Pokemon,
+    secondary=PokemonAbility.__table__,
+    primaryjoin=and_(
+        PokemonAbility.ability_id == Ability.id,
+        PokemonAbility.is_dream == True
+    ),
+    back_populates='dream_ability',
 )
 
 AbilityChangelog.changed_in = relation(VersionGroup, backref='ability_changelog')
@@ -1546,7 +1579,7 @@ PokemonMove.machine = relation(Machine, backref='pokemon_moves',
 PokemonMove.move = relation(Move, backref='pokemon_moves')
 PokemonMove.method = relation(PokemonMoveMethod)
 
-PokemonName.language = relation(Language)
+PokemonName.language = relation(Language, lazy='joined')
 
 PokemonStat.stat = relation(Stat)