"""add_uniqueness_constraints

Revision ID: e726c627ded5
Revises: 0f106fabd22f
Create Date: 2024-11-23 10:55:20.681791

"""

from typing import Sequence
from typing import Union

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

# revision identifiers, used by Alembic.
revision: str = "e726c627ded5"
down_revision: Union[str, None] = "0f106fabd22f"
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.alter_column(
        "xarizmi_candlestick",
        "interval_type",
        existing_type=postgresql.INTERVAL(),
        type_=sa.Enum(
            "MIN_1",
            "MIN_3",
            "MIN_5",
            "MIN_15",
            "MIN_30",
            "HOUR_1",
            "HOUR_2",
            "HOUR_4",
            "HOUR_6",
            "HOUR_8",
            "HOUR_12",
            "DAY_1",
            "DAY_7",
            "DAY_14",
            "WEEK_1",
            "MONTH_1",
            name="interval_type_enum",
        ),
        existing_nullable=False,
    )
    op.create_unique_constraint(
        "uix_symbol_interval",
        "xarizmi_candlestick",
        ["symbol_id", "interval_type", "interval"],
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(
        "uix_symbol_interval", "xarizmi_candlestick", type_="unique"
    )
    op.alter_column(
        "xarizmi_candlestick",
        "interval_type",
        existing_type=sa.Enum(
            "MIN_1",
            "MIN_3",
            "MIN_5",
            "MIN_15",
            "MIN_30",
            "HOUR_1",
            "HOUR_2",
            "HOUR_4",
            "HOUR_6",
            "HOUR_8",
            "HOUR_12",
            "DAY_1",
            "DAY_7",
            "DAY_14",
            "WEEK_1",
            "MONTH_1",
            name="interval_type_enum",
        ),
        type_=postgresql.INTERVAL(),
        existing_nullable=False,
    )
    # ### end Alembic commands ###
