3
3
from uuid import UUID , uuid4
4
4
5
5
from pydantic import validator
6
- from sqlmodel import Field , Relationship , SQLModel , Field , Column , func , DateTime
6
+ from sqlmodel import Column , DateTime , Field , Relationship , SQLModel , func
7
7
8
8
if TYPE_CHECKING :
9
9
from langflow .services .database .models .user import User
10
10
11
11
12
+ def utcnow ():
13
+ return datetime .now ()
14
+
15
+
12
16
class ApiKeyBase (SQLModel ):
13
17
name : Optional [str ] = Field (index = True , nullable = True , default = None )
14
18
created_at : datetime = Field (sa_column = Column (DateTime (timezone = True ), server_default = func .now ()))
15
- last_used_at : Optional [datetime ] = Field (sa_column = Column (DateTime (timezone = True )))
19
+ last_used_at : Optional [datetime ] = Field (None , sa_column = Column (DateTime (timezone = True )))
16
20
total_uses : int = Field (default = 0 )
17
21
is_active : bool = Field (default = True )
18
22
@@ -32,6 +36,9 @@ class ApiKey(ApiKeyBase, table=True):
32
36
class ApiKeyCreate (ApiKeyBase ):
33
37
api_key : Optional [str ] = None
34
38
user_id : Optional [UUID ] = None
39
+ created_at : Optional [datetime ] = Field (
40
+ default_factory = utcnow , description = "The date and time the API key was created"
41
+ )
35
42
36
43
37
44
class UnmaskedApiKeyRead (ApiKeyBase ):
0 commit comments