"""add_user_id_to_transkripsi_tasks

Revision ID: c65ec0e3284a
Revises: 2caf45d8d213
Create Date: 2026-04-23 10:12:22.001543

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


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


def upgrade() -> None:
    with op.batch_alter_table('transkripsi_tasks', schema=None) as batch_op:
        # Kolom mungkin sudah ada dari percobaan sebelumnya, skip jika sudah ada
        batch_op.add_column(sa.Column('user_id', sa.Integer(), nullable=True))
        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', schema=None) as batch_op:
        batch_op.drop_constraint('fk_transkripsi_tasks_user_id', type_='foreignkey')
        batch_op.drop_column('user_id')