"""Add Feishu event receipts. Revision ID: 202607060003 Revises: 202607060002 Create Date: 2026-07-06 """ from alembic import op import sqlalchemy as sa from sqlalchemy import inspect revision = "202607060003" down_revision = "202607060002" branch_labels = None depends_on = None FEISHU_EVENT_RECEIPTS_TABLE = "feishu_event_receipts" def _table_exists() -> bool: inspector = inspect(op.get_bind()) return FEISHU_EVENT_RECEIPTS_TABLE in inspector.get_table_names() def upgrade() -> None: if _table_exists(): return op.create_table( FEISHU_EVENT_RECEIPTS_TABLE, sa.Column("id", sa.Integer(), autoincrement=True, nullable=False), sa.Column("event_key", sa.String(length=256), nullable=False), sa.Column("source", sa.String(length=64), nullable=False), sa.Column("event_id", sa.String(length=128), nullable=True), sa.Column("message_id", sa.String(length=128), nullable=True), sa.Column("received_at", sa.DateTime(), nullable=False), sa.PrimaryKeyConstraint("id"), ) op.create_index( op.f("ix_feishu_event_receipts_event_id"), FEISHU_EVENT_RECEIPTS_TABLE, ["event_id"], unique=False, ) op.create_index( op.f("ix_feishu_event_receipts_event_key"), FEISHU_EVENT_RECEIPTS_TABLE, ["event_key"], unique=True, ) op.create_index( op.f("ix_feishu_event_receipts_message_id"), FEISHU_EVENT_RECEIPTS_TABLE, ["message_id"], unique=False, ) op.create_index( op.f("ix_feishu_event_receipts_received_at"), FEISHU_EVENT_RECEIPTS_TABLE, ["received_at"], unique=False, ) op.create_index( op.f("ix_feishu_event_receipts_source"), FEISHU_EVENT_RECEIPTS_TABLE, ["source"], unique=False, ) def downgrade() -> None: if not _table_exists(): return op.drop_index(op.f("ix_feishu_event_receipts_source"), table_name=FEISHU_EVENT_RECEIPTS_TABLE) op.drop_index( op.f("ix_feishu_event_receipts_received_at"), table_name=FEISHU_EVENT_RECEIPTS_TABLE, ) op.drop_index( op.f("ix_feishu_event_receipts_message_id"), table_name=FEISHU_EVENT_RECEIPTS_TABLE, ) op.drop_index( op.f("ix_feishu_event_receipts_event_key"), table_name=FEISHU_EVENT_RECEIPTS_TABLE, ) op.drop_index( op.f("ix_feishu_event_receipts_event_id"), table_name=FEISHU_EVENT_RECEIPTS_TABLE, ) op.drop_table(FEISHU_EVENT_RECEIPTS_TABLE)