"""Set missing user id

Revision ID: 722e93c4ab22
Revises: a7122bc0b2ca
Create Date: 2024-10-08 12:08:46.844673

"""

from typing import Sequence, Union

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "722e93c4ab22"
down_revision: Union[str, None] = "a7122bc0b2ca"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.execute(
        """
        UPDATE transcript as t
        SET user_id = r.user_id
        FROM meeting m
        JOIN room r ON m.room_id = r.id
        WHERE t.meeting_id = m.id AND t.user_id IS NULL
        """
    )


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    pass
    # ### end Alembic commands ###
