fix(db): alert_operation_log.event_type String→PgEnum (create_type=False)
Some checks failed
CD Pipeline / build-and-deploy (push) Has been cancelled
Some checks failed
CD Pipeline / build-and-deploy (push) Has been cancelled
修正 DatatypeMismatchError: DB 欄位為 native enum alert_event_type, SQLAlchemy model 誤用 String(50),導致 alert_operation_log 寫入失敗。 使用 PgEnum(create_type=False) 讓 SQLAlchemy 映射已存在的 DB enum, 不重建型別。18 個 event_type 值與 M-003 migration 一致。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -25,6 +25,7 @@ from sqlalchemy import (
|
||||
from sqlalchemy import (
|
||||
Enum as SQLEnum,
|
||||
)
|
||||
from sqlalchemy.dialects.postgresql import ENUM as PgEnum
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from src.db.base import Base
|
||||
@@ -445,7 +446,18 @@ class AlertOperationLog(Base):
|
||||
auto_repair_id: Mapped[str | None] = mapped_column(String(36), nullable=True)
|
||||
|
||||
# 事件核心
|
||||
event_type: Mapped[str] = mapped_column(String(50), nullable=False, index=True)
|
||||
# 2026-04-08 Claude Sonnet 4.6: Sprint 5.1 — 修正 enum 型別不符 (String→PgEnum, create_type=False)
|
||||
event_type: Mapped[str] = mapped_column(
|
||||
PgEnum(
|
||||
"ALERT_RECEIVED", "TELEGRAM_SENT", "USER_ACTION", "AUTO_REPAIR_TRIGGERED",
|
||||
"EXECUTION_STARTED", "EXECUTION_COMPLETED", "TELEGRAM_RESULT_SENT",
|
||||
"RESOLVED", "SILENCED", "ESCALATED", "GUARDRAIL_BLOCKED",
|
||||
"PRE_FLIGHT_PASSED", "PRE_FLIGHT_FAILED", "BACKUP_TRIGGERED",
|
||||
"BACKUP_COMPLETED", "BACKUP_FAILED", "APPROVAL_ESCALATED", "CHANGE_APPLIED",
|
||||
name="alert_event_type", create_type=False,
|
||||
),
|
||||
nullable=False, index=True,
|
||||
)
|
||||
actor: Mapped[str | None] = mapped_column(String(100), nullable=True, index=True)
|
||||
action_detail: Mapped[str | None] = mapped_column(String(200), nullable=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user