2022-04-04 11:27:04 +00:00
|
|
|
from citext import CIText
|
2022-04-12 08:24:32 +00:00
|
|
|
from flask import g
|
2022-04-04 11:27:04 +00:00
|
|
|
from sqlalchemy import BigInteger, Column, Sequence, SmallInteger
|
|
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
|
|
|
|
|
|
from ereuse_devicehub.db import db
|
2022-05-18 09:00:04 +00:00
|
|
|
from ereuse_devicehub.resources.action.models import Snapshot
|
2022-04-04 11:27:04 +00:00
|
|
|
from ereuse_devicehub.resources.enums import Severity
|
|
|
|
from ereuse_devicehub.resources.models import Thing
|
2022-04-12 08:24:32 +00:00
|
|
|
from ereuse_devicehub.resources.user.models import User
|
2022-04-04 11:27:04 +00:00
|
|
|
|
|
|
|
|
2022-05-18 09:00:04 +00:00
|
|
|
class SnapshotsLog(Thing):
|
2022-04-04 11:27:04 +00:00
|
|
|
"""A Snapshot errors."""
|
|
|
|
|
2022-05-18 09:00:04 +00:00
|
|
|
id = Column(BigInteger, Sequence('snapshots_log_seq'), primary_key=True)
|
2022-04-04 11:27:04 +00:00
|
|
|
severity = Column(SmallInteger, default=Severity.Info, nullable=False)
|
2022-05-18 09:00:04 +00:00
|
|
|
workbench_version = Column(CIText(), default='', nullable=True)
|
|
|
|
description = Column(CIText(), default='', nullable=True)
|
|
|
|
sid = Column(CIText(), nullable=True)
|
|
|
|
dhid = Column(CIText(), nullable=True)
|
|
|
|
snapshot_id = Column(UUID(as_uuid=True), db.ForeignKey(User.id), nullable=True)
|
2022-04-12 08:24:32 +00:00
|
|
|
owner_id = db.Column(
|
|
|
|
UUID(as_uuid=True),
|
|
|
|
db.ForeignKey(User.id),
|
|
|
|
nullable=False,
|
|
|
|
default=lambda: g.user.id,
|
|
|
|
)
|
2022-05-18 09:00:04 +00:00
|
|
|
snapshot = db.relationship(User, primaryjoin=snapshot_id == Snapshot.id)
|
2022-04-12 08:24:32 +00:00
|
|
|
owner = db.relationship(User, primaryjoin=owner_id == User.id)
|
2022-04-04 11:27:04 +00:00
|
|
|
|
|
|
|
def save(self, commit=False):
|
|
|
|
db.session.add(self)
|
|
|
|
|
|
|
|
if commit:
|
|
|
|
db.session.commit()
|