"""Rename object_storage_namespace table to storage_namespace and bucket column to namespace

Revision ID: 1f76b4c0f399
Revises: 08c1867e266e
Create Date: 2025-09-22 09:01:23.257664

"""

from alembic import op

# revision identifiers, used by Alembic.
revision = "1f76b4c0f399"
down_revision = "08c1867e266e"
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    # Rename table from object_storage_namespace to storage_namespace
    op.rename_table("object_storage_namespace", "storage_namespace")

    # Rename column from bucket to namespace
    op.alter_column("storage_namespace", "bucket", new_column_name="namespace")

    # Update constraint name to match the new column name
    op.drop_constraint("uq_storage_id_bucket", "storage_namespace", type_="unique")
    op.create_unique_constraint(
        "uq_storage_id_namespace", "storage_namespace", ["storage_id", "namespace"]
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    # Reverse the constraint name change
    op.drop_constraint("uq_storage_id_namespace", "storage_namespace", type_="unique")
    op.create_unique_constraint(
        "uq_storage_id_bucket", "storage_namespace", ["storage_id", "namespace"]
    )

    # Reverse column rename from namespace to bucket
    op.alter_column("storage_namespace", "namespace", new_column_name="bucket")

    # Reverse table rename from storage_namespace to object_storage_namespace
    op.rename_table("storage_namespace", "object_storage_namespace")
    # ### end Alembic commands ###
