fix(analytics): 命中表索引幂等守卫独立+created_at 去掉 onupdate 语义

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
浅念
2026-09-04 15:30:14 +08:00
parent 565006239b
commit 8b29326b2e
2 changed files with 14 additions and 5 deletions
@@ -75,9 +75,10 @@ def upgrade() -> None:
sa.Column("created_at", sa.DateTime(), nullable=False, server_default=sa.func.now()),
sa.UniqueConstraint("word_id", "msg_id", name="uq_sensitive_hit_word_msg"),
)
op.create_index(
"ix_sensitive_hit_disp_ts", "sensitive_hit", ["disposition", "ts"]
)
# 索引守卫独立于建表:MySQL DDL 逐句自动提交,进程死在 create_table 与
# create_index 之间的话,重跑会因表已存在而永远跳过索引。
if not _has_index(bind, "sensitive_hit", "ix_sensitive_hit_disp_ts"):
op.create_index("ix_sensitive_hit_disp_ts", "sensitive_hit", ["disposition", "ts"])
if not insp.has_table("sensitive_scan_state"):
op.create_table(
"sensitive_scan_state",