Support null pre-D/P damage class for ??? and Shadow.
[zzz-pokedex.git] / pokedex / db / tables.py
index c025059..4375c07 100644 (file)
@@ -984,7 +984,7 @@ class PokemonEvolution(TableBase):
         info=dict(description=u"The ID of the location the evolution must be triggered at."))
     held_item_id = Column(Integer, ForeignKey('items.id'), nullable=True,
         info=dict(description=u"The ID of the item the Pokémon must hold."))
-    time_of_day = Column(Enum('morning', 'day', 'night', name='pokemon_evolution_time_of_day'), nullable=True,
+    time_of_day = Column(Enum('day', 'night', name='pokemon_evolution_time_of_day'), nullable=True,
         info=dict(description=u"The required time of day."))
     known_move_id = Column(Integer, ForeignKey('moves.id'), nullable=True,
         info=dict(description=u"The ID of the move the Pokémon must know."))
@@ -1264,8 +1264,8 @@ class Type(TableBase):
         info=dict(description=u"An arbitrary 3-letter abbreviation of this type.", format='plaintext'))  # XXX: Or is it not arbitrary?
     generation_id = Column(Integer, ForeignKey('generations.id'), nullable=False,
         info=dict(description=u"The ID of the generation this type first appeared in."))
-    damage_class_id = Column(Integer, ForeignKey('move_damage_classes.id'), nullable=False,
-        info=dict(description=u"The ID of the damage class this type's moves had before Generation IV."))
+    damage_class_id = Column(Integer, ForeignKey('move_damage_classes.id'), nullable=True,
+        info=dict(description=u"The ID of the damage class this type's moves had before Generation IV, null if not applicable (e.g. ???)."))
 
 class TypeName(TableBase):
     u"""An official non-English name of an elemental type."""
@@ -1318,6 +1318,7 @@ Ability.foreign_names = relation(AbilityName, backref='ability')
 Ability.generation = relation(Generation, backref='abilities')
 Ability.all_pokemon = relation(Pokemon,
     secondary=PokemonAbility.__table__,
+    order_by=Pokemon.order,
     back_populates='all_abilities',
 )
 Ability.pokemon = relation(Pokemon,
@@ -1326,6 +1327,7 @@ Ability.pokemon = relation(Pokemon,
         PokemonAbility.ability_id == Ability.id,
         PokemonAbility.is_dream == False
     ),
+    order_by=Pokemon.order,
     back_populates='abilities',
 )
 Ability.dream_pokemon = relation(Pokemon,
@@ -1334,6 +1336,7 @@ Ability.dream_pokemon = relation(Pokemon,
         PokemonAbility.ability_id == Ability.id,
         PokemonAbility.is_dream == True
     ),
+    order_by=Pokemon.order,
     back_populates='dream_ability',
 )
 
@@ -1434,7 +1437,7 @@ Move.super_contest_effect = relation(SuperContestEffect, backref='moves')
 Move.super_contest_combo_next = association_proxy('super_contest_combo_first', 'second')
 Move.super_contest_combo_prev = association_proxy('super_contest_combo_second', 'first')
 Move.target = relation(MoveTarget, backref='moves')
-Move.type = relation(Type, backref='moves')
+Move.type = relation(Type, back_populates='moves')
 
 Move.effect = markdown.MoveEffectProperty('effect')
 Move.short_effect = markdown.MoveEffectProperty('short_effect')
@@ -1448,8 +1451,14 @@ MoveChangelog.short_effect = markdown.MoveEffectProperty('short_effect')
 
 MoveEffect.category_map = relation(MoveEffectCategoryMap)
 MoveEffect.categories = association_proxy('category_map', 'category')
+MoveEffect.changelog = relation(MoveEffectChangelog,
+    order_by=MoveEffectChangelog.changed_in_version_group_id.desc(),
+    backref='move_effect',
+)
 MoveEffectCategoryMap.category = relation(MoveEffectCategory)
 
+MoveEffectChangelog.changed_in = relation(VersionGroup, backref='move_effect_changelog')
+
 MoveFlag.flag = relation(MoveFlagType)
 
 MoveFlavorText.version_group = relation(VersionGroup)
@@ -1628,6 +1637,7 @@ Type.foreign_names = relation(TypeName, backref='type')
 Type.pokemon = relation(Pokemon, secondary=PokemonType.__table__,
                                  order_by=Pokemon.order,
                                  back_populates='types')
+Type.moves = relation(Move, back_populates='type', order_by=Move.name)
 
 TypeName.language = relation(Language)