2016-07-19 14:35:08 +02:00
|
|
|
from django.conf import settings
|
|
|
|
from django.core.exceptions import ObjectDoesNotExist
|
2017-11-16 00:44:00 +01:00
|
|
|
from django.db import migrations, models
|
2020-04-27 07:19:08 +02:00
|
|
|
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
|
2017-11-16 00:44:00 +01:00
|
|
|
from django.db.migrations.state import StateApps
|
2016-07-19 14:35:08 +02:00
|
|
|
|
2020-01-14 21:59:46 +01:00
|
|
|
|
2017-10-26 11:36:30 +02:00
|
|
|
def set_subdomain_of_default_realm(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
|
2016-07-19 14:35:08 +02:00
|
|
|
if settings.DEVELOPMENT:
|
|
|
|
Realm = apps.get_model('zerver', 'Realm')
|
|
|
|
try:
|
|
|
|
default_realm = Realm.objects.get(domain="zulip.com")
|
|
|
|
except ObjectDoesNotExist:
|
|
|
|
default_realm = None
|
|
|
|
|
|
|
|
if default_realm is not None:
|
|
|
|
default_realm.subdomain = "zulip"
|
|
|
|
default_realm.save()
|
|
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
|
|
|
|
dependencies = [
|
2017-06-22 11:50:50 +02:00
|
|
|
('zerver', '0001_initial'),
|
2016-07-19 14:35:08 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
operations = [
|
|
|
|
migrations.AddField(
|
|
|
|
model_name='realm',
|
|
|
|
name='subdomain',
|
|
|
|
field=models.CharField(max_length=40, unique=True, null=True),
|
|
|
|
),
|
|
|
|
migrations.RunPython(set_subdomain_of_default_realm)
|
|
|
|
]
|