more typed orm (#28507)

This commit is contained in:
Asuka Minato
2025-11-21 22:45:51 +09:00
committed by GitHub
parent 63b8bbbab3
commit a6c6bcf95c
20 changed files with 196 additions and 134 deletions

View File

@@ -31,7 +31,7 @@ from .provider_ids import GenericProviderID
from .types import LongText, StringUUID
if TYPE_CHECKING:
from models.workflow import Workflow
from .workflow import Workflow
class DifySetup(TypeBase):
@@ -1747,36 +1747,40 @@ class UploadFile(Base):
self.source_url = source_url
class ApiRequest(Base):
class ApiRequest(TypeBase):
__tablename__ = "api_requests"
__table_args__ = (
sa.PrimaryKeyConstraint("id", name="api_request_pkey"),
sa.Index("api_request_token_idx", "tenant_id", "api_token_id"),
)
id = mapped_column(StringUUID, default=lambda: str(uuid4()))
tenant_id = mapped_column(StringUUID, nullable=False)
api_token_id = mapped_column(StringUUID, nullable=False)
id: Mapped[str] = mapped_column(StringUUID, default=lambda: str(uuid4()), init=False)
tenant_id: Mapped[str] = mapped_column(StringUUID, nullable=False)
api_token_id: Mapped[str] = mapped_column(StringUUID, nullable=False)
path: Mapped[str] = mapped_column(String(255), nullable=False)
request = mapped_column(LongText, nullable=True)
response = mapped_column(LongText, nullable=True)
request: Mapped[str | None] = mapped_column(LongText, nullable=True)
response: Mapped[str | None] = mapped_column(LongText, nullable=True)
ip: Mapped[str] = mapped_column(String(255), nullable=False)
created_at = mapped_column(sa.DateTime, nullable=False, server_default=func.current_timestamp())
created_at: Mapped[datetime] = mapped_column(
sa.DateTime, nullable=False, server_default=func.current_timestamp(), init=False
)
class MessageChain(Base):
class MessageChain(TypeBase):
__tablename__ = "message_chains"
__table_args__ = (
sa.PrimaryKeyConstraint("id", name="message_chain_pkey"),
sa.Index("message_chain_message_id_idx", "message_id"),
)
id = mapped_column(StringUUID, default=lambda: str(uuid4()))
message_id = mapped_column(StringUUID, nullable=False)
id: Mapped[str] = mapped_column(StringUUID, default=lambda: str(uuid4()), init=False)
message_id: Mapped[str] = mapped_column(StringUUID, nullable=False)
type: Mapped[str] = mapped_column(String(255), nullable=False)
input = mapped_column(LongText, nullable=True)
output = mapped_column(LongText, nullable=True)
created_at = mapped_column(sa.DateTime, nullable=False, server_default=sa.func.current_timestamp())
input: Mapped[str | None] = mapped_column(LongText, nullable=True)
output: Mapped[str | None] = mapped_column(LongText, nullable=True)
created_at: Mapped[datetime] = mapped_column(
sa.DateTime, nullable=False, server_default=sa.func.current_timestamp(), init=False
)
class MessageAgentThought(Base):
@@ -1956,22 +1960,28 @@ class TagBinding(TypeBase):
)
class TraceAppConfig(Base):
class TraceAppConfig(TypeBase):
__tablename__ = "trace_app_config"
__table_args__ = (
sa.PrimaryKeyConstraint("id", name="tracing_app_config_pkey"),
sa.Index("trace_app_config_app_id_idx", "app_id"),
)
id = mapped_column(StringUUID, default=lambda: str(uuid4()))
app_id = mapped_column(StringUUID, nullable=False)
tracing_provider = mapped_column(String(255), nullable=True)
tracing_config = mapped_column(sa.JSON, nullable=True)
created_at = mapped_column(sa.DateTime, nullable=False, server_default=func.current_timestamp())
updated_at = mapped_column(
sa.DateTime, nullable=False, server_default=func.current_timestamp(), onupdate=func.current_timestamp()
id: Mapped[str] = mapped_column(StringUUID, default=lambda: str(uuid4()), init=False)
app_id: Mapped[str] = mapped_column(StringUUID, nullable=False)
tracing_provider: Mapped[str | None] = mapped_column(String(255), nullable=True)
tracing_config: Mapped[dict | None] = mapped_column(sa.JSON, nullable=True)
created_at: Mapped[datetime] = mapped_column(
sa.DateTime, nullable=False, server_default=func.current_timestamp(), init=False
)
is_active: Mapped[bool] = mapped_column(sa.Boolean, nullable=False, server_default=sa.text("true"))
updated_at: Mapped[datetime] = mapped_column(
sa.DateTime,
nullable=False,
server_default=func.current_timestamp(),
onupdate=func.current_timestamp(),
init=False,
)
is_active: Mapped[bool] = mapped_column(sa.Boolean, nullable=False, server_default=sa.text("true"), default=True)
@property
def tracing_config_dict(self) -> dict[str, Any]: