"""Add file_hash and is_identical_file columns to proof_versions

Revision ID: 005_add_file_hash
Revises: 004_cleanup_duplicate_dropdown_options
Create Date: 2025-01-25

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision: str = '005_add_file_hash'
down_revision: Union[str, None] = '004_cleanup_duplicates'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # Add file_hash column (MD5 hex digest is always 32 characters)
    op.add_column(
        'proof_versions',
        sa.Column('file_hash', sa.String(32), nullable=True)
    )
    # Add is_identical_file column to track if this version is identical to previous
    op.add_column(
        'proof_versions',
        sa.Column('is_identical_file', sa.Boolean(), nullable=True, server_default='false')
    )


def downgrade() -> None:
    op.drop_column('proof_versions', 'is_identical_file')
    op.drop_column('proof_versions', 'file_hash')
