"""add index Revision ID: fec0fb9a8db7 Revises: fefdd1835b7d Create Date: 2025-08-06 16:21:56.450309 """ from typing import Sequence, Union import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. revision: str = "fec0fb9a8db7" down_revision: Union[str, None] = "fefdd1835b7d" branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None def upgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### op.add_column( "campaigns", sa.Column("last_batch_scheduled_at", sa.DateTime(timezone=True), nullable=True), ) op.add_column( "campaigns", sa.Column("last_activity_at", sa.DateTime(timezone=True), nullable=True), ) op.add_column( "campaigns", sa.Column( "orchestrator_metadata", sa.JSON(), nullable=False, server_default=sa.text("'{}'"), ), ) op.create_index( "idx_campaigns_active_status", "campaigns", ["state"], unique=False, postgresql_where=sa.text("state IN ('syncing', 'running', 'paused')"), ) op.create_index( "idx_queued_runs_campaign_state_optimized", "queued_runs", ["campaign_id", "state"], unique=False, postgresql_where=sa.text("state = 'queued'"), ) op.create_index( "idx_queued_runs_scheduled_optimized", "queued_runs", ["campaign_id", "scheduled_for"], unique=False, postgresql_where=sa.text("scheduled_for IS NOT NULL"), ) # ### end Alembic commands ### def downgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### op.drop_index( "idx_queued_runs_scheduled_optimized", table_name="queued_runs", postgresql_where=sa.text("scheduled_for IS NOT NULL"), ) op.drop_index( "idx_queued_runs_campaign_state_optimized", table_name="queued_runs", postgresql_where=sa.text("state = 'queued'"), ) op.drop_index( "idx_campaigns_active_status", table_name="campaigns", postgresql_where=sa.text("state IN ('syncing', 'running', 'paused')"), ) op.drop_column("campaigns", "orchestrator_metadata") op.drop_column("campaigns", "last_activity_at") op.drop_column("campaigns", "last_batch_scheduled_at") # ### end Alembic commands ###