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
This commit is contained in:
Andrew Ekstedt 2021-03-31 22:03:14 -07:00
parent 6fe50101e8
commit da0aac676a

View file

@ -11,11 +11,15 @@ import sqlalchemy.sql.util
import sqlalchemy.types import sqlalchemy.types
import pokedex import pokedex
import pokedex.db.tables as t
from pokedex.db import metadata, translations from pokedex.db import metadata, translations
from pokedex.defaults import get_default_csv_dir from pokedex.defaults import get_default_csv_dir
from pokedex.db.dependencies import find_dependent_tables from pokedex.db.dependencies import find_dependent_tables
from pokedex.db.oracle import rewrite_long_table_names from pokedex.db.oracle import rewrite_long_table_names
from sqlalchemy import and_
from sqlalchemy.sql import exists
def _get_table_names(metadata, patterns): def _get_table_names(metadata, patterns):
"""Returns a list of table names from the given metadata. If `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() session.commit()
print_done() 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') print_start('Translations')
transl = translations.Translations(csv_directory=directory) transl = translations.Translations(csv_directory=directory)