"""full_schema

Revision ID: 96214ecca77c
Revises: b380d6b8f171
Create Date: 2026-04-27 16:02:23.761851

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


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


def upgrade() -> None:
    # Use batch mode for SQLite to add foreign key to existing table
    # The tables service_rates and transactions already exist, so we skip dropping them
    with op.batch_alter_table('transkripsi_tasks', recreate='always') as batch_op:
        # Drop any existing foreign key with the same name if needed (optional)
        # batch_op.drop_constraint('fk_transkripsi_tasks_user_id', type_='foreignkey')
        # Create the foreign key constraint
        batch_op.create_foreign_key(
            'fk_transkripsi_tasks_user_id',
            'users',
            ['user_id'],
            ['id'],
            ondelete='SET NULL'
        )


def downgrade() -> None:
    with op.batch_alter_table('transkripsi_tasks', recreate='always') as batch_op:
        batch_op.drop_constraint('fk_transkripsi_tasks_user_id', type_='foreignkey')