"""add link from experiments to datasets

Revision ID: 49afefacd064
Revises: 2cb1d34dafa5
Create Date: 2025-11-21 19:58:16.805446

"""

from alembic import op


# revision identifiers, used by Alembic.
revision = "49afefacd064"
down_revision = "2cb1d34dafa5"
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    # Use raw SQL to convert VARCHAR to UUID with explicit USING clause
    op.execute(
        "ALTER TABLE prompt_experiments ALTER COLUMN dataset_id TYPE UUID USING dataset_id::uuid"
    )
    op.create_foreign_key(
        "prompt_experiments_dataset_version_fk",
        "prompt_experiments",
        "dataset_versions",
        ["dataset_id", "dataset_version"],
        ["dataset_id", "version_number"],
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(
        "prompt_experiments_dataset_version_fk",
        "prompt_experiments",
        type_="foreignkey",
    )
    # Use raw SQL to convert UUID back to VARCHAR
    op.execute(
        "ALTER TABLE prompt_experiments ALTER COLUMN dataset_id TYPE VARCHAR USING dataset_id::text"
    )
    # ### end Alembic commands ###
