corridor / sqlalchemy-history

Library to keep track of changes in SQLAlchemy.
Other
32 stars 24 forks source link

table_name not being applied to versioned Class name #116

Open indiVar0508 opened 11 months ago

indiVar0508 commented 11 months ago

We don't refer consider table_name when creating versioned class, so need to look into a better configuration option or a patchy fix that we did in #69

from sqlalchemy_history import make_versioned, version_class
from sqlalchemy import Column, Integer, Unicode, UnicodeText
from sqlalchemy.orm import declarative_base
from sqlalchemy.orm import configure_mappers
make_versioned(user_cls=None, options={"table_name": "%s_user_defined"})
Base = declarative_base()
class Article(Base):
    __versioned__ = {}
    __tablename__ = 'article'
    id = Column(Integer, primary_key=True, autoincrement=True)
    name = Column(Unicode(255))
    content = Column(UnicodeText)
configure_mappers()
print(Article)
print(version_class(Article)) # Gives ArticleVersion but it should have been ArticleUserDefined