From 74abc66612025e0ff5e2ebe16ef11c1332fa4adc Mon Sep 17 00:00:00 2001 From: Andrew Ekstedt Date: Wed, 31 Mar 2021 22:03:14 -0700 Subject: [PATCH] Regen VersionGroupPokemonMoveMethods when loading the database Instead of relying on people to remember to run a script to regenerate it, just do it automatically at load time. Only takes a couple seconds. And hey, this gives us a free test too! (CI will complain if load+dump isn't clean.) Fixes #334 Fixes #74 --- pokedex/db/load.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pokedex/db/load.py b/pokedex/db/load.py index 631fc9b..a13cc3f 100644 --- a/pokedex/db/load.py +++ b/pokedex/db/load.py @@ -11,11 +11,15 @@ import sqlalchemy.sql.util import sqlalchemy.types import pokedex +import pokedex.db.tables as t from pokedex.db import metadata, translations from pokedex.defaults import get_default_csv_dir from pokedex.db.dependencies import find_dependent_tables from pokedex.db.oracle import rewrite_long_table_names +from sqlalchemy import and_ +from sqlalchemy.sql import exists + def _get_table_names(metadata, patterns): """Returns a list of table names from the given metadata. If `patterns` @@ -370,6 +374,23 @@ def load(session, tables=[], directory=None, drop_tables=False, verbose=False, s session.commit() print_done() + VGPMM = t.VersionGroupPokemonMoveMethod + if VGPMM.__tablename__ in table_names or t.PokemonMove.__tablename__ in table_names: + print_start('Regenerating %s' % VGPMM.__tablename__) + + session.query(VGPMM).delete() + + q = session.query(t.VersionGroup.id, t.PokemonMoveMethod.id) + q = q.filter(exists().where(and_( + t.PokemonMove.pokemon_move_method_id == t.PokemonMoveMethod.id, + t.PokemonMove.version_group_id == t.VersionGroup.id))) + for version_group_id, pokemon_move_method_id in q: + session.add(VGPMM( + version_group_id=version_group_id, + pokemon_move_method_id=pokemon_move_method_id, + )) + session.commit() + print_done() print_start('Translations') transl = translations.Translations(csv_directory=directory)