"""make user phone optional and add google sign-in

Revision ID: 361adf5ed93f
Revises: 4edb552c8288
Create Date: 2026-07-20 11:13:18.995444

"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = "361adf5ed93f"
down_revision: Union[str, None] = "4edb552c8288"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    # NOTE: autogenerate also proposed op.drop_table('spatial_ref_sys') (a
    # PostGIS system table — dropping it would break PostGIS entirely),
    # dropping refresh_tokens_token_hash_key (pre-existing unique-index-vs-
    # named-constraint drift unrelated to this migration — same drift
    # called out in 42828b3f2eea), and dropping users_phone_key the same
    # way. That last one looks plausible here since phone is changing, but
    # it isn't actually needed: a UNIQUE constraint already permits
    # multiple NULLs in Postgres, so uniqueness stays enforced by the
    # existing ix_users_phone index with no changes required. All three
    # removed by hand.
    op.add_column(
        "users", sa.Column("google_sub", sa.String(length=255), nullable=True)
    )
    op.alter_column(
        "users", "phone", existing_type=sa.VARCHAR(length=20), nullable=True
    )
    op.create_index(op.f("ix_users_google_sub"), "users", ["google_sub"], unique=True)
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f("ix_users_google_sub"), table_name="users")
    op.alter_column(
        "users", "phone", existing_type=sa.VARCHAR(length=20), nullable=False
    )
    op.drop_column("users", "google_sub")
    # ### end Alembic commands ###
