From 52b8a84219b77b110e3733b73c5120f04476039c Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Sat, 25 Feb 2023 01:29:12 +0000 Subject: [PATCH] models: Drop unique index on user/message/emoji_name. c7d0192755be added the unique constraint on `user_profile_id,message_id,reaction_type,emoji_code`, but left the existing constraint on `user_profile_id,message_id,emoji_name`. As explained in the comment added in 3cd543ee98e9, `emoji_name` cannot be trusted to be unique, as it is possible to have an Unicode emoji reaction and a custom emoji with the same name on a message. Remove the overly-constraining unique index, now that c7d0192755be has provided the correct one. --- ...chivedreaction_unique_together_and_more.py | 20 +++++++++++++++++++ zerver/models.py | 5 +---- 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 zerver/migrations/0431_alter_archivedreaction_unique_together_and_more.py diff --git a/zerver/migrations/0431_alter_archivedreaction_unique_together_and_more.py b/zerver/migrations/0431_alter_archivedreaction_unique_together_and_more.py new file mode 100644 index 0000000000..90fe2c36b7 --- /dev/null +++ b/zerver/migrations/0431_alter_archivedreaction_unique_together_and_more.py @@ -0,0 +1,20 @@ +# Generated by Django 4.1.6 on 2023-02-25 01:22 + +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("zerver", "0430_fix_audit_log_objects_for_group_based_stream_settings"), + ] + + operations = [ + migrations.AlterUniqueTogether( + name="archivedreaction", + unique_together={("user_profile", "message", "reaction_type", "emoji_code")}, + ), + migrations.AlterUniqueTogether( + name="reaction", + unique_together={("user_profile", "message", "reaction_type", "emoji_code")}, + ), + ] diff --git a/zerver/models.py b/zerver/models.py index 1ea42b1c06..5b6942cb15 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -3169,10 +3169,7 @@ class AbstractEmoji(models.Model): class AbstractReaction(AbstractEmoji): class Meta: abstract = True - unique_together = ( - ("user_profile", "message", "emoji_name"), - ("user_profile", "message", "reaction_type", "emoji_code"), - ) + unique_together = ("user_profile", "message", "reaction_type", "emoji_code") class Reaction(AbstractReaction):