"""Add forgejo profile fields to users.

Revision ID: a3c5e7f9b1d2
Revises: f7d8e9a0b1c2
Create Date: 2026-05-22
"""

from __future__ import annotations

import sqlalchemy as sa
from alembic import op

revision = "a3c5e7f9b1d2"
down_revision = "f2a3b4c5d6e7"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.add_column(
        "users",
        sa.Column(
            "use_forgejo_profile",
            sa.Boolean(),
            nullable=False,
            server_default=sa.text("false"),
        ),
    )
    op.add_column(
        "users",
        sa.Column("forgejo_avatar_url", sa.String(), nullable=True),
    )
    op.add_column(
        "users",
        sa.Column("forgejo_display_name", sa.String(), nullable=True),
    )
    # Remove server default so SQLModel manages the value going forward
    op.alter_column("users", "use_forgejo_profile", server_default=None)


def downgrade() -> None:
    op.drop_column("users", "forgejo_display_name")
    op.drop_column("users", "forgejo_avatar_url")
    op.drop_column("users", "use_forgejo_profile")
