"""Add EmailVerification

Revision ID: eaf307b21bd9
Revises: cb9906114207
Create Date: 2024-12-16 11:30:02.693730

"""

import sqlalchemy as sa
from alembic import op

# Polar Custom Imports

# revision identifiers, used by Alembic.
revision = "eaf307b21bd9"
down_revision = "cb9906114207"
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(
        "email_verification",
        sa.Column("email", sa.String(), nullable=False),
        sa.Column("token_hash", sa.String(), nullable=False),
        sa.Column("expires_at", sa.TIMESTAMP(timezone=True), nullable=False),
        sa.Column("user_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(
            ["user_id"],
            ["users.id"],
            name=op.f("email_verification_user_id_fkey"),
            ondelete="cascade",
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("email_verification_pkey")),
    )
    op.create_index(
        op.f("ix_email_verification_created_at"),
        "email_verification",
        ["created_at"],
        unique=False,
    )
    op.create_index(
        op.f("ix_email_verification_deleted_at"),
        "email_verification",
        ["deleted_at"],
        unique=False,
    )
    op.create_index(
        op.f("ix_email_verification_modified_at"),
        "email_verification",
        ["modified_at"],
        unique=False,
    )
    op.create_index(
        op.f("ix_email_verification_token_hash"),
        "email_verification",
        ["token_hash"],
        unique=False,
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(
        op.f("ix_email_verification_token_hash"), table_name="email_verification"
    )
    op.drop_index(
        op.f("ix_email_verification_modified_at"), table_name="email_verification"
    )
    op.drop_index(
        op.f("ix_email_verification_deleted_at"), table_name="email_verification"
    )
    op.drop_index(
        op.f("ix_email_verification_created_at"), table_name="email_verification"
    )
    op.drop_table("email_verification")
    # ### end Alembic commands ###
