"""add filename to release_package unique constraint

Revision ID: 7d855b38fe83
Revises: 8d901bc90e67
Create Date: 2026-05-26 22:55:00.000000

"""
from typing import Sequence, Union

from alembic import op


# revision identifiers, used by Alembic.
revision: str = '7d855b38fe83'
down_revision: Union[str, Sequence[str], None] = '8d901bc90e67'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    """Upgrade schema."""
    # 删除旧约束（release_id + platform + architecture）
    op.drop_constraint('uix_app_pkg_platform_arch', 'mjk_app_release_packages', type_='unique')
    # 创建新约束（release_id + platform + architecture + filename）
    op.create_unique_constraint(
        'uix_app_pkg_platform_arch_filename',
        'mjk_app_release_packages',
        ['release_id', 'platform', 'architecture', 'filename']
    )


def downgrade() -> None:
    """Downgrade schema."""
    # 删除新约束
    op.drop_constraint('uix_app_pkg_platform_arch_filename', 'mjk_app_release_packages', type_='unique')
    # 恢复旧约束
    op.create_unique_constraint(
        'uix_app_pkg_platform_arch',
        'mjk_app_release_packages',
        ['release_id', 'platform', 'architecture']
    )
