"""Add Member model

Revision ID: 14338d209978
Revises: 6f4085630fe9
Create Date: 2025-11-18 14:47:51.420549

"""

import sqlalchemy as sa
from alembic import op

# Polar Custom Imports

# revision identifiers, used by Alembic.
revision = "14338d209978"
down_revision = "6f4085630fe9"
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(
        "members",
        sa.Column("customer_id", sa.Uuid(), nullable=False),
        sa.Column("email", sa.String(length=320), nullable=False),
        sa.Column("name", sa.String(), nullable=True),
        sa.Column("external_id", sa.String(), nullable=True),
        sa.Column("role", sa.String(), 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("members_customer_id_fkey"),
            ondelete="restrict",
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("members_pkey")),
        sa.UniqueConstraint(
            "customer_id",
            "email",
            name="members_customer_id_email_key",
            postgresql_nulls_not_distinct=True,
        ),
        sa.UniqueConstraint(
            "customer_id",
            "external_id",
            name="members_customer_id_external_id_key",
            postgresql_nulls_not_distinct=True,
        ),
    )
    op.create_index(
        op.f("ix_members_created_at"), "members", ["created_at"], unique=False
    )
    op.create_index(
        op.f("ix_members_customer_id"), "members", ["customer_id"], unique=False
    )
    op.create_index(
        op.f("ix_members_deleted_at"), "members", ["deleted_at"], unique=False
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f("ix_members_deleted_at"), table_name="members")
    op.drop_index(op.f("ix_members_customer_id"), table_name="members")
    op.drop_index(op.f("ix_members_created_at"), table_name="members")
    op.drop_table("members")
    # ### end Alembic commands ###
