"""add external_id and parent_id to events

Revision ID: cd0255e61066
Revises: f3cbc3937937
Create Date: 2025-11-03 15:14:55.787471

"""

import sqlalchemy as sa
from alembic import op

# Polar Custom Imports

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


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column("events", sa.Column("external_id", sa.String(), nullable=True))
    op.add_column("events", sa.Column("parent_id", sa.Uuid(), nullable=True))
    op.create_index(
        op.f("ix_events_external_id"),
        "events",
        ["external_id"],
        unique=True,
    )
    op.create_index(op.f("ix_events_parent_id"), "events", ["parent_id"], unique=False)
    op.create_foreign_key(
        op.f("events_parent_id_fkey"),
        "events",
        "events",
        ["parent_id"],
        ["id"],
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(op.f("events_parent_id_fkey"), "events", type_="foreignkey")
    op.drop_index(op.f("ix_events_parent_id"), table_name="events")
    op.drop_index(op.f("ix_events_external_id"), table_name="events")
    op.drop_column("events", "parent_id")
    op.drop_column("events", "external_id")
    # ### end Alembic commands ###
