Revert aggressive renaming; add check to make sure connect doesn't rewrite _original_name

This commit is contained in:
Epithumia 2013-12-19 06:52:51 +01:00
parent 3f63e3c802
commit aa9fd809bf
2 changed files with 10 additions and 21 deletions

View file

@ -50,18 +50,16 @@ def connect(uri=None, session_args={}, engine_args={}, engine_prefix=''):
# Shorten table names, Oracle limits table and column names to 30 chars # Shorten table names, Oracle limits table and column names to 30 chars
# Easy solution : drop the vowels, differents words are unlikely to # Easy solution : drop the vowels, differents words are unlikely to
# end up the same after the vowels are gone # end up the same after the vowels are gone
try:
# Check we haven't already shortened the names
metadata.tables.values()[1]._original_name
except NameError:
for table in metadata.tables.values(): for table in metadata.tables.values():
table._orginal_name = table.name[:] table._orginal_name = table.name[:]
if len(table.name) > 30: if len(table.name) > 30:
for letter in ['a', 'e', 'i', 'o', 'u', 'y']: for letter in ['a', 'e', 'i', 'o', 'u', 'y']:
table.name=table.name.replace(letter,'') 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 ### Connect
engine_args[engine_prefix + 'url'] = uri engine_args[engine_prefix + 'url'] = uri

View file

@ -155,15 +155,6 @@ def load(session, tables=[], directory=None, drop_tables=False, verbose=False, s
for letter in ['a', 'e', 'i', 'o', 'u', 'y']: for letter in ['a', 'e', 'i', 'o', 'u', 'y']:
table.name=table.name.replace(letter,'') table.name=table.name.replace(letter,'')
oradict[table.name]=table._orginal_name 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: if recursive:
table_objs.extend(find_dependent_tables(table_objs)) table_objs.extend(find_dependent_tables(table_objs))