diff --git a/apps/api/src/db/models.py b/apps/api/src/db/models.py index cee42a04b..b2dd1987f 100644 --- a/apps/api/src/db/models.py +++ b/apps/api/src/db/models.py @@ -10,7 +10,7 @@ Schema 設計原則: - 索引優化查詢 """ -from datetime import UTC, datetime +from datetime import datetime from typing import Any from uuid import uuid4 @@ -36,9 +36,14 @@ from src.models.knowledge import EntrySource, EntryStatus, EntryType # Helper Functions # ============================================================================= -def utc_now() -> datetime: - """Get current UTC datetime""" - return datetime.now(UTC) +def taipei_now() -> datetime: + """取得台北時區當前時間 (UTC+8) + + 🔴 HARD RULE: 全系統使用台北時區,禁止 UTC + 2026-04-02 Claude Code: C1 時區統一遷移 (首席架構師審查) + """ + from src.utils.timezone import now_taipei + return now_taipei() def generate_uuid() -> str: @@ -114,7 +119,7 @@ class ApprovalRecord(Base): # 最後觸發時間 - 同指紋告警最近一次出現的時間 last_seen_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), - default=utc_now, + default=taipei_now, nullable=False, comment="Last time this alert pattern was seen", ) @@ -122,12 +127,12 @@ class ApprovalRecord(Base): # Timestamps created_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), - default=utc_now, + default=taipei_now, ) updated_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), - default=utc_now, - onupdate=utc_now, + default=taipei_now, + onupdate=taipei_now, ) expires_at: Mapped[datetime | None] = mapped_column( DateTime(timezone=True), @@ -200,7 +205,7 @@ class TimelineEvent(Base): # Timestamp created_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), - default=utc_now, + default=taipei_now, ) # Indexes @@ -324,7 +329,7 @@ class AuditLog(Base): # Timestamps created_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), - default=utc_now, + default=taipei_now, ) # Indexes @@ -417,13 +422,13 @@ class IncidentRecord(Base): # === 時間軸 === created_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), - default=utc_now, + default=taipei_now, nullable=False, ) updated_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), - default=utc_now, - onupdate=utc_now, + default=taipei_now, + onupdate=taipei_now, nullable=False, ) resolved_at: Mapped[datetime | None] = mapped_column( @@ -537,12 +542,12 @@ class KnowledgeEntryRecord(Base): created_by: Mapped[str | None] = mapped_column(String(100), nullable=True) created_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), - default=utc_now, + default=taipei_now, ) updated_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), - default=utc_now, - onupdate=utc_now, + default=taipei_now, + onupdate=taipei_now, ) # Indexes