mirror of
https://github.com/zulip/zulip.git
synced 2025-11-20 06:28:23 +00:00
Add this field to the Stream model will prevent us from having to look at realm data for several types of stream operations, which can be prone to either doing extra database lookups or making our cached data bloated. Going forward, we'll set stream.is_zephyr to True whenever the realm's string id is "zephyr".
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Generated by Django 1.11.5 on 2017-10-08 18:37
|
|
from __future__ import unicode_literals
|
|
|
|
from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor
|
|
from django.db.migrations.state import StateApps
|
|
from django.db import connection, migrations, models
|
|
|
|
def populate_is_zephyr(apps, schema_editor):
|
|
# type: (StateApps, DatabaseSchemaEditor) -> None
|
|
Realm = apps.get_model("zerver", "Realm")
|
|
Stream = apps.get_model("zerver", "Stream")
|
|
|
|
realms = Realm.objects.filter(
|
|
string_id='zephyr',
|
|
)
|
|
|
|
for realm in realms:
|
|
Stream.objects.filter(
|
|
realm_id=realm.id
|
|
).update(
|
|
is_in_zephyr_realm=True
|
|
)
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
('zerver', '0109_mark_tutorial_status_finished'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.AddField(
|
|
model_name='stream',
|
|
name='is_in_zephyr_realm',
|
|
field=models.BooleanField(default=False),
|
|
),
|
|
migrations.RunPython(populate_is_zephyr,
|
|
reverse_code=migrations.RunPython.noop),
|
|
]
|