"""add "pep" to PubsubNode

Revision ID: 007439b3b0ce
Revises: f9ce59cfc13f
Create Date: 2026-04-12 00:46:56.674238

"""

from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = "007439b3b0ce"
down_revision = "f9ce59cfc13f"
branch_labels = None
depends_on = None


def upgrade():
    with op.batch_alter_table("pubsub_nodes", schema=None) as batch_op:
        batch_op.add_column(
            sa.Column(
                "pep",
                sa.Boolean(create_constraint=True),
                server_default=sa.text("0"),
                nullable=False,
            )
        )
        batch_op.drop_constraint(batch_op.f("uq_pubsub_nodes_profile_id"), type_="unique")
        batch_op.create_unique_constraint(
            batch_op.f("uq_pubsub_nodes_profile_id"),
            ["profile_id", "service", "name", "pep"],
        )


def downgrade():
    with op.batch_alter_table("pubsub_nodes", schema=None) as batch_op:
        batch_op.drop_constraint(batch_op.f("uq_pubsub_nodes_profile_id"), type_="unique")
        batch_op.create_unique_constraint(
            batch_op.f("uq_pubsub_nodes_profile_id"), ["profile_id", "service", "name"]
        )
        batch_op.drop_column("pep")
