migration: Rename 'populate_db' Client to 'ZulipDataImport'.

This commit:

* Creates a migration to rename any existing Client with
name="populate_db" to "ZulipDataImport".
* Updates populate_db.py to use ZulipDataImport for new
message creation

These changes should make code to identify imported messages
considerably more readable.

Fixes #33909.
This commit is contained in:
userAdityaa
2025-04-15 22:46:56 +05:30
committed by Tim Abbott
parent 9577dc9da7
commit 354a16fb0a
6 changed files with 50 additions and 10 deletions

View File

@@ -38,6 +38,17 @@ from zproject.backends import all_default_backend_names
# stubs
ZerverFieldsT: TypeAlias = dict[str, Any]
DATA_IMPORT_CLIENTS = {
# Match low ID clients in zerver/lib/server_initialization.py.
# This has no functional impact other than ensuring low IDs.
"Internal": 1,
"website": 2,
"ZulipMobile": 3,
"ZulipElectron": 4,
# Special client key to be used for data import messages.
"ZulipDataImport": 5,
}
class SubscriberHandler:
def __init__(self) -> None:
@@ -352,9 +363,8 @@ def build_realm(
) -> ZerverFieldsT:
realm = dict(
zerver_client=[
{"name": "populate_db", "id": 1},
{"name": "website", "id": 2},
{"name": "API", "id": 3},
{"name": client_name, "id": client_id}
for client_name, client_id in DATA_IMPORT_CLIENTS.items()
],
zerver_customprofilefield=[],
zerver_customprofilefieldvalue=[],
@@ -520,7 +530,7 @@ def build_message(
zulip_message, exclude=["recipient", "sender", "sending_client"]
)
zulip_message_dict["sender"] = user_id
zulip_message_dict["sending_client"] = 1
zulip_message_dict["sending_client"] = DATA_IMPORT_CLIENTS["ZulipDataImport"]
zulip_message_dict["recipient"] = recipient_id
zulip_message_dict["date_sent"] = date_sent