"""Add Wallet.type and remove WalletTransaction.type

Revision ID: 5b1942f56927
Revises: 2990d8555091
Create Date: 2025-11-20 14:14:21.902101

"""

import sqlalchemy as sa
from alembic import op

# Polar Custom Imports

# revision identifiers, used by Alembic.
revision = "5b1942f56927"
down_revision = "2990d8555091"
branch_labels: tuple[str] | None = None
depends_on: tuple[str] | None = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column("wallet_transactions", "type")
    op.add_column(
        "wallets",
        sa.Column("type", sa.String(), nullable=True),
    )
    op.execute("UPDATE wallets SET type = 'usage'")
    op.alter_column("wallets", "type", nullable=False)
    op.create_unique_constraint(
        op.f("wallets_type_currency_customer_id_key"),
        "wallets",
        ["type", "currency", "customer_id"],
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(
        op.f("wallets_type_currency_customer_id_key"), "wallets", type_="unique"
    )
    op.drop_column("wallets", "type")
    op.add_column(
        "wallet_transactions",
        sa.Column("type", sa.VARCHAR(), autoincrement=False, nullable=False),
    )
    # ### end Alembic commands ###
