"""balances

Revision ID: 89d74331994c
Revises: 7365b4898472
Create Date: 2022-12-29 01:55:43.413214

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "89d74331994c"
down_revision = "7365b4898472"
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "balances",
        sa.Column("id", sa.BigInteger(), nullable=False),
        sa.Column("address", sa.String(), nullable=False),
        sa.Column("chain", sa.String(), nullable=False),
        sa.Column("dapp", sa.String(), nullable=True),
        sa.Column("balance", sa.DECIMAL(), nullable=False),
        sa.Column("eth_height", sa.Integer(), nullable=False),
        sa.PrimaryKeyConstraint("id"),
    )

    op.create_index(op.f("ix_balances_address"), "balances", ["address"], unique=False)
    op.execute(
        """
        ALTER TABLE balances ADD CONSTRAINT balances_address_chain_dapp_uindex 
        UNIQUE NULLS NOT DISTINCT (address, chain, dapp)
    """
    )

    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index("ix_balances_address", "balances")
    op.drop_constraint("balances_address_chain_dapp_uindex", "balances")
    op.drop_table("balances")
    # ### end Alembic commands ###
