"""first_migrations

Revision ID: 4bcb140de81f
Revises:
Create Date: 2024-11-23 00:32:01.735301

"""

from typing import Sequence
from typing import Union

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision: str = "4bcb140de81f"
down_revision: Union[str, None] = None
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! ###
    op.create_table(
        "xarizmi_exchange",
        sa.Column("name", sa.String(), nullable=False),
        sa.PrimaryKeyConstraint("name"),
    )
    op.create_table(
        "xarizmi_symbol",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("base_currency", sa.String(), nullable=False),
        sa.Column("quote_currency", sa.String(), nullable=False),
        sa.Column("fee_currency", sa.String(), nullable=True),
        sa.Column(
            "name",
            sa.String(),
            sa.Computed(
                "base_currency || '-' || quote_currency",
            ),
            nullable=False,
        ),
        sa.Column("exchange_name", sa.String(), nullable=False),
        sa.ForeignKeyConstraint(
            ["exchange_name"],
            ["xarizmi_exchange.name"],
        ),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint(
            "base_currency",
            "quote_currency",
            "exchange_name",
            name="uix_symbol_name_exchange",
        ),
        sa.UniqueConstraint("name"),
    )
    op.create_table(
        "xarizmi_candlestick",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("symbol_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["symbol_id"],
            ["xarizmi_symbol.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table("xarizmi_candlestick")
    op.drop_table("xarizmi_symbol")
    op.drop_table("xarizmi_exchange")
    # ### end Alembic commands ###
