X-Git-Url: http://git.veekun.com/zzz-pokedex.git/blobdiff_plain/05307971f700f0d7f379a90172cc96add8641c72..686c1ce41669bfd1d0837d37733e5a6a8616389c:/pokedex/db/tables.py diff --git a/pokedex/db/tables.py b/pokedex/db/tables.py index 965cf6b..59755a7 100644 --- a/pokedex/db/tables.py +++ b/pokedex/db/tables.py @@ -53,6 +53,16 @@ class Ability(TableBase): short_effect = Column(markdown.MarkdownColumn(255), nullable=False, info=dict(description="Short summary of this ability's effect", format='markdown')) +class AbilityChangelog(TableBase): + """History of changes to abilities across main game versions.""" + __tablename__ = 'ability_changelog' + ability_id = Column(Integer, ForeignKey('abilities.id'), primary_key=True, nullable=False, + info=dict(description="The ID of the ability 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 ability changed")) + effect = Column(markdown.MarkdownColumn(255), nullable=False, + info=dict(description="A description of the old behavior", format='markdown')) + class AbilityFlavorText(TableBase): u"""In-game flavor text of an ability """ @@ -563,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')) @@ -771,15 +781,6 @@ class Pokedex(TableBase): description = Column(Unicode(512), info=dict(description=u"A longer description of the pokédex", format='plaintext')) -class PokedexVersionGroup(TableBase): - u"""Maps a pokédex to the version group that uses it - """ - __tablename__ = 'pokedex_version_groups' - pokedex_id = Column(Integer, ForeignKey('pokedexes.id'), primary_key=True, nullable=False, autoincrement=False, - info=dict(description=u"ID of the pokédex")) - version_group_id = Column(Integer, ForeignKey('version_groups.id'), primary_key=True, nullable=False, autoincrement=False, - info=dict(description=u"ID of the version group")) - class Pokemon(TableBase): u"""A species of Pokémon. The core to this whole mess. """ @@ -1257,6 +1258,8 @@ class VersionGroup(TableBase): info=dict(description=u"A numeric ID")) generation_id = Column(Integer, ForeignKey('generations.id'), nullable=False, info=dict(description=u"ID of the generation the games of this group belong to")) + pokedex_id = Column(Integer, ForeignKey('pokedexes.id'), nullable=False, + info=dict(description=u"ID of the regional Pokédex used in this version group.")) class VersionGroupRegion(TableBase): u"""Maps a region to a game version group that features it @@ -1268,18 +1271,22 @@ class VersionGroupRegion(TableBase): info=dict(description=u"ID of the region")) class Version(TableBase): - u"""A version of a mainline pokémon game + u"""An individual main-series Pokémon game """ __tablename__ = 'versions' id = Column(Integer, primary_key=True, nullable=False, - info=dict(description=u"A numeric ID")) + info=dict(description=u"A unique ID for this version")) version_group_id = Column(Integer, ForeignKey('version_groups.id'), nullable=False, - info=dict(description=u"ID of the version group this game belongs to")) + info=dict(description=u"The ID of the version group this game belongs to")) name = Column(Unicode(32), nullable=False, info=dict(description=u'The English name of the game, without the "Pokémon" prefix', official=True, format='plaintext')) ### Relations down here, to avoid ordering problems +Ability.changelog = relation(AbilityChangelog, + order_by=AbilityChangelog.changed_in_version_group_id.desc(), + backref='ability', +) 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') @@ -1287,6 +1294,8 @@ Ability.pokemon = relation(Pokemon, secondary=PokemonAbility.__table__, ) +AbilityChangelog.changed_in = relation(VersionGroup, backref='ability_changelog') + AbilityFlavorText.version_group = relation(VersionGroup) AbilityName.language = relation(Language) @@ -1366,7 +1375,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') @@ -1423,7 +1432,7 @@ NatureName.language = relation(Language) NaturePokeathlonStat.pokeathlon_stat = relation(PokeathlonStat, backref='nature_effects') Pokedex.region = relation(Region, backref='pokedexes') -Pokedex.version_groups = relation(VersionGroup, secondary=PokedexVersionGroup.__table__, backref='pokedexes') +Pokedex.version_groups = relation(VersionGroup, order_by=VersionGroup.id, back_populates='pokedex') Pokemon.all_abilities = relation(Ability, secondary=PokemonAbility.__table__, @@ -1569,9 +1578,11 @@ Type.foreign_names = relation(TypeName, backref='type') 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') +VersionGroup.pokedex = relation(Pokedex, back_populates='version_groups')