"""add genlocke_transfers table

Revision ID: e5f6a7b9c0d1
Revises: d4e5f6a7b9c0
Create Date: 2026-02-09 22:00:00.000000

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = 'e5f6a7b9c0d1'
down_revision: Union[str, Sequence[str], None] = 'd4e5f6a7b9c0'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.create_table(
        'genlocke_transfers',
        sa.Column('id', sa.Integer(), primary_key=True),
        sa.Column('genlocke_id', sa.Integer(), sa.ForeignKey('genlockes.id', ondelete='CASCADE'), nullable=False, index=True),
        sa.Column('source_encounter_id', sa.Integer(), sa.ForeignKey('encounters.id'), nullable=False, index=True),
        sa.Column('target_encounter_id', sa.Integer(), sa.ForeignKey('encounters.id'), nullable=False, unique=True),
        sa.Column('source_leg_order', sa.SmallInteger(), nullable=False),
        sa.Column('target_leg_order', sa.SmallInteger(), nullable=False),
        sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
        sa.UniqueConstraint('target_encounter_id', name='uq_genlocke_transfers_target'),
    )


def downgrade() -> None:
    op.drop_table('genlocke_transfers')
