"""add_title/short_and_long_summary_and_remove_summary

Revision ID: 99365b0cd87b
Revises: b3df9681cae9
Create Date: 2023-09-01 20:19:47.216334

"""

from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision: str = "99365b0cd87b"
down_revision: Union[str, None] = "b3df9681cae9"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.execute(
        "UPDATE transcript SET events = "
        'REPLACE(events::text, \'"event": "SUMMARY"\', \'"event": "LONG_SUMMARY"\')::json;'
    )
    op.alter_column("transcript", "summary", new_column_name="long_summary")
    op.add_column("transcript", sa.Column("title", sa.String(), nullable=True))
    op.add_column("transcript", sa.Column("short_summary", sa.String(), nullable=True))
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.execute(
        "UPDATE transcript SET events = "
        'REPLACE(events::text, \'"event": "LONG_SUMMARY"\', \'"event": "SUMMARY"\')::json;'
    )
    with op.batch_alter_table("transcript", schema=None) as batch_op:
        batch_op.alter_column("long_summary", nullable=True, new_column_name="summary")
    op.drop_column("transcript", "title")
    op.drop_column("transcript", "short_summary")
    # ### end Alembic commands ###
