Files
ai-video-fullstack/backend/migrations/versions/20261023_0026_add_background_tasks.py
T

50 lines
2.3 KiB
Python

"""Add durable projections for native Pipecat background Jobs."""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
revision = "20261023_0026"
down_revision = "20260907_0025"
branch_labels = None
depends_on = None
def upgrade():
op.drop_constraint("ck_tools_external_type", "tools", type_="check")
op.create_check_constraint("ck_tools_external_type", "tools", "type IN ('http', 'mcp', 'client', 'task')")
op.create_table(
"background_tasks",
sa.Column("id", sa.String(40), primary_key=True),
sa.Column("assistant_id", sa.String(40), nullable=False),
sa.Column("conversation_id", sa.String(80), nullable=False),
sa.Column("tool_id", sa.String(40), nullable=False),
sa.Column("instruction", sa.Text(), nullable=False),
sa.Column("origin_key", sa.String(256), nullable=False, unique=True),
*[sa.Column(name, postgresql.JSONB(), nullable=False) for name in ("connection", "secrets", "remote_handle", "input_request")],
sa.Column("status", sa.String(32), nullable=False),
sa.Column("summary", sa.Text(), nullable=False),
sa.Column("result", sa.Text(), nullable=False),
sa.Column("job_id", sa.String(80), nullable=False),
sa.Column("sequence", sa.Integer(), nullable=False),
sa.Column("created_at", sa.String(40), nullable=False),
sa.Column("updated_at", sa.String(40), nullable=False),
)
for name in ("assistant_id", "conversation_id", "status"):
op.create_index(f"ix_background_tasks_{name}", "background_tasks", [name])
op.create_table(
"background_task_events",
sa.Column("id", sa.String(40), primary_key=True),
sa.Column("task_id", sa.String(40), sa.ForeignKey("background_tasks.id", ondelete="CASCADE"), nullable=False),
sa.Column("sequence", sa.Integer(), nullable=False),
sa.Column("data", postgresql.JSONB(), nullable=False),
sa.UniqueConstraint("task_id", "sequence"),
)
op.create_index("ix_background_task_events_task_id", "background_task_events", ["task_id"])
def downgrade():
op.drop_constraint("ck_tools_external_type", "tools", type_="check")
op.create_check_constraint("ck_tools_external_type", "tools", "type IN ('http', 'mcp', 'client')")
op.drop_table("background_task_events")
op.drop_table("background_tasks")