105
105
connect_args = connect_args ,
106
106
)
107
107
108
+ # ---------------------------------------------------------------------------
109
+ # 6. Function to return UTC timestamp
110
+ # ---------------------------------------------------------------------------
111
+ def utc_now ():
112
+ return datetime .now (timezone .utc )
113
+
108
114
# Session factory
109
115
SessionLocal = sessionmaker (autocommit = False , autoflush = False , bind = engine )
110
116
@@ -181,7 +187,7 @@ class ToolMetric(Base):
181
187
182
188
id : Mapped [int ] = mapped_column (primary_key = True )
183
189
tool_id : Mapped [str ] = mapped_column (String , ForeignKey ("tools.id" ), nullable = False )
184
- timestamp : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = lambda : datetime . now ( timezone . utc ) )
190
+ timestamp : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now )
185
191
response_time : Mapped [float ] = mapped_column (Float , nullable = False )
186
192
is_success : Mapped [bool ] = mapped_column (Boolean , nullable = False )
187
193
error_message : Mapped [Optional [str ]] = mapped_column (Text , nullable = True )
@@ -207,7 +213,7 @@ class ResourceMetric(Base):
207
213
208
214
id : Mapped [int ] = mapped_column (primary_key = True )
209
215
resource_id : Mapped [int ] = mapped_column (Integer , ForeignKey ("resources.id" ), nullable = False )
210
- timestamp : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = lambda : datetime . now ( timezone . utc ) )
216
+ timestamp : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now )
211
217
response_time : Mapped [float ] = mapped_column (Float , nullable = False )
212
218
is_success : Mapped [bool ] = mapped_column (Boolean , nullable = False )
213
219
error_message : Mapped [Optional [str ]] = mapped_column (Text , nullable = True )
@@ -233,7 +239,7 @@ class ServerMetric(Base):
233
239
234
240
id : Mapped [int ] = mapped_column (primary_key = True )
235
241
server_id : Mapped [str ] = mapped_column (String , ForeignKey ("servers.id" ), nullable = False )
236
- timestamp : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = lambda : datetime . now ( timezone . utc ) )
242
+ timestamp : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now )
237
243
response_time : Mapped [float ] = mapped_column (Float , nullable = False )
238
244
is_success : Mapped [bool ] = mapped_column (Boolean , nullable = False )
239
245
error_message : Mapped [Optional [str ]] = mapped_column (Text , nullable = True )
@@ -259,7 +265,7 @@ class PromptMetric(Base):
259
265
260
266
id : Mapped [int ] = mapped_column (primary_key = True )
261
267
prompt_id : Mapped [int ] = mapped_column (Integer , ForeignKey ("prompts.id" ), nullable = False )
262
- timestamp : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = lambda : datetime . now ( timezone . utc ) )
268
+ timestamp : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now )
263
269
response_time : Mapped [float ] = mapped_column (Float , nullable = False )
264
270
is_success : Mapped [bool ] = mapped_column (Boolean , nullable = False )
265
271
error_message : Mapped [Optional [str ]] = mapped_column (Text , nullable = True )
@@ -312,8 +318,8 @@ class Tool(Base):
312
318
headers : Mapped [Optional [Dict [str , str ]]] = mapped_column (JSON )
313
319
input_schema : Mapped [Dict [str , Any ]] = mapped_column (JSON )
314
320
annotations : Mapped [Optional [Dict [str , Any ]]] = mapped_column (JSON , default = lambda : {})
315
- created_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = lambda : datetime . now ( timezone . utc ) )
316
- updated_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = lambda : datetime . now ( timezone . utc ) , onupdate = lambda : datetime . now ( timezone . utc ) )
321
+ created_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now )
322
+ updated_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now , onupdate = utc_now )
317
323
is_active : Mapped [bool ] = mapped_column (default = True )
318
324
jsonpath_filter : Mapped [str ] = mapped_column (default = "" )
319
325
@@ -557,8 +563,8 @@ class Resource(Base):
557
563
mime_type : Mapped [Optional [str ]]
558
564
size : Mapped [Optional [int ]]
559
565
template : Mapped [Optional [str ]] # URI template for parameterized resources
560
- created_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = lambda : datetime . now ( timezone . utc ) )
561
- updated_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = lambda : datetime . now ( timezone . utc ) , onupdate = lambda : datetime . now ( timezone . utc ) )
566
+ created_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now )
567
+ updated_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now , onupdate = utc_now )
562
568
is_active : Mapped [bool ] = mapped_column (default = True )
563
569
metrics : Mapped [List ["ResourceMetric" ]] = relationship ("ResourceMetric" , back_populates = "resource" , cascade = "all, delete-orphan" )
564
570
@@ -714,7 +720,7 @@ class ResourceSubscription(Base):
714
720
id : Mapped [int ] = mapped_column (primary_key = True )
715
721
resource_id : Mapped [int ] = mapped_column (ForeignKey ("resources.id" ))
716
722
subscriber_id : Mapped [str ] # Client identifier
717
- created_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = lambda : datetime . now ( timezone . utc ) )
723
+ created_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now )
718
724
last_notification : Mapped [Optional [datetime ]] = mapped_column (DateTime )
719
725
720
726
resource : Mapped ["Resource" ] = relationship (back_populates = "subscriptions" )
@@ -745,8 +751,8 @@ class Prompt(Base):
745
751
description : Mapped [Optional [str ]]
746
752
template : Mapped [str ] = mapped_column (Text )
747
753
argument_schema : Mapped [Dict [str , Any ]] = mapped_column (JSON )
748
- created_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = lambda : datetime . now ( timezone . utc ) )
749
- updated_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = lambda : datetime . now ( timezone . utc ) , onupdate = lambda : datetime . now ( timezone . utc ) )
754
+ created_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now )
755
+ updated_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now , onupdate = utc_now )
750
756
is_active : Mapped [bool ] = mapped_column (default = True )
751
757
metrics : Mapped [List ["PromptMetric" ]] = relationship ("PromptMetric" , back_populates = "prompt" , cascade = "all, delete-orphan" )
752
758
@@ -894,8 +900,8 @@ class Server(Base):
894
900
name : Mapped [str ] = mapped_column (unique = True )
895
901
description : Mapped [Optional [str ]]
896
902
icon : Mapped [Optional [str ]]
897
- created_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = lambda : datetime . now ( timezone . utc ) )
898
- updated_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = lambda : datetime . now ( timezone . utc ) , onupdate = lambda : datetime . now ( timezone . utc ) )
903
+ created_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now )
904
+ updated_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now , onupdate = utc_now )
899
905
is_active : Mapped [bool ] = mapped_column (default = True )
900
906
metrics : Mapped [List ["ServerMetric" ]] = relationship ("ServerMetric" , back_populates = "server" , cascade = "all, delete-orphan" )
901
907
@@ -1014,8 +1020,8 @@ class Gateway(Base):
1014
1020
description : Mapped [Optional [str ]]
1015
1021
transport : Mapped [str ] = mapped_column (default = "SSE" )
1016
1022
capabilities : Mapped [Dict [str , Any ]] = mapped_column (JSON )
1017
- created_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = lambda : datetime . now ( timezone . utc ) )
1018
- updated_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = lambda : datetime . now ( timezone . utc ) , onupdate = lambda : datetime . now ( timezone . utc ) )
1023
+ created_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now )
1024
+ updated_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now , onupdate = utc_now )
1019
1025
is_active : Mapped [bool ] = mapped_column (default = True )
1020
1026
last_seen : Mapped [Optional [datetime ]]
1021
1027
@@ -1086,8 +1092,8 @@ class SessionRecord(Base):
1086
1092
__tablename__ = "mcp_sessions"
1087
1093
1088
1094
session_id : Mapped [str ] = mapped_column (primary_key = True )
1089
- created_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = lambda : datetime . now ( timezone . utc ) ) # pylint: disable=not-callable
1090
- last_accessed : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = lambda : datetime . now ( timezone . utc ) , onupdate = lambda : datetime . now ( timezone . utc ) ) # pylint: disable=not-callable
1095
+ created_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now ) # pylint: disable=not-callable
1096
+ last_accessed : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now , onupdate = utc_now ) # pylint: disable=not-callable
1091
1097
data : Mapped [str ] = mapped_column (String , nullable = True )
1092
1098
1093
1099
messages : Mapped [List ["SessionMessageRecord" ]] = relationship ("SessionMessageRecord" , back_populates = "session" , cascade = "all, delete-orphan" )
@@ -1101,8 +1107,8 @@ class SessionMessageRecord(Base):
1101
1107
id : Mapped [int ] = mapped_column (primary_key = True , autoincrement = True )
1102
1108
session_id : Mapped [str ] = mapped_column (ForeignKey ("mcp_sessions.session_id" ))
1103
1109
message : Mapped [str ] = mapped_column (String , nullable = True )
1104
- created_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = lambda : datetime . now ( timezone . utc ) ) # pylint: disable=not-callable
1105
- last_accessed : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = lambda : datetime . now ( timezone . utc ) , onupdate = lambda : datetime . now ( timezone . utc ) ) # pylint: disable=not-callable
1110
+ created_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now ) # pylint: disable=not-callable
1111
+ last_accessed : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now , onupdate = utc_now ) # pylint: disable=not-callable
1106
1112
1107
1113
session : Mapped ["SessionRecord" ] = relationship ("SessionRecord" , back_populates = "messages" )
1108
1114
0 commit comments