mirror of https://github.com/zulip/zulip.git
migrations: Add reverser for emoji_alt_code migration.
This is easy to do, and prevents this feature from getting a server admin stuck in potentially a pretty uncomfortable way -- unable to roll back a deploy.
This commit is contained in:
parent
ca1129dea3
commit
6f128279e8
|
@ -9,6 +9,17 @@ def change_emojiset(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> Non
|
||||||
user.emojiset = "text"
|
user.emojiset = "text"
|
||||||
user.save(update_fields=["emojiset"])
|
user.save(update_fields=["emojiset"])
|
||||||
|
|
||||||
|
def reverse_change_emojiset(apps: StateApps,
|
||||||
|
schema_editor: DatabaseSchemaEditor) -> None:
|
||||||
|
UserProfile = apps.get_model("zerver", "UserProfile")
|
||||||
|
for user in UserProfile.objects.filter(emojiset="text"):
|
||||||
|
# Resetting `emojiset` to "google" (the default) doesn't make an
|
||||||
|
# exact round trip, but it's nearly indistinguishable -- the setting
|
||||||
|
# shouldn't really matter while `emoji_alt_code` is true.
|
||||||
|
user.emoji_alt_code = True
|
||||||
|
user.emojiset = "google"
|
||||||
|
user.save(update_fields=["emoji_alt_code", "emojiset"])
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
@ -21,7 +32,7 @@ class Migration(migrations.Migration):
|
||||||
name='emojiset',
|
name='emojiset',
|
||||||
field=models.CharField(choices=[('google', 'Google'), ('apple', 'Apple'), ('twitter', 'Twitter'), ('emojione', 'EmojiOne'), ('text', 'Plain text')], default='google', max_length=20),
|
field=models.CharField(choices=[('google', 'Google'), ('apple', 'Apple'), ('twitter', 'Twitter'), ('emojione', 'EmojiOne'), ('text', 'Plain text')], default='google', max_length=20),
|
||||||
),
|
),
|
||||||
migrations.RunPython(change_emojiset),
|
migrations.RunPython(change_emojiset, reverse_change_emojiset),
|
||||||
migrations.RemoveField(
|
migrations.RemoveField(
|
||||||
model_name='userprofile',
|
model_name='userprofile',
|
||||||
name='emoji_alt_code',
|
name='emoji_alt_code',
|
||||||
|
|
Loading…
Reference in New Issue