From 48f3957aabd77c61e1231e4b2ff564ebc49865b1 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Mon, 6 Feb 2012 00:43:47 +0100 Subject: [PATCH] Add the VersionGroupPokemonMoveMethod table --- .../version_group_pokemon_move_methods.csv | 54 +++++++++++++++++++ pokedex/db/tables.py | 23 ++++++++ scripts/version-group-pokemon-move-methods.py | 35 ++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 pokedex/data/csv/version_group_pokemon_move_methods.csv create mode 100644 scripts/version-group-pokemon-move-methods.py diff --git a/pokedex/data/csv/version_group_pokemon_move_methods.csv b/pokedex/data/csv/version_group_pokemon_move_methods.csv new file mode 100644 index 0000000..7470b25 --- /dev/null +++ b/pokedex/data/csv/version_group_pokemon_move_methods.csv @@ -0,0 +1,54 @@ +version_group_id,pokemon_move_method_id +1,1 +1,4 +1,5 +2,1 +2,4 +2,5 +3,1 +3,2 +3,4 +4,1 +4,2 +4,3 +4,4 +5,1 +5,2 +5,4 +5,6 +6,1 +6,2 +6,3 +6,4 +6,6 +7,1 +7,2 +7,3 +7,4 +7,6 +8,1 +8,2 +8,3 +8,4 +8,6 +9,1 +9,2 +9,3 +9,4 +9,6 +9,10 +10,1 +10,2 +10,3 +10,4 +10,6 +10,10 +11,1 +11,2 +11,3 +11,4 +11,6 +11,10 +12,1 +13,1 +13,3 diff --git a/pokedex/db/tables.py b/pokedex/db/tables.py index 704eeef..40335f3 100644 --- a/pokedex/db/tables.py +++ b/pokedex/db/tables.py @@ -1590,6 +1590,18 @@ class VersionGroup(TableBase): order = Column(Integer, nullable=True, info=dict(description=u"Order for sorting. Almost by date of release, except similar versions are grouped together.")) +class VersionGroupPokemonMoveMethod(TableBase): + u"""Maps a version group to a move learn methods it supports. + + "Supporting" means simply that the method appears in the game. + For example, Breeding didn't exist in Gen.I, so it's not in this table. + """ + __tablename__ = 'version_group_pokemon_move_methods' + version_group_id = Column(Integer, ForeignKey('version_groups.id'), primary_key=True, nullable=False, + info=dict(description=u"The ID of the version group.")) + pokemon_move_method_id = Column(Integer, ForeignKey('pokemon_move_methods.id'), primary_key=True, nullable=False, + info=dict(description=u"The ID of the move method.")) + class VersionGroupRegion(TableBase): u"""Maps a version group to a region that appears in it.""" __tablename__ = 'version_group_regions' @@ -2109,3 +2121,14 @@ VersionGroup.generation = relationship(Generation, VersionGroup.version_group_regions = relationship(VersionGroupRegion, backref='version_group') VersionGroup.regions = association_proxy('version_group_regions', 'region') +VersionGroup.pokemon_move_methods = relationship(PokemonMoveMethod, + secondary=VersionGroupPokemonMoveMethod.__table__, + primaryjoin=and_(VersionGroup.id == VersionGroupPokemonMoveMethod.version_group_id), + secondaryjoin=and_(PokemonMoveMethod.id == VersionGroupPokemonMoveMethod.pokemon_move_method_id), + backref="version_groups") + + +VersionGroupPokemonMoveMethod.version_group = relationship(VersionGroup, + backref='version_group_move_methods') +VersionGroupPokemonMoveMethod.pokemon_move_method = relationship(PokemonMoveMethod, + backref='version_group_move_methods') diff --git a/scripts/version-group-pokemon-move-methods.py b/scripts/version-group-pokemon-move-methods.py new file mode 100644 index 0000000..4b09663 --- /dev/null +++ b/scripts/version-group-pokemon-move-methods.py @@ -0,0 +1,35 @@ +# Encoding: UTF-8 +"""Fill the version_group_pokemon_move_methods table + +This is an unmaintained one-shot script, only included in the repo for reference. + + +""" + + +from sqlalchemy.sql import exists, func +from sqlalchemy.orm import lazyload +from sqlalchemy import and_, or_, not_ + +from pokedex.db import connect, tables, load + +session = connect() + +session.query(tables.VersionGroupPokemonMoveMethod).delete() + +q = session.query(tables.VersionGroup, tables.PokemonMoveMethod) +q = q.filter(exists().where(and_( + tables.PokemonMove.pokemon_move_method_id == tables.PokemonMoveMethod.id, + tables.PokemonMove.version_group_id == tables.VersionGroup.id))) +q = q.options(lazyload('*')) +for version_group, pokemon_move_method in q: + entry = tables.VersionGroupPokemonMoveMethod( + version_group=version_group, + pokemon_move_method=pokemon_move_method, + ) + session.add(entry) + + +load.dump(session, tables=['version_group_pokemon_move_methods']) +print "Dumped to CSV, rolling back transaction" +session.rollback()