"""Add file_hash to assets and ingest_jobs

Revision ID: 031
Revises: 030
Create Date: 2026-07-07

为素材去重检测功能添加 file_hash 字段。
"""

import sqlalchemy as sa

from alembic import op

revision = "031"
down_revision = "030"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.add_column("assets", sa.Column("file_hash", sa.String(64), nullable=True))
    op.create_index(op.f("ix_assets_file_hash"), "assets", ["file_hash"])

    op.add_column("ingest_jobs", sa.Column("file_hash", sa.String(64), nullable=True))
    op.create_index(op.f("ix_ingest_jobs_file_hash"), "ingest_jobs", ["file_hash"])


def downgrade() -> None:
    op.drop_index(op.f("ix_ingest_jobs_file_hash"), table_name="ingest_jobs")
    op.drop_column("ingest_jobs", "file_hash")

    op.drop_index(op.f("ix_assets_file_hash"), table_name="assets")
    op.drop_column("assets", "file_hash")
