2017-05-01 07:29:56 +02:00
|
|
|
# Generated by Django 1.11.2 on 2017-06-18 21:26
|
|
|
|
import os
|
|
|
|
|
2020-08-07 01:09:47 +02:00
|
|
|
import orjson
|
2017-05-01 07:29:56 +02:00
|
|
|
from django.db import migrations, models
|
2020-04-27 07:19:08 +02:00
|
|
|
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
|
2017-05-01 07:29:56 +02:00
|
|
|
from django.db.migrations.state import StateApps
|
|
|
|
|
2020-01-14 21:59:46 +01:00
|
|
|
|
2017-10-26 11:36:30 +02:00
|
|
|
def populate_new_fields(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
|
2017-05-01 07:29:56 +02:00
|
|
|
# Open the JSON file which contains the data to be used for migration.
|
2021-02-12 08:19:30 +01:00
|
|
|
MIGRATION_DATA_PATH = os.path.join(
|
|
|
|
os.path.dirname(os.path.dirname(__file__)), "management", "data"
|
|
|
|
)
|
2017-05-01 07:29:56 +02:00
|
|
|
path_to_unified_reactions = os.path.join(MIGRATION_DATA_PATH, "unified_reactions.json")
|
2020-08-07 01:09:47 +02:00
|
|
|
with open(path_to_unified_reactions, "rb") as f:
|
|
|
|
unified_reactions = orjson.loads(f.read())
|
2017-05-01 07:29:56 +02:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
Reaction = apps.get_model("zerver", "Reaction")
|
2017-05-01 07:29:56 +02:00
|
|
|
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.emoji_code = reaction.emoji_name
|
2021-02-12 08:20:45 +01:00
|
|
|
if reaction.emoji_name == "zulip":
|
2017-05-01 07:29:56 +02:00
|
|
|
# `:zulip:` emoji is a zulip special custom emoji.
|
2021-02-12 08:20:45 +01:00
|
|
|
reaction.reaction_type = "zulip_extra_emoji"
|
2017-05-01 07:29:56 +02:00
|
|
|
else:
|
2021-02-12 08:20:45 +01:00
|
|
|
reaction.reaction_type = "realm_emoji"
|
2017-05-01 07:29:56 +02:00
|
|
|
reaction.save()
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2017-05-01 07:29:56 +02:00
|
|
|
class Migration(migrations.Migration):
|
|
|
|
|
|
|
|
dependencies = [
|
2021-02-12 08:20:45 +01:00
|
|
|
("zerver", "0096_add_password_required"),
|
2017-05-01 07:29:56 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
operations = [
|
|
|
|
migrations.AddField(
|
2021-02-12 08:20:45 +01:00
|
|
|
model_name="reaction",
|
|
|
|
name="emoji_code",
|
|
|
|
field=models.TextField(default="unset"),
|
2017-05-01 07:29:56 +02:00
|
|
|
preserve_default=False,
|
|
|
|
),
|
|
|
|
migrations.AddField(
|
2021-02-12 08:20:45 +01:00
|
|
|
model_name="reaction",
|
|
|
|
name="reaction_type",
|
2021-02-12 08:19:30 +01:00
|
|
|
field=models.CharField(
|
|
|
|
choices=[
|
2021-02-12 08:20:45 +01:00
|
|
|
("unicode_emoji", "Unicode emoji"),
|
|
|
|
("realm_emoji", "Custom emoji"),
|
|
|
|
("zulip_extra_emoji", "Zulip extra emoji"),
|
2021-02-12 08:19:30 +01:00
|
|
|
],
|
2021-02-12 08:20:45 +01:00
|
|
|
default="unicode_emoji",
|
2021-02-12 08:19:30 +01:00
|
|
|
max_length=30,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
migrations.RunPython(
|
|
|
|
populate_new_fields, reverse_code=migrations.RunPython.noop, elidable=True
|
2017-05-01 07:29:56 +02:00
|
|
|
),
|
|
|
|
]
|