85 lines
2.5 KiB
Python
85 lines
2.5 KiB
Python
|
|
"""add notifications table, schedule_id to executions, webhook_url to agent_schedules, feishu_open_id to users
|
|||
|
|
|
|||
|
|
Revision ID: 009_add_notifications_and_schedule_fields
|
|||
|
|
Revises: 008_add_agent_budget_config
|
|||
|
|
Create Date: 2026-05-02
|
|||
|
|
"""
|
|||
|
|
from alembic import op
|
|||
|
|
import sqlalchemy as sa
|
|||
|
|
from sqlalchemy.dialects.mysql import CHAR
|
|||
|
|
|
|||
|
|
|
|||
|
|
revision = "009_notif_sched_feishu"
|
|||
|
|
down_revision = "008_add_agent_budget_config"
|
|||
|
|
branch_labels = None
|
|||
|
|
depends_on = None
|
|||
|
|
|
|||
|
|
|
|||
|
|
def upgrade() -> None:
|
|||
|
|
# 1. 新增 notifications 表
|
|||
|
|
op.create_table(
|
|||
|
|
"notifications",
|
|||
|
|
sa.Column("id", CHAR(36), primary_key=True),
|
|||
|
|
sa.Column("user_id", CHAR(36), sa.ForeignKey("users.id"), nullable=False, index=True),
|
|||
|
|
sa.Column("title", sa.String(200), nullable=False),
|
|||
|
|
sa.Column("content", sa.Text(), nullable=True),
|
|||
|
|
sa.Column("category", sa.String(32), default="system"),
|
|||
|
|
sa.Column("ref_type", sa.String(32), nullable=True),
|
|||
|
|
sa.Column("ref_id", sa.String(36), nullable=True),
|
|||
|
|
sa.Column("is_read", sa.Boolean(), default=False),
|
|||
|
|
sa.Column("created_at", sa.DateTime(), default=sa.func.now()),
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
# 2. executions 表添加 schedule_id 字段
|
|||
|
|
op.add_column(
|
|||
|
|
"executions",
|
|||
|
|
sa.Column(
|
|||
|
|
"schedule_id",
|
|||
|
|
CHAR(36),
|
|||
|
|
sa.ForeignKey("agent_schedules.id"),
|
|||
|
|
nullable=True,
|
|||
|
|
comment="定时任务ID",
|
|||
|
|
),
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
# 3. agent_schedules 表添加 webhook_url 字段
|
|||
|
|
op.add_column(
|
|||
|
|
"agent_schedules",
|
|||
|
|
sa.Column(
|
|||
|
|
"webhook_url",
|
|||
|
|
sa.String(512),
|
|||
|
|
nullable=True,
|
|||
|
|
comment="飞书机器人 Webhook URL(可选),执行完成后推送通知",
|
|||
|
|
),
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
# 4. users 表添加 feishu_open_id 字段
|
|||
|
|
op.add_column(
|
|||
|
|
"users",
|
|||
|
|
sa.Column(
|
|||
|
|
"feishu_open_id",
|
|||
|
|
sa.String(64),
|
|||
|
|
nullable=True,
|
|||
|
|
comment="飞书用户 open_id,用于推送通知",
|
|||
|
|
),
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
# 5. users 表添加 feishu_default_agent_id 字段
|
|||
|
|
op.add_column(
|
|||
|
|
"users",
|
|||
|
|
sa.Column(
|
|||
|
|
"feishu_default_agent_id",
|
|||
|
|
CHAR(36),
|
|||
|
|
nullable=True,
|
|||
|
|
comment="飞书对话默认 Agent ID",
|
|||
|
|
),
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
|
|||
|
|
def downgrade() -> None:
|
|||
|
|
op.drop_column("users", "feishu_default_agent_id")
|
|||
|
|
op.drop_column("users", "feishu_open_id")
|
|||
|
|
op.drop_column("agent_schedules", "webhook_url")
|
|||
|
|
op.drop_column("executions", "schedule_id")
|
|||
|
|
op.drop_table("notifications")
|