"""Create `login_codes`-table

Revision ID: 6fdd959d5dbe
Revises: 33e67212795d
Create Date: 2025-07-11 15:39:23.496054

"""

import sqlalchemy as sa
from alembic import op

# Polar Custom Imports

# revision identifiers, used by Alembic.
revision = "6fdd959d5dbe"
down_revision = "33e67212795d"
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(
        "login_codes",
        sa.Column("code_hash", sa.CHAR(length=64), nullable=False),
        sa.Column("expires_at", sa.TIMESTAMP(timezone=True), nullable=False),
        sa.Column("email", sa.String(length=320), nullable=False),
        sa.Column("user_id", sa.Uuid(), nullable=True),
        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("login_codes_user_id_fkey"),
            ondelete="cascade",
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("login_codes_pkey")),
    )
    op.create_index(
        op.f("ix_login_codes_code_hash"), "login_codes", ["code_hash"], unique=True
    )
    op.create_index(
        op.f("ix_login_codes_created_at"), "login_codes", ["created_at"], unique=False
    )
    op.create_index(
        op.f("ix_login_codes_deleted_at"), "login_codes", ["deleted_at"], unique=False
    )
    op.create_index(
        op.f("ix_login_codes_email"), "login_codes", ["email"], unique=False
    )
    op.create_index(
        op.f("ix_login_codes_expires_at"), "login_codes", ["expires_at"], unique=False
    )
    op.create_index(
        op.f("ix_login_codes_modified_at"), "login_codes", ["modified_at"], unique=False
    )
    op.create_index(
        op.f("ix_login_codes_user_id"), "login_codes", ["user_id"], unique=False
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f("ix_login_codes_user_id"), table_name="login_codes")
    op.drop_index(op.f("ix_login_codes_modified_at"), table_name="login_codes")
    op.drop_index(op.f("ix_login_codes_expires_at"), table_name="login_codes")
    op.drop_index(op.f("ix_login_codes_email"), table_name="login_codes")
    op.drop_index(op.f("ix_login_codes_deleted_at"), table_name="login_codes")
    op.drop_index(op.f("ix_login_codes_created_at"), table_name="login_codes")
    op.drop_index(op.f("ix_login_codes_code_hash"), table_name="login_codes")
    op.drop_table("login_codes")
    # ### end Alembic commands ###
