SqlAlchemy Continuum: history and transaction tables are not created

Question:

I am trying to integrate sqlalchemy-continuum versioning into an existing application that uses flask-sqlalchemy.

I have a __versioned__ = {} to the models I want to have versioned e.g.:

class User(Base):
    __versioned__ = {}
    __tablename__ = 'user'

And I am trying to initialize sqlalchemy-continuum as follows:

from flask_sqlalchemy import SQLAlchemy
from sqlalchemy_continuum import make_versioned
from sqlalchemy.orm import configure_mappers

class SQLOrm():
    def __init__(self):
        if not hasattr(self, 'orm'):
            make_versioned(user_cls=None)
            self.orm = SQLAlchemy()
            configure_mappers()

    # ... 

db_orm = SQLOrm()

But the transaction table and history tables are not created. I can see continuum is trying to create records, but there are no tables:

LINE 1: INSERT INTO transaction (issued_at, id, remote_addr) VALUES ...
                     ^
[SQL: "INSERT INTO transaction (issued_at, id, remote_addr) VALUES (%(issued_at)s, nextval('transaction_id_seq'), %(remote_addr)s) RETURNING transaction.id"] [parameters: {'issued_at': datetime.datetime(2019, 5, 3, 0, 46, 39, 699358), 'remote_addr': None}] (Background on this error at: http://sqlalche.me/e/f405)

There is something wrong in the way I am initializing this. Any idea what I am doing wrong?

Asked By: Andrei Savin

||

Answers:

You have to create the table before use sqlalchemy-continuum.
You can create the table via script, create it with db.create_all() or otherwise make an alembic migration.

Answered By: user3558532