39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
"""Models for bot API keys and project reports."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
from typing import Any
|
|
from uuid import UUID, uuid4
|
|
|
|
from sqlalchemy import JSON, Column
|
|
from sqlmodel import Field
|
|
|
|
from app.core.time import utcnow
|
|
from app.models.base import QueryModel
|
|
|
|
|
|
class BotApiKey(QueryModel, table=True):
|
|
__tablename__ = "bot_api_keys" # pyright: ignore[reportAssignmentType]
|
|
|
|
id: UUID = Field(default_factory=uuid4, primary_key=True)
|
|
organization_id: UUID = Field(foreign_key="organizations.id", index=True)
|
|
name: str = Field(index=True)
|
|
key_hash: str = Field(index=True)
|
|
key_last_four: str
|
|
created_at: datetime = Field(default_factory=utcnow)
|
|
last_used_at: datetime | None = Field(default=None)
|
|
|
|
|
|
class BotReport(QueryModel, table=True):
|
|
__tablename__ = "bot_reports" # pyright: ignore[reportAssignmentType]
|
|
|
|
id: UUID = Field(default_factory=uuid4, primary_key=True)
|
|
organization_id: UUID = Field(foreign_key="organizations.id", index=True)
|
|
key_id: UUID = Field(foreign_key="bot_api_keys.id", index=True)
|
|
project: str | None = Field(default=None)
|
|
task: str | None = Field(default=None)
|
|
status: str | None = Field(default=None)
|
|
detail: dict[str, Any] | None = Field(default=None, sa_column=Column(JSON))
|
|
reported_at: datetime = Field(default_factory=utcnow, index=True)
|