mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-17 10:42:25 -05:00
Update the unique constraint for the name of an api_key so that it only looks at api_keys that are not expired (or expiry_date is null).
This will allow clients to create a new api key with the same name.
This commit is contained in:
23
migrations/versions/0295_api_key_constraint.py
Normal file
23
migrations/versions/0295_api_key_constraint.py
Normal file
@@ -0,0 +1,23 @@
|
||||
"""
|
||||
|
||||
Revision ID: 0295_api_key_constraint
|
||||
Revises: 0294_add_verify_reply_to
|
||||
Create Date: 2019-06-04 13:49:50.685493
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
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'])
|
||||
Reference in New Issue
Block a user