migrations: Remove the possibly-duplicated emoji re-uploading.

In 85e531e377, we duplicated this block
of migration code to fix a bug, but moving it (aka deleting the
original copy) is a cleaner solution.
This commit is contained in:
Alex Vandiver 2022-04-01 17:09:35 -07:00 committed by Tim Abbott
parent eb31681934
commit 35e27aef4a
3 changed files with 13 additions and 22 deletions

View File

@ -39,7 +39,6 @@ rules:
- zerver/migrations/0206_stream_rendered_description.py
- zerver/migrations/0209_user_profile_no_empty_password.py
- zerver/migrations/0260_missed_message_addresses_from_redis_to_db.py
- zerver/migrations/0376_set_realmemoji_author_and_reupload_realmemoji.py
- zerver/migrations/0387_reupload_realmemoji_again.py
- pgroonga/migrations/0002_html_escape_subject.py

View File

@ -1,10 +1,7 @@
from django.conf import settings
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps
from zerver.lib.queue import queue_json_publish
def set_emoji_author(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
"""
@ -13,7 +10,6 @@ def set_emoji_author(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> No
"""
RealmEmoji = apps.get_model("zerver", "RealmEmoji")
Realm = apps.get_model("zerver", "Realm")
UserProfile = apps.get_model("zerver", "UserProfile")
ROLE_REALM_OWNER = 100
@ -32,18 +28,12 @@ def set_emoji_author(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> No
RealmEmoji.objects.bulk_update(realm_emoji_to_update, ["author_id"])
if settings.TEST_SUITE:
# There are no custom emoji in the test suite data set, and
# the below code won't work because RabbitMQ isn't enabled for
# the test suite.
return
for realm_id in Realm.objects.order_by("id").values_list("id", flat=True):
event = {
"type": "reupload_realm_emoji",
"realm_id": realm_id,
}
queue_json_publish("deferred_work", event)
# Previously, this also pushed `reupload_realm_emoji` events onto
# the `deferred_work` queue; however,
# https://github.com/zulip/zulip/issues/21608 made those possibly
# run too early, and that work was repeated in migration 0387 to
# ensure it ran. As such, the work has been removed from this
# migration, so it does not unnecessarily run twice.
class Migration(migrations.Migration):

View File

@ -12,12 +12,14 @@ def reupload_realm_emoji(apps: StateApps, schema_editor: DatabaseSchemaEditor) -
started up by puppet during the deployment before migrations were
run on Zulip 5.0.
This means that the deferred_work events produced by migration
0376 might have been processed and discarded without effect.
This means that the deferred_work events originally produced by
migration 0376 might have been processed and discarded without
effect.
Since it's harmless to reupload a custom emoji a second time, we
fix this issue for the slice of servers that have already
installed 5.0 by repeating that part of the migration.
That code has been removed from the 0376 migration, and we run it
here, after the upgrade code has been fixed; servers which already
processed that migration might at worst do this work twice, which
is harmless aside from being a small waste of resources.
"""
Realm = apps.get_model("zerver", "Realm")