105
105
connect_args = connect_args ,
106
106
)
107
107
108
+
109
+ # ---------------------------------------------------------------------------
110
+ # 6. Function to return UTC timestamp
111
+ # ---------------------------------------------------------------------------
112
+ def utc_now ():
113
+ return datetime .now (timezone .utc )
114
+
115
+
108
116
# Session factory
109
117
SessionLocal = sessionmaker (autocommit = False , autoflush = False , bind = engine )
110
118
@@ -181,7 +189,7 @@ class ToolMetric(Base):
181
189
182
190
id : Mapped [int ] = mapped_column (primary_key = True )
183
191
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 ) )
192
+ timestamp : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now )
185
193
response_time : Mapped [float ] = mapped_column (Float , nullable = False )
186
194
is_success : Mapped [bool ] = mapped_column (Boolean , nullable = False )
187
195
error_message : Mapped [Optional [str ]] = mapped_column (Text , nullable = True )
@@ -207,7 +215,7 @@ class ResourceMetric(Base):
207
215
208
216
id : Mapped [int ] = mapped_column (primary_key = True )
209
217
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 ) )
218
+ timestamp : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now )
211
219
response_time : Mapped [float ] = mapped_column (Float , nullable = False )
212
220
is_success : Mapped [bool ] = mapped_column (Boolean , nullable = False )
213
221
error_message : Mapped [Optional [str ]] = mapped_column (Text , nullable = True )
@@ -233,7 +241,7 @@ class ServerMetric(Base):
233
241
234
242
id : Mapped [int ] = mapped_column (primary_key = True )
235
243
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 ) )
244
+ timestamp : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now )
237
245
response_time : Mapped [float ] = mapped_column (Float , nullable = False )
238
246
is_success : Mapped [bool ] = mapped_column (Boolean , nullable = False )
239
247
error_message : Mapped [Optional [str ]] = mapped_column (Text , nullable = True )
@@ -259,7 +267,7 @@ class PromptMetric(Base):
259
267
260
268
id : Mapped [int ] = mapped_column (primary_key = True )
261
269
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 ) )
270
+ timestamp : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now )
263
271
response_time : Mapped [float ] = mapped_column (Float , nullable = False )
264
272
is_success : Mapped [bool ] = mapped_column (Boolean , nullable = False )
265
273
error_message : Mapped [Optional [str ]] = mapped_column (Text , nullable = True )
@@ -312,8 +320,8 @@ class Tool(Base):
312
320
headers : Mapped [Optional [Dict [str , str ]]] = mapped_column (JSON )
313
321
input_schema : Mapped [Dict [str , Any ]] = mapped_column (JSON )
314
322
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 ) )
323
+ created_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now )
324
+ updated_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now , onupdate = utc_now )
317
325
is_active : Mapped [bool ] = mapped_column (default = True )
318
326
jsonpath_filter : Mapped [str ] = mapped_column (default = "" )
319
327
@@ -557,8 +565,8 @@ class Resource(Base):
557
565
mime_type : Mapped [Optional [str ]]
558
566
size : Mapped [Optional [int ]]
559
567
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 ) )
568
+ created_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now )
569
+ updated_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now , onupdate = utc_now )
562
570
is_active : Mapped [bool ] = mapped_column (default = True )
563
571
metrics : Mapped [List ["ResourceMetric" ]] = relationship ("ResourceMetric" , back_populates = "resource" , cascade = "all, delete-orphan" )
564
572
@@ -714,7 +722,7 @@ class ResourceSubscription(Base):
714
722
id : Mapped [int ] = mapped_column (primary_key = True )
715
723
resource_id : Mapped [int ] = mapped_column (ForeignKey ("resources.id" ))
716
724
subscriber_id : Mapped [str ] # Client identifier
717
- created_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = lambda : datetime . now ( timezone . utc ) )
725
+ created_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now )
718
726
last_notification : Mapped [Optional [datetime ]] = mapped_column (DateTime )
719
727
720
728
resource : Mapped ["Resource" ] = relationship (back_populates = "subscriptions" )
@@ -745,8 +753,8 @@ class Prompt(Base):
745
753
description : Mapped [Optional [str ]]
746
754
template : Mapped [str ] = mapped_column (Text )
747
755
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 ) )
756
+ created_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now )
757
+ updated_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now , onupdate = utc_now )
750
758
is_active : Mapped [bool ] = mapped_column (default = True )
751
759
metrics : Mapped [List ["PromptMetric" ]] = relationship ("PromptMetric" , back_populates = "prompt" , cascade = "all, delete-orphan" )
752
760
@@ -894,8 +902,8 @@ class Server(Base):
894
902
name : Mapped [str ] = mapped_column (unique = True )
895
903
description : Mapped [Optional [str ]]
896
904
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 ) )
905
+ created_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now )
906
+ updated_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now , onupdate = utc_now )
899
907
is_active : Mapped [bool ] = mapped_column (default = True )
900
908
metrics : Mapped [List ["ServerMetric" ]] = relationship ("ServerMetric" , back_populates = "server" , cascade = "all, delete-orphan" )
901
909
@@ -1014,8 +1022,8 @@ class Gateway(Base):
1014
1022
description : Mapped [Optional [str ]]
1015
1023
transport : Mapped [str ] = mapped_column (default = "SSE" )
1016
1024
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 ) )
1025
+ created_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now )
1026
+ updated_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now , onupdate = utc_now )
1019
1027
is_active : Mapped [bool ] = mapped_column (default = True )
1020
1028
last_seen : Mapped [Optional [datetime ]]
1021
1029
@@ -1086,8 +1094,8 @@ class SessionRecord(Base):
1086
1094
__tablename__ = "mcp_sessions"
1087
1095
1088
1096
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
1097
+ created_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now ) # pylint: disable=not-callable
1098
+ last_accessed : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now , onupdate = utc_now ) # pylint: disable=not-callable
1091
1099
data : Mapped [str ] = mapped_column (String , nullable = True )
1092
1100
1093
1101
messages : Mapped [List ["SessionMessageRecord" ]] = relationship ("SessionMessageRecord" , back_populates = "session" , cascade = "all, delete-orphan" )
@@ -1101,8 +1109,8 @@ class SessionMessageRecord(Base):
1101
1109
id : Mapped [int ] = mapped_column (primary_key = True , autoincrement = True )
1102
1110
session_id : Mapped [str ] = mapped_column (ForeignKey ("mcp_sessions.session_id" ))
1103
1111
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
1112
+ created_at : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now ) # pylint: disable=not-callable
1113
+ last_accessed : Mapped [datetime ] = mapped_column (DateTime (timezone = True ), default = utc_now , onupdate = utc_now ) # pylint: disable=not-callable
1106
1114
1107
1115
session : Mapped ["SessionRecord" ] = relationship ("SessionRecord" , back_populates = "messages" )
1108
1116
0 commit comments