2016-09-28 00:03:13 +02:00
|
|
|
from django.db import migrations
|
2020-04-27 07:19:08 +02:00
|
|
|
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
|
2016-09-28 00:03:13 +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 add_domain_to_realm_alias_if_needed(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
|
2016-09-28 00:03:13 +02:00
|
|
|
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 = [
|
2020-04-29 08:43:25 +02:00
|
|
|
migrations.RunPython(add_domain_to_realm_alias_if_needed, elidable=True)
|
2016-09-28 00:03:13 +02:00
|
|
|
]
|