"""Drop PullRequest

Revision ID: db4153e8ea36
Revises: e9d8922faba6
Create Date: 2024-10-09 16:03:33.435459

"""

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql

# Polar Custom Imports

# revision identifiers, used by Alembic.
revision = "db4153e8ea36"
down_revision = "e9d8922faba6"
branch_labels: tuple[str] | None = None
depends_on: tuple[str] | None = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(
        "notifications_pull_request_id_fkey", "notifications", type_="foreignkey"
    )
    op.drop_column("notifications", "pull_request_id")
    op.drop_index(
        "idx_pull_requests_title_tsv",
        table_name="pull_requests",
        postgresql_using="gin",
    )
    op.drop_index("ix_pull_requests_created_at", table_name="pull_requests")
    op.drop_index("ix_pull_requests_deleted_at", table_name="pull_requests")
    op.drop_index("ix_pull_requests_modified_at", table_name="pull_requests")
    op.drop_index("ix_pull_requests_organization_id", table_name="pull_requests")
    op.drop_index("ix_pull_requests_repository_id", table_name="pull_requests")
    op.drop_table("pull_requests")
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        "notifications",
        sa.Column("pull_request_id", sa.UUID(), autoincrement=False, nullable=True),
    )
    op.create_foreign_key(
        "notifications_pull_request_id_fkey",
        "notifications",
        "pull_requests",
        ["pull_request_id"],
        ["id"],
    )
    op.create_table(
        "pull_requests",
        sa.Column("commits", sa.INTEGER(), autoincrement=False, nullable=True),
        sa.Column("additions", sa.INTEGER(), autoincrement=False, nullable=True),
        sa.Column("deletions", sa.INTEGER(), autoincrement=False, nullable=True),
        sa.Column("changed_files", sa.INTEGER(), autoincrement=False, nullable=True),
        sa.Column(
            "requested_reviewers",
            postgresql.JSONB(astext_type=sa.Text()),
            autoincrement=False,
            nullable=True,
        ),
        sa.Column(
            "requested_teams",
            postgresql.JSONB(astext_type=sa.Text()),
            autoincrement=False,
            nullable=True,
        ),
        sa.Column("is_draft", sa.BOOLEAN(), autoincrement=False, nullable=True),
        sa.Column("is_rebaseable", sa.BOOLEAN(), autoincrement=False, nullable=True),
        sa.Column("review_comments", sa.INTEGER(), autoincrement=False, nullable=True),
        sa.Column(
            "maintainer_can_modify", sa.BOOLEAN(), autoincrement=False, nullable=True
        ),
        sa.Column("is_mergeable", sa.BOOLEAN(), autoincrement=False, nullable=True),
        sa.Column("mergeable_state", sa.VARCHAR(), autoincrement=False, nullable=True),
        sa.Column("auto_merge", sa.VARCHAR(), autoincrement=False, nullable=True),
        sa.Column(
            "merged_by",
            postgresql.JSONB(astext_type=sa.Text()),
            autoincrement=False,
            nullable=True,
        ),
        sa.Column(
            "merged_at",
            postgresql.TIMESTAMP(timezone=True),
            autoincrement=False,
            nullable=True,
        ),
        sa.Column("merge_commit_sha", sa.VARCHAR(), autoincrement=False, nullable=True),
        sa.Column(
            "head",
            postgresql.JSONB(astext_type=sa.Text()),
            autoincrement=False,
            nullable=True,
        ),
        sa.Column(
            "base",
            postgresql.JSONB(astext_type=sa.Text()),
            autoincrement=False,
            nullable=True,
        ),
        sa.Column("platform", sa.VARCHAR(), autoincrement=False, nullable=False),
        sa.Column("external_id", sa.BIGINT(), autoincrement=False, nullable=False),
        sa.Column("number", sa.INTEGER(), autoincrement=False, nullable=False),
        sa.Column("title", sa.VARCHAR(), autoincrement=False, nullable=False),
        sa.Column("body", sa.TEXT(), autoincrement=False, nullable=True),
        sa.Column("comments", sa.INTEGER(), autoincrement=False, nullable=True),
        sa.Column(
            "author",
            postgresql.JSONB(astext_type=sa.Text()),
            autoincrement=False,
            nullable=True,
        ),
        sa.Column(
            "author_association", sa.VARCHAR(), autoincrement=False, nullable=True
        ),
        sa.Column(
            "labels",
            postgresql.JSONB(astext_type=sa.Text()),
            autoincrement=False,
            nullable=True,
        ),
        sa.Column(
            "assignee",
            postgresql.JSONB(astext_type=sa.Text()),
            autoincrement=False,
            nullable=True,
        ),
        sa.Column(
            "assignees",
            postgresql.JSONB(astext_type=sa.Text()),
            autoincrement=False,
            nullable=True,
        ),
        sa.Column(
            "milestone",
            postgresql.JSONB(astext_type=sa.Text()),
            autoincrement=False,
            nullable=True,
        ),
        sa.Column(
            "closed_by",
            postgresql.JSONB(astext_type=sa.Text()),
            autoincrement=False,
            nullable=True,
        ),
        sa.Column(
            "reactions",
            postgresql.JSONB(astext_type=sa.Text()),
            autoincrement=False,
            nullable=True,
        ),
        sa.Column("state", sa.VARCHAR(), autoincrement=False, nullable=False),
        sa.Column("state_reason", sa.VARCHAR(), autoincrement=False, nullable=True),
        sa.Column(
            "issue_closed_at",
            postgresql.TIMESTAMP(timezone=True),
            autoincrement=False,
            nullable=True,
        ),
        sa.Column(
            "issue_created_at",
            postgresql.TIMESTAMP(timezone=True),
            autoincrement=False,
            nullable=False,
        ),
        sa.Column(
            "issue_modified_at",
            postgresql.TIMESTAMP(timezone=True),
            autoincrement=False,
            nullable=True,
        ),
        sa.Column(
            "title_tsv",
            postgresql.TSVECTOR(),
            sa.Computed(
                "to_tsvector('simple'::regconfig, (title)::text)", persisted=True
            ),
            autoincrement=False,
            nullable=False,
        ),
        sa.Column("organization_id", sa.UUID(), autoincrement=False, nullable=False),
        sa.Column("repository_id", sa.UUID(), autoincrement=False, nullable=False),
        sa.Column("id", sa.UUID(), autoincrement=False, nullable=False),
        sa.Column(
            "created_at",
            postgresql.TIMESTAMP(timezone=True),
            autoincrement=False,
            nullable=False,
        ),
        sa.Column(
            "modified_at",
            postgresql.TIMESTAMP(timezone=True),
            autoincrement=False,
            nullable=True,
        ),
        sa.Column(
            "deleted_at",
            postgresql.TIMESTAMP(timezone=True),
            autoincrement=False,
            nullable=True,
        ),
        sa.ForeignKeyConstraint(
            ["organization_id"],
            ["external_organizations.id"],
            name="pull_requests_organization_id_fkey",
        ),
        sa.ForeignKeyConstraint(
            ["repository_id"],
            ["repositories.id"],
            name="pull_requests_repository_id_fkey",
        ),
        sa.PrimaryKeyConstraint("id", name="pull_requests_pkey"),
        sa.UniqueConstraint("external_id", name="pull_requests_external_id_key"),
        sa.UniqueConstraint(
            "organization_id",
            "repository_id",
            "number",
            name="pull_requests_organization_id_repository_id_number_key",
        ),
    )
    op.create_index(
        "ix_pull_requests_repository_id",
        "pull_requests",
        ["repository_id"],
        unique=False,
    )
    op.create_index(
        "ix_pull_requests_organization_id",
        "pull_requests",
        ["organization_id"],
        unique=False,
    )
    op.create_index(
        "ix_pull_requests_modified_at", "pull_requests", ["modified_at"], unique=False
    )
    op.create_index(
        "ix_pull_requests_deleted_at", "pull_requests", ["deleted_at"], unique=False
    )
    op.create_index(
        "ix_pull_requests_created_at", "pull_requests", ["created_at"], unique=False
    )
    op.create_index(
        "idx_pull_requests_title_tsv",
        "pull_requests",
        ["title_tsv"],
        unique=False,
        postgresql_using="gin",
    )
    # ### end Alembic commands ###
