"""add_dataset_transform_table

Revision ID: 4392c0a6800e
Revises: 7c2dbe560050
Create Date: 2025-11-15 11:15:20.246124

"""

import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

from alembic import op

# revision identifiers, used by Alembic.
revision = "4392c0a6800e"
down_revision = "7c2dbe560050"
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "dataset_transforms",
        sa.Column("id", sa.UUID(), nullable=False),
        sa.Column("dataset_id", sa.UUID(), nullable=False),
        sa.Column("name", sa.String(), nullable=False),
        sa.Column("description", sa.String(), nullable=True),
        sa.Column("definition", postgresql.JSON(astext_type=sa.Text()), nullable=False),
        sa.Column("created_at", sa.TIMESTAMP(), nullable=False),
        sa.Column("updated_at", sa.TIMESTAMP(), nullable=False),
        sa.ForeignKeyConstraint(["dataset_id"], ["datasets.id"], ondelete="CASCADE"),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint(
            "dataset_id",
            "name",
            name="uq_dataset_transforms_dataset_id_name",
        ),
    )
    op.create_index(
        "idx_dataset_transforms_dataset_id",
        "dataset_transforms",
        ["dataset_id"],
        unique=False,
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index("idx_dataset_transforms_dataset_id", table_name="dataset_transforms")
    op.drop_table("dataset_transforms")
    # ### end Alembic commands ###
