update: remove workspace operation table and refactor
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
from common.db.base import Base
|
||||
from common.db.models.events import ConsumerInbox, OutboxEvents
|
||||
from common.db.models.identity import Permissions, RolePermissions, Roles, Users
|
||||
from common.db.models.runtime import WorkspaceOperations
|
||||
from common.db.models.schedules import (
|
||||
ScheduleEdges,
|
||||
ScheduleNodeRuns,
|
||||
@@ -32,6 +31,5 @@ __all__ = [
|
||||
"Users",
|
||||
"Versions",
|
||||
"WorkspaceMembers",
|
||||
"WorkspaceOperations",
|
||||
"Workspaces",
|
||||
]
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
import datetime
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import Index, String, Text, text
|
||||
from sqlalchemy.dialects.mysql import CHAR, DATETIME, INTEGER, TINYINT
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from common.db.base import Base
|
||||
|
||||
|
||||
class WorkspaceOperations(Base):
|
||||
__tablename__ = "workspace_operations"
|
||||
__table_args__ = (
|
||||
Index("fk_workspace_operations_user", "requested_by"),
|
||||
Index("idx_workspace_operations_runtime", "runtime_id", "created_at"),
|
||||
Index(
|
||||
"idx_workspace_operations_workspace",
|
||||
"workspace_id",
|
||||
"operation_status",
|
||||
"created_at",
|
||||
),
|
||||
Index("uk_workspace_operations_request", "request_id", unique=True),
|
||||
{"comment": "无状态 Backend 的 Workspace/Jupyter 异步操作记录"},
|
||||
)
|
||||
|
||||
operation_id: Mapped[str] = mapped_column(CHAR(26), primary_key=True)
|
||||
workspace_id: Mapped[str] = mapped_column(CHAR(26), nullable=False)
|
||||
operation_type: Mapped[str] = mapped_column(
|
||||
String(24),
|
||||
nullable=False,
|
||||
comment="open/close/mount/unmount/start/stop/restart/recycle",
|
||||
)
|
||||
operation_status: Mapped[str] = mapped_column(
|
||||
String(24),
|
||||
nullable=False,
|
||||
server_default=text("'pending'"),
|
||||
comment="pending/running/succeeded/failed/cancelled",
|
||||
)
|
||||
state_version: Mapped[int] = mapped_column(
|
||||
INTEGER, nullable=False, server_default=text("0"), comment="乐观锁版本"
|
||||
)
|
||||
requested_by: Mapped[str] = mapped_column(CHAR(26), nullable=False)
|
||||
created_at: Mapped[datetime.datetime] = mapped_column(
|
||||
DATETIME(fsp=3), nullable=False, server_default=text("CURRENT_TIMESTAMP(3)")
|
||||
)
|
||||
runtime_id: Mapped[Optional[str]] = mapped_column(CHAR(26))
|
||||
request_id: Mapped[Optional[str]] = mapped_column(String(128))
|
||||
started_at: Mapped[Optional[datetime.datetime]] = mapped_column(DATETIME(fsp=3))
|
||||
finished_at: Mapped[Optional[datetime.datetime]] = mapped_column(DATETIME(fsp=3))
|
||||
error_code: Mapped[Optional[str]] = mapped_column(String(64))
|
||||
error_message: Mapped[Optional[str]] = mapped_column(Text)
|
||||
is_deleted: Mapped[int] = mapped_column(
|
||||
TINYINT(1), nullable=False, server_default=text("0")
|
||||
)
|
||||
deleted_at: Mapped[Optional[datetime.datetime]] = mapped_column(DATETIME(fsp=3))
|
||||
Reference in New Issue
Block a user