Files
notifications-api/migrations/versions/0295_api_key_constraint.py
Cliff Hill 1157f5639d black, isort, flake8
Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
2023-12-08 21:43:52 -05:00

31 lines
732 B
Python

"""
Revision ID: 0295_api_key_constraint
Revises: 0294_add_verify_reply_to
Create Date: 2019-06-04 13:49:50.685493
"""
import sqlalchemy as sa
from alembic import op
revision = "0295_api_key_constraint"
down_revision = "0294_add_verify_reply_to"
def upgrade():
op.drop_constraint("uix_service_to_key_name", "api_keys", type_="unique")
op.create_index(
"uix_service_to_key_name",
"api_keys",
["service_id", "name"],
unique=True,
postgresql_where=sa.text("expiry_date IS NULL"),
)
def downgrade():
op.drop_index("uix_service_to_key_name", table_name="api_keys")
op.create_unique_constraint(
"uix_service_to_key_name", "api_keys", ["service_id", "name"]
)