migrations: Fix system bot realm not having a name.

This prevented migration 0345
(517c2ed39d / #19696) from applying on
systems that were created after the refactoring that resulted in the
system bot realm potentially having null as its name.

(We've already confirmed that normal realms, created via
`do_create_realm`, shouldn't be able to have this unusual state).
This commit is contained in:
Tim Abbott 2021-09-09 09:21:18 -07:00
parent 545911b051
commit c5261af2dc
2 changed files with 18 additions and 1 deletions

View File

@ -13,7 +13,7 @@ def server_initialized() -> bool:
def create_internal_realm() -> None:
from zerver.lib.actions import do_change_can_forge_sender
realm = Realm.objects.create(string_id=settings.SYSTEM_BOT_REALM)
realm = Realm.objects.create(string_id=settings.SYSTEM_BOT_REALM, name="System bot realm")
RealmAuditLog.objects.create(
realm=realm, event_type=RealmAuditLog.REALM_CREATED, event_time=realm.date_created
)

View File

@ -1,15 +1,32 @@
# Generated by Django 3.2.6 on 2021-09-08 22:35
from django.conf import settings
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps
def rename_system_bot_realm(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
# Prior to this migration, the system bot realm had name incorrectly set to null.
Realm = apps.get_model("zerver", "Realm")
Realm.objects.filter(name=None, string_id=settings.SYSTEM_BOT_REALM).update(
name="System bot realm"
)
class Migration(migrations.Migration):
atomic = False
dependencies = [
("zerver", "0344_alter_emojiset_default_value"),
]
operations = [
migrations.RunPython(
rename_system_bot_realm,
reverse_code=migrations.RunPython.noop,
elidable=True,
),
migrations.AlterField(
model_name="realm",
name="name",