diff --git a/pokedex/db/__init__.py b/pokedex/db/__init__.py index 0bb1705..558a26c 100644 --- a/pokedex/db/__init__.py +++ b/pokedex/db/__init__.py @@ -3,6 +3,8 @@ import re from sqlalchemy import engine_from_config, orm +from hashlib import md5 + from ..defaults import get_default_db_uri from .tables import Language, metadata from .multilang import MultilangSession, MultilangScopedSession @@ -53,6 +55,13 @@ def connect(uri=None, session_args={}, engine_args={}, engine_prefix=''): if len(table.name) > 30: for letter in ['a', 'e', 'i', 'o', 'u', 'y']: table.name=table.name.replace(letter,'') + # Aggressive renaming if the length is still too long: + # Take the initials of the table, add a hash to make a new name + if len(table.name) > 30: + hashedname = md5(table._orginal_name).hexdigest() + shortname = ''.join(word[:1] for word in table.name.split('_')) + shortname = ''.join([shortname, hashedname]) + table.name = shortname[:30] ### Connect engine_args[engine_prefix + 'url'] = uri diff --git a/pokedex/db/load.py b/pokedex/db/load.py index bc52578..251f19e 100644 --- a/pokedex/db/load.py +++ b/pokedex/db/load.py @@ -7,6 +7,8 @@ import sys import sqlalchemy.sql.util import sqlalchemy.types +from hashlib import md5 + import pokedex from pokedex.db import metadata, tables, translations from pokedex.defaults import get_default_csv_dir @@ -153,6 +155,15 @@ def load(session, tables=[], directory=None, drop_tables=False, verbose=False, s for letter in ['a', 'e', 'i', 'o', 'u', 'y']: table.name=table.name.replace(letter,'') oradict[table.name]=table._orginal_name + # Aggressive renaming if the length is still too long: + # Take the initials of the table, add a hash to make a new name + if len(table.name) > 30: + hashedname = md5(table._orginal_name).hexdigest() + shortname = ''.join(word[:1] for word in table.name.split('_')) + shortname = ''.join([shortname, hashedname]) + table.name = shortname[:30] + oradict[table.name]=table._orginal_name + if recursive: table_objs.extend(find_dependent_tables(table_objs))