"""add cascade delete to scans and logs

Revision ID: 2da47dbd4a52
Revises: 71a3e5b4db2a
Create Date: 2025-06-08 22:09:41.393963

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision: str = '2da47dbd4a52'
down_revision: Union[str, None] = '71a3e5b4db2a'
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.alter_column('scans', 'status',
               existing_type=postgresql.ENUM('PENDING', 'RUNNING', 'COMPLETED', 'FAILED', name='transformstatus'),
               nullable=True)
    op.drop_constraint('scans_sketch_id_fkey', 'scans', type_='foreignkey')
    op.create_foreign_key(None, 'scans', 'sketches', ['sketch_id'], ['id'], onupdate='CASCADE', ondelete='CASCADE')
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, 'scans', type_='foreignkey')
    op.create_foreign_key('scans_sketch_id_fkey', 'scans', 'sketches', ['sketch_id'], ['id'])
    op.alter_column('scans', 'status',
               existing_type=postgresql.ENUM('PENDING', 'RUNNING', 'COMPLETED', 'FAILED', name='transformstatus'),
               nullable=False)
    # ### end Alembic commands ###
