-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reactions: Store the emoji codepoint in the database.
This is the first part of a larger migration to convert Zulip's reactions storage to something based on the codepoint, not the emoji name that the user typed in, so that we don't need to worry about changes in the names we're using breaking the emoji storage.
- Loading branch information
1 parent
7e99262
commit dc06466
Showing
6 changed files
with
119 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.2 on 2017-06-18 21:26 | ||
from __future__ import unicode_literals | ||
|
||
import os | ||
import ujson | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor | ||
from django.db.migrations.state import StateApps | ||
|
||
def populate_new_fields(apps, schema_editor): | ||
# type: (StateApps, DatabaseSchemaEditor) -> None | ||
# Open the JSON file which contains the data to be used for migration. | ||
MIGRATION_DATA_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "management", "data") | ||
path_to_unified_reactions = os.path.join(MIGRATION_DATA_PATH, "unified_reactions.json") | ||
unified_reactions = ujson.load(open(path_to_unified_reactions)) | ||
|
||
Reaction = apps.get_model('zerver', 'Reaction') | ||
for reaction in Reaction.objects.all(): | ||
reaction.emoji_code = unified_reactions.get(reaction.emoji_name) | ||
if reaction.emoji_code is None: | ||
# If it's not present in the unified_reactions map, it's a realm emoji. | ||
reaction.codepoint = reaction.emoji_name | ||
if reaction.emoji_name == 'zulip': | ||
# `:zulip:` emoji is a fake realm emoji. | ||
reaction.reaction_type = 'fake_realm_emoji' | ||
else: | ||
reaction.reaction_type = 'realm_emoji' | ||
reaction.save() | ||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('zerver', '0084_realmemoji_deactivated'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='reaction', | ||
name='emoji_code', | ||
field=models.TextField(default='unset'), | ||
preserve_default=False, | ||
), | ||
migrations.AddField( | ||
model_name='reaction', | ||
name='reaction_type', | ||
field=models.CharField(choices=[('unicode_emoji', 'Unicode emoji'), ('realm_emoji', 'Realm emoji'), ('fake_realm_emoji', 'Fake realm emoji')], default='unicode_emoji', max_length=30), | ||
), | ||
migrations.RunPython(populate_new_fields, | ||
reverse_code=migrations.RunPython.noop), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters