Skip to content

Commit

Permalink
undo unique index
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanParish committed Feb 7, 2025
1 parent a7c6fd4 commit b3eb9b1
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ fileignoreconfig:
- filename: app/dao/api_key_dao.py
checksum: c44cbd8ae02fb1d551a1f0941365c11977564a6444950ee2b0282ee4b5fd1314
- filename: app/models.py
checksum: 79d0f675baa0bb0bf5dc6abe65b8f4812e2b6285d7303c7aa521fada5fe0003e
checksum: 386e62b8fc698c2ceb709c46b062b0880ff8289aaaad05bd8934ca1941027cc1
- filename: app/notifications/process_notifications.py
checksum: 199e175df804d0d9cc5413630ae0d3be805a3bfc54f2822f9a54936054354c9a
- filename: app/schema_validation/__init__.py
Expand Down
2 changes: 1 addition & 1 deletion app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ class ApiKey(db.Model, Versioned):
created_by_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), index=True, nullable=False)

__table_args__ = (
Index('uix_service_and_key_name', 'service_id', 'name', unique=True, postgresql_where=revoked.is_(False)),
Index('uix_service_to_key_name', 'service_id', 'name', unique=True, postgresql_where=expiry_date.is_(None)),
)

@property
Expand Down
4 changes: 0 additions & 4 deletions migrations/versions/0375_add_key_revoked.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@

def upgrade():
op.add_column('api_keys', sa.Column('revoked', sa.Boolean(), nullable=False, server_default=sa.false()))
op.drop_index('uix_service_to_key_name', table_name='api_keys', postgresql_where='(expiry_date IS NULL)')
op.create_index('uix_service_and_key_name', 'api_keys', ['service_id', 'name'], unique=True, postgresql_where=sa.text('revoked IS false'))
op.add_column('api_keys_history', sa.Column('revoked', sa.Boolean(), nullable=False, server_default=sa.false()))


def downgrade():
op.drop_column('api_keys_history', 'revoked')
op.drop_index('uix_service_and_key_name', table_name='api_keys', postgresql_where=sa.text('revoked IS false'))
op.create_index('uix_service_to_key_name', 'api_keys', ['service_id', 'name'], unique=True, postgresql_where='(expiry_date IS NULL)')
op.drop_column('api_keys', 'revoked')
1 change: 0 additions & 1 deletion tests/app/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,6 @@ def create_api_key(service, key_type=KEY_TYPE_NORMAL, key_name=None, expired=Fal

if expired:
data['expiry_date'] = datetime.utcnow()
data['revoked'] = True

api_key = ApiKey(**data)
db.session.add(api_key)
Expand Down

0 comments on commit b3eb9b1

Please sign in to comment.