"""Add Customer.external_id and Checkout.customer_external_id

Revision ID: e80c47585ffb
Revises: cb77e86b9e13
Create Date: 2025-02-27 15:07:43.589014

"""

import sqlalchemy as sa
from alembic import op

# Polar Custom Imports

# revision identifiers, used by Alembic.
revision = "e80c47585ffb"
down_revision = "cb77e86b9e13"
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(
        "checkouts", sa.Column("customer_external_id", sa.String(), nullable=True)
    )
    op.add_column("customers", sa.Column("external_id", sa.String(), nullable=True))
    op.create_unique_constraint(
        op.f("customers_organization_id_external_id_key"),
        "customers",
        ["organization_id", "external_id"],
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(
        op.f("customers_organization_id_external_id_key"), "customers", type_="unique"
    )
    op.drop_column("customers", "external_id")
    op.drop_column("checkouts", "customer_external_id")
    # ### end Alembic commands ###
