Support kaburumo and chobomaki's trade-for-each other evolution. #378
[zzz-pokedex.git] / pokedex / db / tables.py
index 958cfb7..a0a12a5 100644 (file)
@@ -363,6 +363,8 @@ class Item(TableBase):
         info=dict(description=u"Power of the move Fling when used with this item."))
     fling_effect_id = Column(Integer, ForeignKey('item_fling_effects.id'), nullable=True,
         info=dict(description=u"ID of the fling-effect of the move Fling when used with this item. Note that these are different from move effects."))
+    short_effect = Column(Unicode(256), nullable=False,
+        info=dict(description="A short summary of the effect", format='plaintext'))
     effect = Column(markdown.MarkdownColumn(5120), nullable=False,
         info=dict(description=u"Detailed English description of the item's effect.", format='markdown'))
 
@@ -573,7 +575,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 +591,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 +685,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 +701,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
@@ -823,6 +841,8 @@ class Pokemon(TableBase):
         info=dict(description=u"Set iff the species' female front sprite is different from the male's in generation IV"))
     has_gen4_fem_back_sprite = Column(Boolean, nullable=False,
         info=dict(description=u"Set iff the species' female back sprite is different from the male's in generation IV"))
+    order = Column(Integer, nullable=False, index=True,
+        info=dict(description=u"Order for sorting. Almost national order, except families and forms are grouped together."))
 
     ### Stuff to handle alternate Pokémon forms
 
@@ -976,7 +996,9 @@ class PokemonEvolution(TableBase):
     relative_physical_stats = Column(Integer, nullable=True,
         info=dict(description=u"Relation of Attack and Defense stats the pokémon must have, as sgn(atk-def), or None if that doesn't matter"))
     party_pokemon_id = Column(Integer, ForeignKey('pokemon.id'), nullable=True,
-        info=dict(description=u"ID of a pokémon that must be present in the party, or None if there's no such condition"))
+        info=dict(description=u"The ID of the Pokémon that must be present in the party."))
+    trade_pokemon_id = Column(Integer, ForeignKey('pokemon.id'), nullable=True,
+        info=dict(description=u"The ID of the Pokémon for which this Pokémon must be traded."))
 
 class PokemonFlavorText(TableBase):
     u"""In-game pokédex descrption of a pokémon.
@@ -1290,8 +1312,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')
@@ -1333,6 +1372,7 @@ EncounterSlotCondition.condition = relation(EncounterCondition,
 
 EvolutionChain.growth_rate = relation(GrowthRate, backref='evolution_chains')
 EvolutionChain.baby_trigger_item = relation(Item, backref='evolution_chains')
+EvolutionChain.pokemon = relation(Pokemon, order_by=Pokemon.order, back_populates='evolution_chain')
 
 Experience.growth_rate = relation(GrowthRate, backref='experience_table')
 
@@ -1375,7 +1415,7 @@ Machine.item = relation(Item)
 Machine.version_group = relation(VersionGroup)
 
 Move.changelog = relation(MoveChangelog,
-    order_by=MoveChangelog.changed_in_version_group_id.asc(),
+    order_by=MoveChangelog.changed_in_version_group_id.desc(),
     backref='move',
 )
 Move.contest_effect = relation(ContestEffect, backref='moves')
@@ -1400,6 +1440,11 @@ Move.effect = markdown.MoveEffectProperty('effect')
 Move.short_effect = markdown.MoveEffectProperty('short_effect')
 
 MoveChangelog.changed_in = relation(VersionGroup, backref='move_changelog')
+MoveChangelog.move_effect = relation(MoveEffect, backref='move_changelog')
+MoveChangelog.type = relation(Type, backref='move_changelog')
+
+MoveChangelog.effect = markdown.MoveEffectProperty('effect')
+MoveChangelog.short_effect = markdown.MoveEffectProperty('short_effect')
 
 MoveEffect.category_map = relation(MoveEffectCategoryMap)
 MoveEffect.categories = association_proxy('category_map', 'category')
@@ -1459,8 +1504,8 @@ Pokemon.color = association_proxy('pokemon_color', 'name')
 Pokemon.dex_numbers = relation(PokemonDexNumber, order_by=PokemonDexNumber.pokedex_id.asc(), backref='pokemon')
 Pokemon.egg_groups = relation(EggGroup, secondary=PokemonEggGroup.__table__,
                                         order_by=PokemonEggGroup.egg_group_id,
-                                        backref='pokemon')
-Pokemon.evolution_chain = relation(EvolutionChain, backref='pokemon')
+                                        backref=backref('pokemon', order_by=Pokemon.order))
+Pokemon.evolution_chain = relation(EvolutionChain, back_populates='pokemon')
 Pokemon.child_pokemon = relation(Pokemon,
     primaryjoin=Pokemon.id==PokemonEvolution.from_pokemon_id,
     secondary=PokemonEvolution.__table__,
@@ -1481,7 +1526,9 @@ Pokemon.items = relation(PokemonItem, backref='pokemon')
 Pokemon.generation = relation(Generation, backref='pokemon')
 Pokemon.shape = relation(PokemonShape, backref='pokemon')
 Pokemon.stats = relation(PokemonStat, backref='pokemon', order_by=PokemonStat.stat_id.asc())
-Pokemon.types = relation(Type, secondary=PokemonType.__table__, order_by=PokemonType.slot.asc(), backref='pokemon')
+Pokemon.types = relation(Type, secondary=PokemonType.__table__,
+                               order_by=PokemonType.slot.asc(),
+                               back_populates='pokemon')
 
 PokemonDexNumber.pokedex = relation(Pokedex)
 
@@ -1516,6 +1563,9 @@ PokemonEvolution.party_pokemon = relation(Pokemon,
     primaryjoin=PokemonEvolution.party_pokemon_id==Pokemon.id,
     backref='triggered_evolutions',
 )
+PokemonEvolution.trade_pokemon = relation(Pokemon,
+    primaryjoin=PokemonEvolution.trade_pokemon_id==Pokemon.id,
+)
 
 PokemonFlavorText.version = relation(Version)
 
@@ -1546,7 +1596,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)
 
@@ -1575,12 +1625,16 @@ Type.target_efficacies = relation(TypeEfficacy,
 Type.generation = relation(Generation, backref='types')
 Type.damage_class = relation(MoveDamageClass, backref='types')
 Type.foreign_names = relation(TypeName, backref='type')
+Type.pokemon = relation(Pokemon, secondary=PokemonType.__table__,
+                                 order_by=Pokemon.order,
+                                 back_populates='types')
 
 TypeName.language = relation(Language)
 
-Version.version_group = relation(VersionGroup, backref='versions')
+Version.version_group = relation(VersionGroup, back_populates='versions')
 Version.generation = association_proxy('version_group', 'generation')
 
+VersionGroup.versions = relation(Version, order_by=Version.id, back_populates='version_group')
 VersionGroup.generation = relation(Generation, backref='version_groups')
 VersionGroup.version_group_regions = relation(VersionGroupRegion, backref='version_group')
 VersionGroup.regions = association_proxy('version_group_regions', 'region')