models: New PresenceSequence model and UserPresence.last_update_id col.

Migration plan:
1. Add NULLable .last_update_id column to UserPresence with default 0
   for new objects.
2. Backfill the value to 0 for old UserPresences, can be done in the
   background while server is running.
3. Make the column non-NULL.
4. Add new model PresenceSequence and create its rows for old realms.
This commit is contained in:
Mateusz Mandera
2024-05-03 00:52:41 +02:00
committed by Tim Abbott
parent 6750b02437
commit 0dca8f2a38
6 changed files with 179 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ from zerver.models import (
UserProfile,
)
from zerver.models.clients import get_client
from zerver.models.presence import PresenceSequence
from zerver.models.users import get_system_bot
from zproject.backends import all_default_backend_names
@@ -48,6 +49,8 @@ def create_internal_realm() -> None:
]
)
PresenceSequence.objects.create(realm=realm, last_update_id=0)
# Create some client objects for common requests. Not required;
# just ensures these get low IDs in production, and in development
# avoids an extra database write for the first HTTP request in