Files
aiagent/backend/alembic/versions/009_add_notifications_and_schedule_fields.py
renjianbo 7ee80c74b2 feat: 集成飞书通知和机器人对话系统
- 新增通知系统 (notifications 表、服务、API)
- 新增飞书定时任务结果推送 (webhook + 应用消息)
- 新增飞书应用消息发送服务 (feishu_app_service)
- 新增飞书 WebSocket 长连接事件监听 (苹果应用)
- 新增飞书账号绑定/解绑 API
- 新增橙子飞书机器人 (独立 WS 连接,固定路由到橙子助手 Agent)
- 执行记录添加 schedule_id,用户添加飞书绑定字段

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-02 16:17:49 +08:00

85 lines
2.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""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")