zilencer: Change push bouncer API to accept uuids as user identifier.

This is the first step to making the full switch to self-hosted servers
use user uuids, per issue #18017. The old id format is still supported
of course, for backward compatibility.

This commit is separate in order to allow deploying *just* the bouncer
API change to production first.
This commit is contained in:
Mateusz Mandera
2022-02-23 20:25:30 +01:00
committed by Tim Abbott
parent 75f7426e21
commit 0677c90170
5 changed files with 199 additions and 60 deletions

View File

@@ -63,10 +63,18 @@ class RemotePushDeviceToken(AbstractPushDeviceToken):
server: RemoteZulipServer = models.ForeignKey(RemoteZulipServer, on_delete=models.CASCADE)
# The user id on the remote server for this device
user_id: int = models.BigIntegerField(db_index=True)
user_id: int = models.BigIntegerField(db_index=True, null=True)
user_uuid: UUID = models.UUIDField(null=True)
class Meta:
unique_together = ("server", "user_id", "kind", "token")
unique_together = [
# These indexes rely on the property that in Postgres,
# NULL != NULL in the context of unique indexes, so multiple
# rows with the same values in these columns can exist
# if one of them is NULL.
("server", "user_id", "kind", "token"),
("server", "user_uuid", "kind", "token"),
]
def __str__(self) -> str:
return f"<RemotePushDeviceToken {self.server} {self.user_id}>"