"""launch_confirm_sample table (启动确认窗 agent 兜底样本: LLM 放行的弹窗样本沉淀) Revision ID: launch_confirm_sample_table Revises: cps_wx_user Create Date: 2026-06-20 00:00:00.000000 """ from typing import Sequence, Union from alembic import op import sqlalchemy as sa # revision identifiers, used by Alembic. revision: str = "launch_confirm_sample_table" down_revision: Union[str, Sequence[str], None] = "cps_wx_user" branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None def upgrade() -> None: op.create_table( "launch_confirm_sample", sa.Column("id", sa.Integer(), autoincrement=True, nullable=False), sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("(CURRENT_TIMESTAMP)"), nullable=False), sa.Column("trace_id", sa.String(length=64), nullable=True), sa.Column("device_id", sa.String(length=64), nullable=True), sa.Column("host_package", sa.String(length=128), nullable=True), sa.Column("target_app", sa.String(length=128), nullable=True), sa.Column("system_locale", sa.String(length=32), nullable=True), sa.Column("exec_success", sa.Boolean(), nullable=False), sa.Column("dialog_title", sa.String(length=256), nullable=True), # PG 上为 JSONB,其它(SQLite)为 JSON——与模型层 with_variant 对齐 sa.Column("payload", sa.JSON().with_variant(sa.dialects.postgresql.JSONB(), "postgresql"), nullable=True), sa.PrimaryKeyConstraint("id"), ) with op.batch_alter_table("launch_confirm_sample", schema=None) as batch_op: batch_op.create_index(batch_op.f("ix_launch_confirm_sample_created_at"), ["created_at"], unique=False) batch_op.create_index(batch_op.f("ix_launch_confirm_sample_trace_id"), ["trace_id"], unique=False) batch_op.create_index(batch_op.f("ix_launch_confirm_sample_device_id"), ["device_id"], unique=False) batch_op.create_index(batch_op.f("ix_launch_confirm_sample_host_package"), ["host_package"], unique=False) batch_op.create_index(batch_op.f("ix_launch_confirm_sample_system_locale"), ["system_locale"], unique=False) def downgrade() -> None: with op.batch_alter_table("launch_confirm_sample", schema=None) as batch_op: batch_op.drop_index(batch_op.f("ix_launch_confirm_sample_system_locale")) batch_op.drop_index(batch_op.f("ix_launch_confirm_sample_host_package")) batch_op.drop_index(batch_op.f("ix_launch_confirm_sample_device_id")) batch_op.drop_index(batch_op.f("ix_launch_confirm_sample_trace_id")) batch_op.drop_index(batch_op.f("ix_launch_confirm_sample_created_at")) op.drop_table("launch_confirm_sample")