"""Extend Execution/Task model to estimate unicity and permit caching

Revision ID: bc1934d5d8d4
Revises: 2be1e584707d
Create Date: 2024-10-10 09:49:55.925921

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'bc1934d5d8d4'
down_revision = '2be1e584707d'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('execution', schema=None) as batch_op:
        batch_op.add_column(sa.Column('container', sa.String(), nullable=True))
        batch_op.add_column(sa.Column('container_options', sa.String(), nullable=True))
        batch_op.add_column(sa.Column('input', sa.String(), nullable=True))
        batch_op.add_column(sa.Column('output_folder', sa.String(), nullable=True))
        batch_op.add_column(sa.Column('resource', sa.String(), nullable=True))
        batch_op.add_column(sa.Column('input_hash', sa.String(), nullable=True))
        batch_op.add_column(sa.Column('output_hash', sa.String(), nullable=True))
        batch_op.create_index(batch_op.f('ix_execution_input_hash'), ['input_hash'], unique=False)

    with op.batch_alter_table('task', schema=None) as batch_op:
        batch_op.add_column(sa.Column('use_cache', sa.Boolean(), server_default="0"))

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('task', schema=None) as batch_op:
        batch_op.drop_column('use_cache')

    with op.batch_alter_table('execution', schema=None) as batch_op:
        batch_op.drop_index(batch_op.f('ix_execution_input_hash'))
        batch_op.drop_column('output_hash')
        batch_op.drop_column('input_hash')
        batch_op.drop_column('resource')
        batch_op.drop_column('output_folder')
        batch_op.drop_column('input')
        batch_op.drop_column('container_options')
        batch_op.drop_column('container')

    # ### end Alembic commands ###
