Files
zulip/zerver/migrations/0081_make_emoji_lowercase.py
Cory Lynch b1bfe9f42e Add migration to force lowercase existing realm emoji.
Since realm emoji are now required to be lowercase,
an appropriate migration was added to retroactively
fix any emoji that might have contained uppercase
letters.

Also, the validator on the model was changed to
reject uppercase letters.
2017-05-11 19:10:21 -07:00

37 lines
1.3 KiB
Python

# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-05-02 21:44
from __future__ import unicode_literals
import django.core.validators
from django.db import migrations, models
from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps
class Migration(migrations.Migration):
dependencies = [
('zerver', '0080_realm_description_length'),
]
def emoji_to_lowercase(apps, schema_editor):
# type: (StateApps, DatabaseSchemaEditor) -> None
RealmEmoji = apps.get_model("zerver", "RealmEmoji")
emoji = RealmEmoji.objects.all()
for e in emoji:
# Technically, this could create a conflict, but it's
# exceedingly unlikely. If that happens, the sysadmin can
# manually rename the conflicts with the manage.py shell
# and then rerun the migration/upgrade.
e.name = e.name.lower()
e.save()
operations = [
migrations.RunPython(emoji_to_lowercase),
migrations.AlterField(
model_name='realmemoji',
name='name',
field=models.TextField(validators=[django.core.validators.MinLengthValidator(1), django.core.validators.RegexValidator(message='Invalid characters in emoji name', regex='^[0-9a-z.\\-_]+(?<![.\\-_])$')]),
),
]