I am trying to integrate SqlAlchemy with SQLAlchemy-continuum. I use Automap feature instead of making declarative classes, I have been unable to use continuum with the automap feature. Also there are no examples or citations in the docs regarding the same.
Has anybody used SqlAlchemy-continuum with this feature.
Note - I am using custom schemas for postrgesql, the schema is not the default the postrges ships with.
Also adding some code for reference:
#Imports
from sqlalchemy.ext.automap import automap_base
from sqlalchemy_continuum import make_versioned
from sqlalchemy_continuum import version_class, parent_class
make_versioned(user_cls=None) #Currently trying to not make user relationship with transactions table.
#Created the engine and queried the schema metadata from there in _metdadata.
_metdadata.reflect(views=True)
Base = automap_base(metadata=_metdadata)
class Map1(Base):
__tablename__ = 'test_pg_audit'
__table_args__ = {'extend_existing': 'True'}
__versioned__ = {}
id = Column(Integer, primary_key=True)
Base.prepare()
rec = TestPGAudit(name='test')
dbsession.add(rec)
dbsession.flush()
dbsession.commit()
#The History Class is not found, and sqlalchemy_continuum.exc.ClassNotVersioned is raise here.
at = version_class(TestPGAudit)
recs = dbsession.query(at).all()
print recs
I have also tried configuring the mappers at different places including after Base.prepare, but to no avail. Also tried creating history tables in database manually.
Any help is appreciated.
from sqlalchemy-continuum with Automap Base
No comments:
Post a Comment