Skip to content

Commit

Permalink
Fix #238: handling hardcoded string with options.tablename attribute …
Browse files Browse the repository at this point in the history
…via version_manager
  • Loading branch information
indiVar0508 authored and marksteward committed Aug 28, 2022
1 parent 38cef84 commit 1bc630e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions sqlalchemy_continuum/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
get_primary_keys,
identity,
naturally_equivalent,
get_mapper
)

from .exc import ClassNotVersioned
Expand Down Expand Up @@ -133,17 +134,20 @@ def version_table(table):
:param table: SQLAlchemy Table object
"""
mapped_class = get_mapper(table).class_
table_name_format = option(mapped_class, 'table_name') # '%s_version' by default
suffixed_table_name = table_name_format % table.name
if table.schema:
return table.metadata.tables[
table.schema + '.' + table.name + '_version'
table.schema + '.' + suffixed_table_name
]
elif table.metadata.schema:
return table.metadata.tables[
table.metadata.schema + '.' + table.name + '_version'
table.metadata.schema + '.' + suffixed_table_name
]
else:
return table.metadata.tables[
table.name + '_version'
suffixed_table_name
]


Expand Down

0 comments on commit 1bc630e

Please sign in to comment.