models.py 704 Bytes
from sqlalchemy import (
    Column,
    Integer,
    String,
    DateTime,
    JSON,
    CheckConstraint,
    func,
    )
from sqlalchemy.ext.declarative import declarative_base


Base = declarative_base()


class Log(Base):
    __tablename__ = 'log_table'
    id = Column(Integer, primary_key=True)
    created = Column(
            DateTime(timezone=True), nullable=False,
            server_default=func.now())
    table_schema = Column(String(32))
    table_name = Column(String(32), nullable=False)
    operation = Column(
        String(6),
        CheckConstraint("operation IN ('insert', 'update', 'delete')"),
        nullable=False)
    old_values = Column(JSON)
    new_values = Column(JSON)