-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathalert_results_models.py
More file actions
53 lines (40 loc) · 1.78 KB
/
alert_results_models.py
File metadata and controls
53 lines (40 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# SPDX-FileCopyrightText: 2025 GitHub
# SPDX-License-Identifier: MIT
from __future__ import annotations
from sqlalchemy import Column, ForeignKey, Integer, Text
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship
class Base(DeclarativeBase):
pass
class AlertResults(Base):
__tablename__ = "alert_results"
canonical_id: Mapped[int] = mapped_column(primary_key=True)
alert_id: Mapped[str]
repo: Mapped[str]
rule: Mapped[str]
language: Mapped[str]
location: Mapped[str]
result: Mapped[str] = mapped_column(Text)
created: Mapped[str | None]
valid: Mapped[bool] = mapped_column(nullable=False, default=True)
completed: Mapped[bool] = mapped_column(nullable=False, default=False)
relationship("AlertFlowGraph", cascade="all, delete")
def __repr__(self):
return (
f"<AlertResults(alert_id={self.alert_id}, repo={self.repo}, "
f"rule={self.rule}, language={self.language}, location={self.location}, "
f"result={self.result}, created_at={self.created}, valid={self.valid}, completed={self.completed})>"
)
class AlertFlowGraph(Base):
__tablename__ = "alert_flow_graph"
id: Mapped[int] = mapped_column(primary_key=True)
alert_canonical_id = Column(Integer, ForeignKey("alert_results.canonical_id", ondelete="CASCADE"))
flow_data: Mapped[str] = mapped_column(Text)
repo: Mapped[str]
prev: Mapped[str | None]
next: Mapped[str | None]
started: Mapped[bool] = mapped_column(nullable=False, default=False)
def __repr__(self):
return (
f"<AlertFlowGraph(alert_canonical_id={self.alert_canonical_id}, "
f"flow_data={self.flow_data}, repo={self.repo}, prev={self.prev}, next={self.next}, started={self.started})>"
)