"""Make conversions.file_hash NOT NULL

Revision ID: b5a6c3d4e7f8
Revises: 2b627d0885c3
Create Date: 2025-10-06 21:05:00.000000

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = "b5a6c3d4e7f8"
down_revision: Union[str, None] = "2b627d0885c3"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # Ensure no NULLs remain before altering nullability
    op.execute("UPDATE conversions SET file_hash = '' WHERE file_hash IS NULL")
    op.alter_column(
        "conversions",
        "file_hash",
        existing_type=sa.String(length=64),
        nullable=False,
        existing_nullable=True,
    )


def downgrade() -> None:
    op.alter_column(
        "conversions",
        "file_hash",
        existing_type=sa.String(length=64),
        nullable=True,
        existing_nullable=False,
    )
