"""empty message

Revision ID: 6e8c6ec99a5c
Revises: fa7f7ef37e5e
Create Date: 2026-05-10 23:42:49.991731

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from db.models.tasks.shared import TaskUsage
from db.models.utils import DataClassJSON
from db.models.utils import PydanticJSON

# revision identifiers, used by Alembic.
revision: str = '6e8c6ec99a5c'
down_revision: Union[str, Sequence[str], None] = 'fa7f7ef37e5e'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    """Upgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('subtasks',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('usage', DataClassJSON(TaskUsage), nullable=False),
    sa.Column('messages', PydanticJSON(None), nullable=False),
    sa.Column('task_id', sa.Integer(), nullable=False),
    sa.Column('agent_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['agent_id'], ['agents.id'], ondelete='SET NULL'),
    sa.ForeignKeyConstraint(['task_id'], ['tasks.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    with op.batch_alter_table('providers', schema=None) as batch_op:
        batch_op.alter_column('type',
               existing_type=sa.VARCHAR(length=9),
               type_=sa.Enum('OPENAI', 'OPENAI_RESPONSES', 'ANTHROPIC', name='llmproviders'),
               existing_nullable=False)

    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('providers', schema=None) as batch_op:
        batch_op.alter_column('type',
               existing_type=sa.Enum('OPENAI', 'OPENAI_RESPONSES', 'ANTHROPIC', name='llmproviders'),
               type_=sa.VARCHAR(length=9),
               existing_nullable=False)

    op.drop_table('subtasks')
    # ### end Alembic commands ###
