"""Add CustomerSessionCode

Revision ID: 648a1268ab97
Revises: e47b6d16d3e0
Create Date: 2024-12-12 16:27:41.581614

"""

import sqlalchemy as sa
from alembic import op

# Polar Custom Imports

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


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "customer_session_codes",
        sa.Column("code", sa.CHAR(length=64), nullable=False),
        sa.Column("expires_at", sa.TIMESTAMP(timezone=True), nullable=False),
        sa.Column("customer_id", sa.Uuid(), nullable=False),
        sa.Column("id", sa.Uuid(), nullable=False),
        sa.Column("created_at", sa.TIMESTAMP(timezone=True), nullable=False),
        sa.Column("modified_at", sa.TIMESTAMP(timezone=True), nullable=True),
        sa.Column("deleted_at", sa.TIMESTAMP(timezone=True), nullable=True),
        sa.ForeignKeyConstraint(
            ["customer_id"],
            ["customers.id"],
            name=op.f("customer_session_codes_customer_id_fkey"),
            ondelete="cascade",
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("customer_session_codes_pkey")),
        sa.UniqueConstraint("code", name=op.f("customer_session_codes_code_key")),
    )
    op.create_index(
        op.f("ix_customer_session_codes_created_at"),
        "customer_session_codes",
        ["created_at"],
        unique=False,
    )
    op.create_index(
        op.f("ix_customer_session_codes_deleted_at"),
        "customer_session_codes",
        ["deleted_at"],
        unique=False,
    )
    op.create_index(
        op.f("ix_customer_session_codes_expires_at"),
        "customer_session_codes",
        ["expires_at"],
        unique=False,
    )
    op.create_index(
        op.f("ix_customer_session_codes_modified_at"),
        "customer_session_codes",
        ["modified_at"],
        unique=False,
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(
        op.f("ix_customer_session_codes_modified_at"),
        table_name="customer_session_codes",
    )
    op.drop_index(
        op.f("ix_customer_session_codes_expires_at"),
        table_name="customer_session_codes",
    )
    op.drop_index(
        op.f("ix_customer_session_codes_deleted_at"),
        table_name="customer_session_codes",
    )
    op.drop_index(
        op.f("ix_customer_session_codes_created_at"),
        table_name="customer_session_codes",
    )
    op.drop_table("customer_session_codes")
    # ### end Alembic commands ###
