"""Remove MagicLink

Revision ID: f03f2ade2c86
Revises: 3802b2aa320c
Create Date: 2025-08-18 14:40:37.882893

"""

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql

# Polar Custom Imports

# revision identifiers, used by Alembic.
revision = "f03f2ade2c86"
down_revision = "3802b2aa320c"
branch_labels: tuple[str] | None = None
depends_on: tuple[str] | None = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f("ix_magic_links_created_at"), table_name="magic_links")
    op.drop_index(op.f("ix_magic_links_deleted_at"), table_name="magic_links")
    op.drop_index(op.f("ix_magic_links_modified_at"), table_name="magic_links")
    op.drop_index(op.f("ix_magic_links_token_hash"), table_name="magic_links")
    op.drop_table("magic_links")
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "magic_links",
        sa.Column("token_hash", sa.VARCHAR(), autoincrement=False, nullable=False),
        sa.Column(
            "expires_at",
            postgresql.TIMESTAMP(timezone=True),
            autoincrement=False,
            nullable=False,
        ),
        sa.Column("user_email", sa.VARCHAR(), autoincrement=False, nullable=False),
        sa.Column("user_id", sa.UUID(), autoincrement=False, nullable=True),
        sa.Column("source", sa.VARCHAR(), autoincrement=False, nullable=True),
        sa.Column("id", sa.UUID(), autoincrement=False, nullable=False),
        sa.Column(
            "created_at",
            postgresql.TIMESTAMP(timezone=True),
            autoincrement=False,
            nullable=False,
        ),
        sa.Column(
            "modified_at",
            postgresql.TIMESTAMP(timezone=True),
            autoincrement=False,
            nullable=True,
        ),
        sa.Column(
            "deleted_at",
            postgresql.TIMESTAMP(timezone=True),
            autoincrement=False,
            nullable=True,
        ),
        sa.Column(
            "signup_attribution",
            postgresql.JSONB(astext_type=sa.Text()),
            server_default=sa.text("'{}'::jsonb"),
            autoincrement=False,
            nullable=False,
        ),
        sa.ForeignKeyConstraint(
            ["user_id"],
            ["users.id"],
            name=op.f("magic_links_user_id_fkey"),
            ondelete="CASCADE",
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("magic_links_pkey")),
    )
    op.create_index(
        op.f("ix_magic_links_token_hash"), "magic_links", ["token_hash"], unique=False
    )
    op.create_index(
        op.f("ix_magic_links_modified_at"), "magic_links", ["modified_at"], unique=False
    )
    op.create_index(
        op.f("ix_magic_links_deleted_at"), "magic_links", ["deleted_at"], unique=False
    )
    op.create_index(
        op.f("ix_magic_links_created_at"), "magic_links", ["created_at"], unique=False
    )
    # ### end Alembic commands ###
