"""change_agent_card_data_to_jsonb

Revision ID: 495a40fce45f
Revises: e163cd45ddf7
Create Date: 2025-04-14 20:55:56.382563

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
# --- ADDED: Import postgresql dialect ---
from sqlalchemy.dialects import postgresql
# --- END ADDED ---


# revision identifiers, used by Alembic.
revision: str = '495a40fce45f'
# --- MODIFIED: Point to the migration *before* the original index attempt ---
down_revision: Union[str, None] = 'e163cd45ddf7'
# --- END MODIFIED ---
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.alter_column(
        'agent_cards',
        'card_data',
        existing_type=sa.JSON(),
        type_=postgresql.JSONB(astext_type=sa.Text()), # Specify JSONB type
        postgresql_using='card_data::jsonb', # Tell PG how to cast
        existing_nullable=False
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column(
        'agent_cards',
        'card_data',
        existing_type=postgresql.JSONB(astext_type=sa.Text()),
        type_=sa.JSON(), # Change back to standard JSON
        # Cast back might not be strictly needed but good practice
        postgresql_using='card_data::json',
        existing_nullable=False
    )
    # ### end Alembic commands ###
