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:
Rebecca Law
2019-06-04 15:30:27 +01:00
parent 396149ddde
commit a1f6a5f78a
3 changed files with 50 additions and 9 deletions

View File

@@ -742,7 +742,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__ = (
UniqueConstraint('service_id', 'name', name='uix_service_to_key_name'),
Index('uix_service_to_key_name', 'service_id', 'name', unique=True, postgresql_where=expiry_date.is_(None)),
)
@property