"""empty message

Revision ID: roc_dingo_0032_up_cuc_constraints
Revises: roc_dingo_0031_add_sbm_subtype
Create Date: 2025-02-06 10:51:57.794747

"""

from pathlib import Path
from alembic import op

# revision identifiers, used by Alembic.
revision = "roc_dingo_0032_up_cuc_constraints"
down_revision = "roc_dingo_0031_add_sbm_subtype"
branch_labels = None
depends_on = None


def upgrade():

    # Command to ensure there is no [cuc_time, sweep_step] or [cuc_time, kcoeff_pkt_nr] doublons before creating the constraint
    filename = "SQL/roc_dingo_0032__upgrade.sql"
    sql_file = Path(__file__).parent / filename
    with open(sql_file, "r") as sql_content:
        sql_cmd = sql_content.read()
        op.execute(sql_cmd)

    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(
        "bia_sweep_log_sweep_step_utc_time_key",
        "bia_sweep_log",
        schema="pipeline",
        type_="unique",
    )
    op.create_unique_constraint(
        "bia_sweep_log_cuc_time_sweep_step_key", "bia_sweep_log", ["cuc_time", "sweep_step"], schema="pipeline"
    )
    op.drop_constraint(
        "lfr_kcoeff_dump_utc_time_kcoeff_pkt_nr_key",
        "lfr_kcoeff_dump",
        schema="pipeline",
        type_="unique",
    )
    op.create_unique_constraint(
        "lfr_kcoeff_dump_cuc_time_kcoeff_pkt_nr_key", "lfr_kcoeff_dump", ["cuc_time", "kcoeff_pkt_nr"], schema="pipeline"
    )
    # ### end Alembic commands ###


def downgrade():

    # Command to ensure there is no [utc_time, sweep_step] or [utc_time, kcoeff_pkt_nr] doublons before creating the constraint
    filename = "SQL/roc_dingo_0032__downgrade.sql"
    sql_file = Path(__file__).parent / filename
    with open(sql_file, "r") as sql_content:
        sql_cmd = sql_content.read()
        op.execute(sql_cmd)

    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint("lfr_kcoeff_dump_cuc_time_kcoeff_pkt_nr_key", "lfr_kcoeff_dump", schema="pipeline", type_="unique")
    op.create_unique_constraint(
        "lfr_kcoeff_dump_utc_time_kcoeff_pkt_nr_key",
        "lfr_kcoeff_dump",
        ["utc_time", "kcoeff_pkt_nr"],
        schema="pipeline",
    )
    op.drop_constraint("bia_sweep_log_cuc_time_sweep_step_key", "bia_sweep_log", schema="pipeline", type_="unique")
    op.create_unique_constraint(
        "bia_sweep_log_sweep_step_utc_time_key",
        "bia_sweep_log",
        ["sweep_step", "utc_time"],
        schema="pipeline",
    )
    # ### end Alembic commands ###
