"""messages.kind 列(消息来源标记,避免 push 记录被 extract_last_assistant_text 误取).

Revision ID: 0018
Revises: 0017
Create Date: 2026-06-26

给 messages 加 kind 列(nullable Text,默认 NULL)。NULL=agent run 产生的消息;
"push"=push 记录(_record_push_to_chat 写)。extract_last_assistant_text 加
WHERE kind IS NULL 跳过 push 记录,避免 wecom 入站取回复时误取 push 摘要。
独立列不进 payload,不影响 agent 上下文 / LLM API。纯加列,不动现有数据。
"""
from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op


revision: str = "0018"
down_revision: Union[str, None] = "0017"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.add_column("messages", sa.Column("kind", sa.Text(), nullable=True))


def downgrade() -> None:
    op.drop_column("messages", "kind")
