"""Add interactivity to Action

Revision ID: 9039a443701d
Revises: 4aade4315ef9
Create Date: 2025-03-14 11:18:55.774748

"""

from collections.abc import Sequence

import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "9039a443701d"
down_revision: str | None = "4aade4315ef9"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    # First add the column as nullable
    op.add_column(
        "action",
        sa.Column("is_interactive", sa.Boolean(), nullable=True),
    )
    # Set default value for existing rows
    op.execute("UPDATE action SET is_interactive = false")
    # Make the column non-nullable
    op.alter_column("action", "is_interactive", nullable=False)

    op.add_column(
        "action",
        sa.Column(
            "interaction", postgresql.JSONB(astext_type=sa.Text()), nullable=True
        ),
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column("action", "interaction")
    op.drop_column("action", "is_interactive")
    # ### end Alembic commands ###
