feat(backend): harden task boundaries

This commit is contained in:
2026-05-05 00:55:29 +08:00
parent 817540f8a0
commit e243dccfd7
15 changed files with 694 additions and 147 deletions
+8 -1
View File
@@ -1,7 +1,7 @@
from datetime import datetime
from typing import TYPE_CHECKING
from sqlalchemy import Boolean, DateTime, ForeignKey, Index, String, Text
from sqlalchemy import Boolean, DateTime, ForeignKey, Index, String, Text, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column, relationship
from sqlalchemy.sql import func
@@ -23,6 +23,12 @@ class CheckInTask(Base):
index=True,
comment="用户 ID",
)
thread_id: Mapped[str | None] = mapped_column(
String(100),
index=True,
nullable=True,
comment="接龙项目 ID",
)
payload_config: Mapped[str] = mapped_column(
Text,
default="{}",
@@ -57,6 +63,7 @@ class CheckInTask(Base):
# 添加索引:加速查询
__table_args__ = (
Index("ix_task_user_active", "user_id", "is_active"),
UniqueConstraint("user_id", "thread_id", name="uq_task_user_thread_id"),
Index("ix_task_cron", "cron_expression"), # 加速查询启用了定时打卡的任务
)