"""provider_credentials oauth columns

Revision ID: 1f011c42bd4d
Revises: 220ca2e3d53f
Create Date: 2026-06-19 15:25:05.499145
"""

from __future__ import annotations

from collections.abc import Sequence

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

revision: str = "1f011c42bd4d"
down_revision: str | None = "220ca2e3d53f"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    op.add_column(
        "provider_credentials",
        sa.Column("auth_type", sa.Text(), server_default=sa.text("'api_key'"), nullable=False),
    )
    op.add_column(
        "provider_credentials",
        sa.Column("oauth_enc", sa.LargeBinary(), nullable=True),
    )
    op.alter_column(
        "provider_credentials",
        "api_key_enc",
        existing_type=postgresql.BYTEA(),
        nullable=True,
    )


def downgrade() -> None:
    op.alter_column(
        "provider_credentials",
        "api_key_enc",
        existing_type=postgresql.BYTEA(),
        nullable=False,
    )
    op.drop_column("provider_credentials", "oauth_enc")
    op.drop_column("provider_credentials", "auth_type")
