2013-12-20 23:06:27 +00:00
|
|
|
from pokedex.db import metadata
|
|
|
|
|
|
|
|
### Helper functions for oracle
|
|
|
|
def rewrite_long_table_names():
|
|
|
|
"""Modifies the table names to disenvowel long table names.
|
2013-12-22 18:21:01 +00:00
|
|
|
Takes the metadata from memory or uses the imported one.
|
|
|
|
|
|
|
|
Returns a dictionary matching short names -> long names.
|
2013-12-20 23:06:27 +00:00
|
|
|
"""
|
2013-12-22 18:21:01 +00:00
|
|
|
|
|
|
|
# Load table names from metadata
|
2013-12-20 23:06:27 +00:00
|
|
|
t_names = metadata.tables.keys()
|
|
|
|
|
|
|
|
table_names = list(t_names)
|
|
|
|
table_objs = [metadata.tables[name] for name in table_names]
|
|
|
|
|
|
|
|
# Prepare a dictionary to match old<->new names
|
2013-12-22 18:21:01 +00:00
|
|
|
dictionary = {}
|
2013-12-20 23:06:27 +00:00
|
|
|
|
|
|
|
# Shorten table names, Oracle limits table and column names to 30 chars
|
|
|
|
for table in table_objs:
|
|
|
|
table._orginal_name = table.name[:]
|
2013-12-22 18:21:01 +00:00
|
|
|
dictionary[table.name]=table._orginal_name
|
2013-12-20 23:06:27 +00:00
|
|
|
if len(table._orginal_name) > 30:
|
|
|
|
for letter in ['a', 'e', 'i', 'o', 'u', 'y']:
|
|
|
|
table.name=table.name.replace(letter,'')
|
2013-12-22 18:21:01 +00:00
|
|
|
dictionary[table.name]=table._orginal_name
|
|
|
|
return dictionary
|
2013-12-20 23:06:27 +00:00
|
|
|
|
|
|
|
|
2013-12-22 18:21:01 +00:00
|
|
|
def restore_long_table_names(metadata,dictionary):
|
2013-12-20 23:06:27 +00:00
|
|
|
"""Modifies the table names to restore the long-naming.
|
2013-12-22 18:21:01 +00:00
|
|
|
|
|
|
|
`metadata`
|
|
|
|
The metadata to restore.
|
|
|
|
|
|
|
|
`dictionary`
|
|
|
|
The dictionary matching short name -> long name.
|
2013-12-20 23:06:27 +00:00
|
|
|
"""
|
|
|
|
for table in metadata.tables.values():
|
2013-12-22 18:21:01 +00:00
|
|
|
table.name = dictionary[table.name]
|