zulip/zerver/migrations/0217_migrate_create_stream_...

31 lines
1.2 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-05-06 13:15
from __future__ import unicode_literals
from django.db import migrations
from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps
def upgrade_create_stream_policy(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
Realm = apps.get_model('zerver', 'Realm')
Realm.objects.filter(waiting_period_threshold__exact=0) \
.filter(create_stream_by_admins_only=False) \
.update(create_stream_policy=1) # CREATE_STREAM_POLICY_MEMBERS
Realm.objects.filter(create_stream_by_admins_only=True) \
.update(create_stream_policy=2) # CREATE_STREAM_POLICY_ADMINS
Realm.objects.filter(waiting_period_threshold__gt=0) \
.filter(create_stream_by_admins_only=False) \
.update(create_stream_policy=3) # CREATE_STREAM_POLICY_WAITING_PERIOD
class Migration(migrations.Migration):
dependencies = [
('zerver', '0216_add_create_stream_policy'),
]
operations = [
migrations.RunPython(upgrade_create_stream_policy,
reverse_code=migrations.RunPython.noop),
]