2021-04-21 16:47:18 +00:00
|
|
|
"""
|
|
|
|
This module defines the BoolOperation database class.
|
|
|
|
"""
|
|
|
|
|
2021-05-07 17:46:14 +00:00
|
|
|
from ..base import ext
|
2021-04-21 16:47:18 +00:00
|
|
|
from .Enums import OperationType
|
2021-05-07 17:46:14 +00:00
|
|
|
from sqlalchemy.orm import backref
|
2021-04-21 16:47:18 +00:00
|
|
|
|
|
|
|
|
2021-05-07 17:46:14 +00:00
|
|
|
class BoolOperation(ext.Model):
|
2021-04-21 16:47:18 +00:00
|
|
|
__tablename__ = "bool_operation"
|
2021-05-07 17:46:14 +00:00
|
|
|
id = ext.Column(ext.Integer, primary_key=True)
|
|
|
|
operation = ext.Column(ext.Enum(OperationType), nullable=False)
|
|
|
|
isRoot = ext.Column(ext.Boolean, default=False, nullable=False)
|
2021-04-21 16:47:18 +00:00
|
|
|
# Foreign Keys
|
2021-05-07 17:46:14 +00:00
|
|
|
condition_id = ext.Column(ext.Integer, ext.ForeignKey("condition.id"))
|
|
|
|
node_1_id = ext.Column(ext.Integer, ext.ForeignKey("bool_operation.id"))
|
|
|
|
node_2_id = ext.Column(ext.Integer, ext.ForeignKey("bool_operation.id"))
|
|
|
|
alert_id = ext.Column(ext.Integer, ext.ForeignKey("alert.id"))
|
2021-04-21 16:47:18 +00:00
|
|
|
# Relationships
|
2021-05-07 17:46:14 +00:00
|
|
|
condition = ext.relationship("Condition", back_populates="operations")
|
|
|
|
node_1 = ext.relationship("BoolOperation", primaryjoin=("bool_operation.c.node_1_id==bool_operation.c.id"),
|
|
|
|
remote_side="BoolOperation.id", backref=backref("father_1", uselist=False))
|
|
|
|
node_2 = ext.relationship("BoolOperation", primaryjoin=("bool_operation.c.node_2_id==bool_operation.c.id"),
|
|
|
|
remote_side="BoolOperation.id", backref=backref("father_2", uselist=False))
|
|
|
|
alert = ext.relationship("Alert", back_populates="operations")
|