Files
zulip/zerver/migrations/0033_migrate_domain_to_realmalias.py
Aman Agrawal 47bf111de8 migrations: Mark RunPython statements elidable.
This will make django automatically remove them when we run
squashmigrations. There are still some RunSQL statements which
we will have to take care of manually.
2020-04-29 10:41:20 -07:00

24 lines
854 B
Python

from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps
def add_domain_to_realm_alias_if_needed(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
Realm = apps.get_model('zerver', 'Realm')
RealmAlias = apps.get_model('zerver', 'RealmAlias')
for realm in Realm.objects.all():
# if realm.domain already exists in RealmAlias, assume it is correct
if not RealmAlias.objects.filter(domain=realm.domain).exists():
RealmAlias.objects.create(realm=realm, domain=realm.domain)
class Migration(migrations.Migration):
dependencies = [
('zerver', '0032_verify_all_medium_avatar_images'),
]
operations = [
migrations.RunPython(add_domain_to_realm_alias_if_needed, elidable=True)
]