"""Remove PullRequest.is_merged

Revision ID: 70121ed63b4b
Revises: 859b8df4d1cf
Create Date: 2024-08-28 09:56:31.907344

"""

import sqlalchemy as sa
from alembic import op

# Polar Custom Imports

# revision identifiers, used by Alembic.
revision = "70121ed63b4b"
down_revision = "859b8df4d1cf"
branch_labels: tuple[str] | None = None
depends_on: tuple[str] | None = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column("pull_requests", "is_merged")
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        "pull_requests",
        sa.Column("is_merged", sa.BOOLEAN(), autoincrement=False, nullable=True),
    )

    op.execute("UPDATE pull_requests SET is_merged = FALSE WHERE merged_at IS NULL")
    op.execute("UPDATE pull_requests SET is_merged = TRUE WHERE merged_at IS NOT NULL")
    # ### end Alembic commands ###
