47
47
# but we also want to allow it to be nullable. MySQL doesn't allow nullable fields in primary keys, so:
48
48
NULL_FOR_DELETED_AT = datetime (1000 , 1 , 1 , 0 , 0 )
49
49
50
+
50
51
class AlertToIncident (SQLModel , table = True ):
51
52
tenant_id : str = Field (foreign_key = "tenant.id" )
52
53
timestamp : datetime = Field (default_factory = datetime .utcnow )
@@ -61,16 +62,17 @@ class AlertToIncident(SQLModel, table=True):
61
62
)
62
63
alert : "Alert" = Relationship (back_populates = "alert_to_incident_link" )
63
64
incident : "Incident" = Relationship (back_populates = "alert_to_incident_link" )
64
-
65
+
65
66
is_created_by_ai : bool = Field (default = False )
66
67
67
68
deleted_at : datetime = Field (
68
69
default_factory = None ,
69
- nullable = True ,
70
+ nullable = True ,
70
71
primary_key = True ,
71
72
default = NULL_FOR_DELETED_AT ,
72
73
)
73
74
75
+
74
76
class Incident (SQLModel , table = True ):
75
77
id : UUID = Field (default_factory = uuid4 , primary_key = True )
76
78
tenant_id : str = Field (foreign_key = "tenant.id" )
@@ -96,7 +98,8 @@ class Incident(SQLModel, table=True):
96
98
97
99
# map of attributes to values
98
100
alerts : List ["Alert" ] = Relationship (
99
- back_populates = "incidents" , link_model = AlertToIncident ,
101
+ back_populates = "incidents" ,
102
+ link_model = AlertToIncident ,
100
103
# primaryjoin is used to filter out deleted links for various DB dialects
101
104
sa_relationship_kwargs = {
102
105
"primaryjoin" : f"""and_(AlertToIncident.incident_id == Incident.id,
@@ -106,14 +109,11 @@ class Incident(SQLModel, table=True):
106
109
))""" ,
107
110
"uselist" : True ,
108
111
"overlaps" : "alert,incident" ,
109
- }
110
-
112
+ },
111
113
)
112
114
alert_to_incident_link : List [AlertToIncident ] = Relationship (
113
115
back_populates = "incident" ,
114
- sa_relationship_kwargs = {
115
- "overlaps" : "alerts,incidents"
116
- }
116
+ sa_relationship_kwargs = {"overlaps" : "alerts,incidents" },
117
117
)
118
118
119
119
is_predicted : bool = Field (default = False )
@@ -222,7 +222,7 @@ class Alert(SQLModel, table=True):
222
222
)
223
223
224
224
incidents : List ["Incident" ] = Relationship (
225
- back_populates = "alerts" ,
225
+ back_populates = "alerts" ,
226
226
link_model = AlertToIncident ,
227
227
sa_relationship_kwargs = {
228
228
# primaryjoin is used to filter out deleted links for various DB dialects
@@ -233,13 +233,19 @@ class Alert(SQLModel, table=True):
233
233
))""" ,
234
234
"uselist" : True ,
235
235
"overlaps" : "alert,incident" ,
236
- }
236
+ },
237
237
)
238
238
alert_to_incident_link : List [AlertToIncident ] = Relationship (
239
- back_populates = "alert" ,
240
- sa_relationship_kwargs = {
241
- "overlaps" : "alerts,incidents"
242
- }
239
+ back_populates = "alert" , sa_relationship_kwargs = {"overlaps" : "alerts,incidents" }
240
+ )
241
+
242
+ __table_args__ = (
243
+ Index (
244
+ "ix_alert_tenant_fingerprint_timestamp" ,
245
+ "tenant_id" ,
246
+ "fingerprint" ,
247
+ "timestamp" ,
248
+ ),
243
249
)
244
250
245
251
class Config :
0 commit comments