models: Add denormalized .realm column to Message.

This commit adds the OPTIONAL .realm attribute to Message
(and ArchivedMessage), with the server changes for making new Messages
have this set. Old Messages still have to be migrated to backfill this,
before it can be non-nullable.

Appropriate test changes to correctly set .realm for Messages the tests
manually create are included here as well.
This commit is contained in:
Mateusz Mandera
2022-09-27 21:42:31 +02:00
committed by Tim Abbott
parent a4008d938a
commit 00b3546c9f
21 changed files with 176 additions and 36 deletions

View File

@@ -1469,6 +1469,8 @@ def import_message_data(realm: Realm, sender_map: Dict[int, Record], import_dir:
# apply them.
message_id_map = ID_MAP["message"]
for row in data["zerver_message"]:
del row["realm"]
row["realm_id"] = realm.id
row["id"] = message_id_map[row["id"]]
for row in data["zerver_usermessage"]: