"""remove foreign keys on endpoints

Revision ID: 70e0533aa49a
Revises: 9fc0e92ea510
Create Date: 2025-03-05 14:10:39.897579

"""

from alembic import op
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = "70e0533aa49a"
down_revision = "9fc0e92ea510"
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column(
        "endpoint_tokens", "session_owner", existing_type=postgresql.UUID(), nullable=False
    )
    op.drop_constraint(
        "fk_endpoint_tokens_session_owner_users", "endpoint_tokens", type_="foreignkey"
    )
    op.drop_constraint(
        "fk_endpoint_tokens_endpoint_endpoints", "endpoint_tokens", type_="foreignkey"
    )
    op.drop_constraint("fk_endpoints_session_owner_users", "endpoints", type_="foreignkey")
    op.drop_constraint("fk_endpoints_created_user_users", "endpoints", type_="foreignkey")
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_foreign_key(
        "fk_endpoints_created_user_users",
        "endpoints",
        "users",
        ["created_user"],
        ["uuid"],
        ondelete="RESTRICT",
    )
    op.create_foreign_key(
        "fk_endpoints_session_owner_users",
        "endpoints",
        "users",
        ["session_owner"],
        ["uuid"],
        ondelete="RESTRICT",
    )
    op.create_foreign_key(
        "fk_endpoint_tokens_endpoint_endpoints",
        "endpoint_tokens",
        "endpoints",
        ["endpoint"],
        ["id"],
        ondelete="SET NULL",
    )
    op.create_foreign_key(
        "fk_endpoint_tokens_session_owner_users",
        "endpoint_tokens",
        "users",
        ["session_owner"],
        ["uuid"],
    )
    op.alter_column(
        "endpoint_tokens", "session_owner", existing_type=postgresql.UUID(), nullable=True
    )
    # ### end Alembic commands ###
