typing: Use BaseDatabaseSchemaEditor in place of DatabaseSchemaEditor.

This is a part of #18777.

Signed-off-by: Zixuan James Li <359101898@qq.com>
This commit is contained in:
Zixuan James Li 2022-05-27 17:33:51 -04:00 committed by Tim Abbott
parent 63e9ae8389
commit d5517932cd
101 changed files with 260 additions and 224 deletions

View File

@ -1,10 +1,10 @@
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def delete_messages_sent_to_stream_stat(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
UserCount = apps.get_model("analytics", "UserCount")
StreamCount = apps.get_model("analytics", "StreamCount")

View File

@ -1,10 +1,10 @@
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def clear_message_sent_by_message_type_values(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
UserCount = apps.get_model("analytics", "UserCount")
StreamCount = apps.get_model("analytics", "StreamCount")

View File

@ -1,9 +1,9 @@
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def clear_analytics_tables(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def clear_analytics_tables(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
UserCount = apps.get_model("analytics", "UserCount")
StreamCount = apps.get_model("analytics", "StreamCount")
RealmCount = apps.get_model("analytics", "RealmCount")

View File

@ -1,10 +1,10 @@
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from django.db.models import Count, Sum
def clear_duplicate_counts(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def clear_duplicate_counts(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
"""This is a preparatory migration for our Analytics tables.
The backstory is that Django's unique_together indexes do not properly

View File

@ -5,12 +5,12 @@ from datetime import timedelta
from django.conf import settings
from django.db import migrations, transaction
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def set_expiry_date_for_existing_confirmations(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
Confirmation = apps.get_model("confirmation", "Confirmation")
if not Confirmation.objects.exists():

View File

@ -1,12 +1,12 @@
from django.db import connection, migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from psycopg2.sql import SQL
from zerver.lib.migrate import do_batch_update
def rebuild_pgroonga_index(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def rebuild_pgroonga_index(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
with connection.cursor() as cursor:
do_batch_update(
cursor,

View File

@ -8,14 +8,16 @@ from django.conf import settings
from django.contrib.postgres.indexes import GinIndex
from django.contrib.postgres.search import SearchVectorField
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from django.db.models.functions import Upper
from zerver.models import generate_email_token_for_stream
def migrate_existing_attachment_data(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def migrate_existing_attachment_data(
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
Attachment = apps.get_model("zerver", "Attachment")
Recipient = apps.get_model("zerver", "Recipient")
Stream = apps.get_model("zerver", "Stream")

View File

@ -1,11 +1,13 @@
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def set_subdomain_of_default_realm(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def set_subdomain_of_default_realm(
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
if settings.DEVELOPMENT:
Realm = apps.get_model("zerver", "Realm")
try:

View File

@ -3,7 +3,7 @@ from unittest.mock import patch
from django.conf import settings
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from zerver.lib.upload import upload_backend
@ -24,7 +24,7 @@ def patched_user_avatar_path(user_profile: UserProfile) -> str:
@patch("zerver.lib.upload.user_avatar_path", patched_user_avatar_path)
def verify_medium_avatar_image(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def verify_medium_avatar_image(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
user_profile_model = apps.get_model("zerver", "UserProfile")
for user_profile in user_profile_model.objects.filter(avatar_source="U"):
upload_backend.ensure_avatar_image(user_profile, is_medium=True)

View File

@ -1,10 +1,10 @@
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def add_domain_to_realm_alias_if_needed(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
Realm = apps.get_model("zerver", "Realm")
RealmAlias = apps.get_model("zerver", "RealmAlias")

View File

@ -1,10 +1,10 @@
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from django.db.utils import IntegrityError
def set_string_id_using_domain(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def set_string_id_using_domain(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
Realm = apps.get_model("zerver", "Realm")
for realm in Realm.objects.all():
if not realm.string_id:

View File

@ -2,7 +2,7 @@ import os
import re
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
attachment_url_re = re.compile(r"[/\-]user[\-_]uploads[/\.-].*?(?=[ )]|\Z)")
@ -14,7 +14,7 @@ def attachment_url_to_path_id(attachment_url: str) -> str:
return re.sub("[.]+$", "", path_id_raw, re.M)
def check_and_create_attachments(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def check_and_create_attachments(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
STREAM = 2
Message = apps.get_model("zerver", "Message")
Attachment = apps.get_model("zerver", "Attachment")

View File

@ -2,13 +2,13 @@
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from django.utils.timezone import now as timezone_now
def backfill_user_activations_and_deactivations(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
migration_time = timezone_now()
RealmAuditLog = apps.get_model("zerver", "RealmAuditLog")
@ -33,7 +33,7 @@ def backfill_user_activations_and_deactivations(
)
def reverse_code(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def reverse_code(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
RealmAuditLog = apps.get_model("zerver", "RealmAuditLog")
RealmAuditLog.objects.filter(event_type="user_created").delete()
RealmAuditLog.objects.filter(event_type="user_deactivated").delete()

View File

@ -1,11 +1,11 @@
# Generated by Django 1.10.5 on 2017-04-13 22:12
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from django.db.models import Count
def fix_duplicate_attachments(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def fix_duplicate_attachments(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
"""Migration 0041 had a bug, where if multiple messages referenced the
same attachment, rather than creating a single attachment object
for all of them, we would incorrectly create one for each message.

View File

@ -1,10 +1,10 @@
# Generated by Django 1.10.5 on 2017-05-10 05:59
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def delete_old_scheduled_jobs(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def delete_old_scheduled_jobs(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
"""Delete any old scheduled jobs, to handle changes in the format of
that table. Ideally, we'd translate the jobs, but it's not really
worth the development effort to save a few invitation reminders

View File

@ -1,7 +1,7 @@
# Generated by Django 1.10.5 on 2017-05-02 21:44
import django.core.validators
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
@ -11,7 +11,7 @@ class Migration(migrations.Migration):
("zerver", "0080_realm_description_length"),
]
def emoji_to_lowercase(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def emoji_to_lowercase(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
RealmEmoji = apps.get_model("zerver", "RealmEmoji")
emoji = RealmEmoji.objects.all()
for e in emoji:

View File

@ -1,10 +1,10 @@
# Generated by Django 1.11.2 on 2017-06-20 10:31
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def fix_bot_type(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def fix_bot_type(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
UserProfile = apps.get_model("zerver", "UserProfile")
bots = UserProfile.objects.filter(is_bot=True, bot_type=None)
for bot in bots:

View File

@ -1,10 +1,10 @@
# Generated by Django 1.10.5 on 2017-05-10 05:59
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def delete_old_scheduled_jobs(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def delete_old_scheduled_jobs(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
"""Delete any old scheduled jobs, to handle changes in the format of
send_email. Ideally, we'd translate the jobs, but it's not really
worth the development effort to save a few invitation reminders

View File

@ -1,11 +1,13 @@
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from django.db.models import Max
from django.utils.timezone import now as timezone_now
def backfill_subscription_log_events(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def backfill_subscription_log_events(
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
migration_time = timezone_now()
RealmAuditLog = apps.get_model("zerver", "RealmAuditLog")
Subscription = apps.get_model("zerver", "Subscription")
@ -46,7 +48,7 @@ def backfill_subscription_log_events(apps: StateApps, schema_editor: DatabaseSch
objects_to_create = []
def reverse_code(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def reverse_code(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
RealmAuditLog = apps.get_model("zerver", "RealmAuditLog")
RealmAuditLog.objects.filter(event_type="subscription_created").delete()
RealmAuditLog.objects.filter(event_type="subscription_deactivated").delete()

View File

@ -3,11 +3,11 @@ import os
import orjson
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def populate_new_fields(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def populate_new_fields(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
# Open the JSON file which contains the data to be used for migration.
MIGRATION_DATA_PATH = os.path.join(
os.path.dirname(os.path.dirname(__file__)), "management", "data"

View File

@ -1,12 +1,12 @@
# Generated by Django 1.11.4 on 2017-08-30 00:26
import orjson
from django.db import connection, migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from psycopg2.sql import SQL
def convert_muted_topics(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def convert_muted_topics(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
stream_query = SQL(
"""
SELECT

View File

@ -1,12 +1,12 @@
# Generated by Django 1.11.4 on 2017-08-30 00:26
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from zerver.lib.fix_unreads import fix
def fix_unreads(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def fix_unreads(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
UserProfile = apps.get_model("zerver", "UserProfile")
user_profiles = list(UserProfile.objects.filter(is_bot=False))
for user_profile in user_profiles:

View File

@ -1,10 +1,10 @@
# Generated by Django 1.11.4 on 2017-08-24 02:39
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def fix_realm_string_ids(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def fix_realm_string_ids(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
Realm = apps.get_model("zerver", "Realm")
if Realm.objects.filter(deactivated=False).count() != 2:
return

View File

@ -1,9 +1,11 @@
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def set_tutorial_status_to_finished(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def set_tutorial_status_to_finished(
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
UserProfile = apps.get_model("zerver", "UserProfile")
UserProfile.objects.update(tutorial_status="F")

View File

@ -1,10 +1,10 @@
# Generated by Django 1.11.5 on 2017-10-08 18:37
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def populate_is_zephyr(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def populate_is_zephyr(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
Realm = apps.get_model("zerver", "Realm")
Stream = apps.get_model("zerver", "Stream")

View File

@ -2,12 +2,12 @@
import django.db.models.deletion
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def set_initial_value_for_signup_notifications_stream(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
realm_model = apps.get_model("zerver", "Realm")
realms = realm_model.objects.exclude(notifications_stream__isnull=True)

View File

@ -1,11 +1,13 @@
# Generated by Django 1.11.6 on 2017-11-30 04:58
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def remove_prereg_users_without_realm(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def remove_prereg_users_without_realm(
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
prereg_model = apps.get_model("zerver", "PreregistrationUser")
prereg_model.objects.filter(realm=None, realm_creation=False).delete()

View File

@ -2,12 +2,12 @@
import django.db.models.deletion
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def set_realm_for_existing_scheduledemails(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
scheduledemail_model = apps.get_model("zerver", "ScheduledEmail")
preregistrationuser_model = apps.get_model("zerver", "PreregistrationUser")

View File

@ -1,17 +1,17 @@
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
# change emoji set to text if emoji_alt_code is true.
def change_emojiset(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def change_emojiset(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
UserProfile = apps.get_model("zerver", "UserProfile")
for user in UserProfile.objects.filter(emoji_alt_code=True):
user.emojiset = "text"
user.save(update_fields=["emojiset"])
def reverse_change_emojiset(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def reverse_change_emojiset(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
UserProfile = apps.get_model("zerver", "UserProfile")
for user in UserProfile.objects.filter(emojiset="text"):
# Resetting `emojiset` to "google" (the default) doesn't make an

View File

@ -1,9 +1,9 @@
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def backfill_last_message_id(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def backfill_last_message_id(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
event_type = ["subscription_created", "subscription_deactivated", "subscription_activated"]
RealmAuditLog = apps.get_model("zerver", "RealmAuditLog")
subscription_logs = RealmAuditLog.objects.filter(

View File

@ -1,13 +1,13 @@
# Generated by Django 1.11.6 on 2018-03-09 18:00
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
BOT_CREATION_EVERYONE = 1
def set_initial_value_for_bot_creation_policy(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
Realm = apps.get_model("zerver", "Realm")
Realm.BOT_CREATION_EVERYONE = 1
@ -20,7 +20,7 @@ def set_initial_value_for_bot_creation_policy(
realm.save(update_fields=["bot_creation_policy"])
def reverse_code(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def reverse_code(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
Realm = apps.get_model("zerver", "Realm")
Realm.BOT_CREATION_EVERYONE = 1
for realm in Realm.objects.all():

View File

@ -2,11 +2,11 @@ from collections import defaultdict
from typing import Any, Dict
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def realm_emoji_name_to_id(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def realm_emoji_name_to_id(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
Reaction = apps.get_model("zerver", "Reaction")
RealmEmoji = apps.get_model("zerver", "RealmEmoji")
realm_emoji_by_realm_id: Dict[int, Dict[str, Any]] = defaultdict(dict)
@ -33,7 +33,7 @@ def realm_emoji_name_to_id(apps: StateApps, schema_editor: DatabaseSchemaEditor)
reaction.save()
def reversal(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def reversal(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
Reaction = apps.get_model("zerver", "Reaction")
for reaction in Reaction.objects.filter(reaction_type="realm_emoji"):
reaction.emoji_code = reaction.emoji_name

View File

@ -4,7 +4,7 @@ import shutil
import boto3
from django.conf import settings
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from mypy_boto3_s3.type_defs import CopySourceTypeDef
@ -82,7 +82,9 @@ def get_emoji_file_name(emoji_file_name: str, new_name: str) -> str:
return "".join((new_name, image_ext))
def migrate_realm_emoji_image_files(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def migrate_realm_emoji_image_files(
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
RealmEmoji = apps.get_model("zerver", "RealmEmoji")
uploader = get_uploader()
for realm_emoji in RealmEmoji.objects.all():
@ -93,7 +95,7 @@ def migrate_realm_emoji_image_files(apps: StateApps, schema_editor: DatabaseSche
realm_emoji.save(update_fields=["file_name"])
def reversal(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def reversal(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
# Ensures that migration can be re-run in case of a failure.
RealmEmoji = apps.get_model("zerver", "RealmEmoji")
for realm_emoji in RealmEmoji.objects.all():

View File

@ -1,12 +1,12 @@
# Generated by Django 1.11.6 on 2018-04-03 01:52
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def migrate_fix_invalid_bot_owner_values(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
"""Fixes UserProfile objects that incorrectly had a bot_owner set"""
UserProfile = apps.get_model("zerver", "UserProfile")

View File

@ -2,12 +2,12 @@
from django.conf import settings
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def set_initial_value_for_history_public_to_subscribers(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
stream_model = apps.get_model("zerver", "Stream")
streams = stream_model.objects.all()

View File

@ -1,12 +1,12 @@
# Generated by Django 1.11.11 on 2018-04-08 15:49
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from django.db.models import F
def migrate_set_order_value(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def migrate_set_order_value(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
CustomProfileField = apps.get_model("zerver", "CustomProfileField")
CustomProfileField.objects.all().update(order=F("id"))

View File

@ -1,12 +1,12 @@
# Generated by Django 1.11.13 on 2018-07-05 17:57
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from django.db.models import F
def copy_email_field(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def copy_email_field(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
UserProfile = apps.get_model("zerver", "UserProfile")
UserProfile.objects.all().update(delivery_email=F("email"))

View File

@ -1,10 +1,10 @@
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def change_realm_audit_log_event_type_tense(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
RealmAuditLog = apps.get_model("zerver", "RealmAuditLog")
RealmAuditLog.objects.filter(event_type="user_change_password").update(

View File

@ -2,12 +2,12 @@
import bitfield.models
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from django.db.models import F, Q
def reset_is_private_flag(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def reset_is_private_flag(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
UserMessage = apps.get_model("zerver", "UserMessage")
UserProfile = apps.get_model("zerver", "UserProfile")
user_profile_ids = UserProfile.objects.all().order_by("id").values_list("id", flat=True)

View File

@ -1,9 +1,9 @@
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def change_emojiset_choice(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def change_emojiset_choice(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
UserProfile = apps.get_model("zerver", "UserProfile")
UserProfile.objects.exclude(emojiset__in=["google", "text"]).update(emojiset="google")

View File

@ -1,11 +1,11 @@
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from django.db.models import F
def set_initial_value_of_is_private_flag(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
UserMessage = apps.get_model("zerver", "UserMessage")
Message = apps.get_model("zerver", "Message")

View File

@ -1,11 +1,11 @@
# Generated by Django 1.11.14 on 2018-08-28 19:01
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def change_emojiset_choice(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def change_emojiset_choice(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
UserProfile = apps.get_model("zerver", "UserProfile")
UserProfile.objects.filter(emojiset="google").update(emojiset="google-blob")

View File

@ -1,11 +1,13 @@
# Generated by Django 1.11.16 on 2018-12-27 17:09
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def set_initial_value_for_invited_as(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def set_initial_value_for_invited_as(
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
PreregistrationUser = apps.get_model("zerver", "PreregistrationUser")
for user in PreregistrationUser.objects.all():
if user.invited_as_admin:
@ -15,7 +17,7 @@ def set_initial_value_for_invited_as(apps: StateApps, schema_editor: DatabaseSch
user.save(update_fields=["invited_as"])
def reverse_code(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def reverse_code(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
PreregistrationUser = apps.get_model("zerver", "PreregistrationUser")
for user in PreregistrationUser.objects.all():
if user.invited_as == 2: # PreregistrationUser.INVITE_AS['REALM_ADMIN']

View File

@ -1,9 +1,11 @@
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def render_all_stream_descriptions(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def render_all_stream_descriptions(
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
# FIXME: Application code should not be imported from migrations.
from zerver.lib.streams import render_stream_description

View File

@ -6,7 +6,7 @@ import orjson
from django.conf import settings
from django.contrib.auth.hashers import check_password, make_password
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from django.utils.timezone import now as timezone_now
@ -15,7 +15,7 @@ from zerver.lib.queue import queue_json_publish
from zerver.lib.utils import generate_api_key
def ensure_no_empty_passwords(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def ensure_no_empty_passwords(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
"""With CVE-2019-18933, it was possible for certain users created
using social login (e.g. Google/GitHub auth) to have the empty
string as their password in the Zulip database, rather than

View File

@ -1,11 +1,11 @@
# Generated by Django 1.11.18 on 2019-02-25 12:42
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def backfill_first_message_id(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def backfill_first_message_id(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
Stream = apps.get_model("zerver", "Stream")
Message = apps.get_model("zerver", "Message")
for stream in Stream.objects.all():

View File

@ -2,12 +2,12 @@
from django.conf import settings
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def set_users_for_existing_scheduledemails(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
ScheduledEmail = apps.get_model("zerver", "ScheduledEmail")
for email in ScheduledEmail.objects.all():

View File

@ -1,12 +1,12 @@
# Generated by Django 1.11.20 on 2019-04-29 05:29
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
INVITE_TO_STREAM_POLICY_MEMBERS = 1
def handle_waiting_period(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def handle_waiting_period(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
Realm = apps.get_model("zerver", "Realm")
Realm.INVITE_TO_STREAM_POLICY_WAITING_PERIOD = 3
Realm.objects.filter(waiting_period_threshold__gt=0).update(

View File

@ -1,11 +1,11 @@
# Generated by Django 1.11.20 on 2019-05-06 13:15
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def upgrade_create_stream_policy(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def upgrade_create_stream_policy(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
Realm = apps.get_model("zerver", "Realm")
Realm.CREATE_STREAM_POLICY_MEMBERS = 1
Realm.CREATE_STREAM_POLICY_ADMINS = 2

View File

@ -1,12 +1,12 @@
# Generated by Django 1.11.20 on 2019-05-08 05:42
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def disable_realm_digest_emails_enabled(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
Realm = apps.get_model("zerver", "Realm")
realms = Realm.objects.filter(digest_emails_enabled=True)

View File

@ -1,7 +1,7 @@
# Generated by Django 1.11.18 on 2019-02-13 20:13
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
RECIPIENT_STREAM = 2
@ -13,7 +13,7 @@ SETTINGS_MAP = {
}
def update_notification_settings(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def update_notification_settings(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
Subscription = apps.get_model("zerver", "Subscription")
UserProfile = apps.get_model("zerver", "UserProfile")
@ -29,7 +29,7 @@ def update_notification_settings(apps: StateApps, schema_editor: DatabaseSchemaE
).update(**update_kwargs)
def reverse_notification_settings(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def reverse_notification_settings(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
Subscription = apps.get_model("zerver", "Subscription")
UserProfile = apps.get_model("zerver", "UserProfile")

View File

@ -1,12 +1,14 @@
# Generated by Django 1.11.14 on 2018-08-10 16:04
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from django.db.models import Case, Value, When
def set_initial_value_for_is_muted(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def set_initial_value_for_is_muted(
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
Subscription = apps.get_model("zerver", "Subscription")
Subscription.objects.update(
is_muted=Case(
@ -16,7 +18,7 @@ def set_initial_value_for_is_muted(apps: StateApps, schema_editor: DatabaseSchem
)
def reverse_code(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def reverse_code(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
Subscription = apps.get_model("zerver", "Subscription")
Subscription.objects.update(
in_home_view=Case(

View File

@ -3,7 +3,7 @@
from typing import Any, Dict, Optional
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
# We include a copy of this structure as it was at the time this
@ -38,7 +38,7 @@ def get_video_chat_provider_detail(
def update_existing_video_chat_provider_values(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
Realm = apps.get_model("zerver", "Realm")
@ -49,7 +49,7 @@ def update_existing_video_chat_provider_values(
realm.save(update_fields=["video_chat_provider"])
def reverse_code(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def reverse_code(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
Realm = apps.get_model("zerver", "Realm")
for realm in Realm.objects.all():

View File

@ -1,12 +1,12 @@
# Generated by Django 1.11.20 on 2019-05-31 02:33
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def disable_realm_inline_url_embed_preview(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
Realm = apps.get_model("zerver", "Realm")
realms = Realm.objects.filter(inline_url_embed_preview=True)

View File

@ -3,13 +3,13 @@
from unicodedata import category
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
NAME_INVALID_CHARS = ["*", "`", "\\", ">", '"', "@"]
def remove_name_illegal_chars(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def remove_name_illegal_chars(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
UserProfile = apps.get_model("zerver", "UserProfile")
for user in UserProfile.objects.all():
stripped = []

View File

@ -1,11 +1,11 @@
from django.conf import settings
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def rename_zulip_realm_to_zulipinternal(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
if not settings.PRODUCTION:
return

View File

@ -3,7 +3,7 @@
import time
from django.db import connection, migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from django.db.models import Min
from psycopg2.sql import SQL
@ -29,7 +29,7 @@ def sql_copy_id_to_bigint_id(id_range_lower_bound: int, id_range_upper_bound: in
)
def copy_id_to_bigid(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def copy_id_to_bigid(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
UserMessage = apps.get_model("zerver", "UserMessage")
if not UserMessage.objects.exists():
# Nothing to do

View File

@ -1,11 +1,11 @@
# Generated by Django 1.11.24 on 2019-09-23 20:39
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def fix_bot_email_property(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def fix_bot_email_property(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
UserProfile = apps.get_model("zerver", "UserProfile")
for user_profile in UserProfile.objects.filter(is_bot=True):
if user_profile.email != user_profile.delivery_email:

View File

@ -2,7 +2,7 @@ import time
from django.contrib.postgres.operations import AddIndexConcurrently
from django.db import connection, migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from django.db.models import Min
from psycopg2.sql import SQL
@ -28,7 +28,7 @@ def sql_copy_pub_date_to_date_sent(id_range_lower_bound: int, id_range_upper_bou
)
def copy_pub_date_to_date_sent(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def copy_pub_date_to_date_sent(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
Message = apps.get_model("zerver", "Message")
if not Message.objects.exists():
# Nothing to do

View File

@ -1,7 +1,7 @@
# Generated by Django 1.11.24 on 2019-10-02 16:48
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
INT_VALUE = {
@ -67,14 +67,16 @@ STR_VALUE = {
}
def update_existing_event_type_values(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def update_existing_event_type_values(
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
RealmAuditLog = apps.get_model("zerver", "RealmAuditLog")
for log_entry in RealmAuditLog.objects.all():
log_entry.event_type_int = INT_VALUE[log_entry.event_type]
log_entry.save(update_fields=["event_type_int"])
def reverse_code(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def reverse_code(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
RealmAuditLog = apps.get_model("zerver", "RealmAuditLog")
for log_entry in RealmAuditLog.objects.all():
log_entry.event_type = STR_VALUE[log_entry.event_type_int]

View File

@ -1,10 +1,10 @@
# Generated by Django 1.11.24 on 2019-10-03 22:27
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def update_role(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def update_role(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
UserProfile = apps.get_model("zerver", "UserProfile")
# The values at the time of this migration
UserProfile.ROLE_REALM_ADMINISTRATOR = 200
@ -20,7 +20,7 @@ def update_role(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
user.save(update_fields=["role"])
def reverse_code(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def reverse_code(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
UserProfile = apps.get_model("zerver", "UserProfile")
UserProfile.ROLE_REALM_ADMINISTRATOR = 200
UserProfile.ROLE_GUEST = 600

View File

@ -5,7 +5,7 @@ from typing import cast
import lxml
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
BATCH_SIZE = 1000
@ -55,7 +55,7 @@ def process_batch(apps: StateApps, id_start: int, id_end: int, last_id: int) ->
message.save(update_fields=["has_link", "has_attachment", "has_image"])
def fix_has_link(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def fix_has_link(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
Message = apps.get_model("zerver", "Message")
if not Message.objects.exists():
# Nothing to do, and Message.objects.latest() will crash.

View File

@ -2,7 +2,7 @@ import secrets
from django.core.exceptions import ObjectDoesNotExist
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
# Imported to avoid needing to duplicate Redis-related code.
@ -14,7 +14,7 @@ def generate_missed_message_token() -> str:
def move_missed_message_addresses_to_database(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
redis_client = get_redis_client()
MissedMessageEmailAddress = apps.get_model("zerver", "MissedMessageEmailAddress")

View File

@ -1,12 +1,12 @@
# Generated by Django 1.11.26 on 2020-06-16 22:26
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def clear_preregistrationuser_invited_as_admin(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
"""This migration fixes any PreregistrationUser objects that might
have been already corrupted to have the administrator role by the

View File

@ -1,11 +1,11 @@
# Generated by Django 1.11.26 on 2020-01-25 23:47
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def upgrade_stream_post_policy(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def upgrade_stream_post_policy(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
Stream = apps.get_model("zerver", "Stream")
Stream.STREAM_POST_POLICY_EVERYONE = 1
Stream.STREAM_POST_POLICY_ADMINS = 2

View File

@ -2,11 +2,11 @@ from typing import Any
from django.conf import settings
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def fix_messages(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def fix_messages(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
"""Conceptually, this migration cleans up the old NEW_USER_BOT and FEEDBACK_BOT
UserProfile objects (their implementations were removed long ago).

View File

@ -2,11 +2,11 @@ from typing import Dict, List
import orjson
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def move_to_seperate_table(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def move_to_seperate_table(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
UserProfile = apps.get_model("zerver", "UserProfile")
AlertWord = apps.get_model("zerver", "AlertWord")
@ -24,7 +24,7 @@ def move_to_seperate_table(apps: StateApps, schema_editor: DatabaseSchemaEditor)
)
def move_back_to_user_profile(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def move_back_to_user_profile(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
AlertWord = apps.get_model("zerver", "AlertWord")
UserProfile = apps.get_model("zerver", "UserProfile")

View File

@ -3,13 +3,15 @@ from typing import Any, Dict
import orjson
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from django.db.models import Count
from django.utils.timezone import now as timezone_now
def set_realm_admins_as_realm_owners(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def set_realm_admins_as_realm_owners(
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
UserProfile = apps.get_model("zerver", "UserProfile")
RealmAuditLog = apps.get_model("zerver", "RealmAuditLog")

View File

@ -1,7 +1,7 @@
# Generated by Django 2.2.13 on 2020-06-14 01:58
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
VIDEO_CHAT_PROVIDERS = {
@ -16,7 +16,9 @@ VIDEO_CHAT_PROVIDERS = {
}
def remove_google_hangouts_provider(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def remove_google_hangouts_provider(
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
# We are removing the Google Hangout integration because Google has
# removed the Hangouts brand. All the realms that used Hangouts as
# their video chat provided are now set to the default, Jitsi.

View File

@ -1,10 +1,10 @@
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from django.db.models import Count
def clear_duplicate_reactions(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def clear_duplicate_reactions(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
"""Zulip's data model for reactions has enforced via code,
nontransactionally, that they can only react with one emoji_code
for a given reaction_type. This fixes any that were stored in the

View File

@ -1,14 +1,16 @@
# Generated by Django 2.2.13 on 2020-06-20 15:22
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
COLOR_SCHEME_AUTOMATIC = 1
COLOR_SCHEME_NIGHT = 2
# Set color_scheme to night mode, if night_mode is True.
def set_color_scheme_to_night_mode(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def set_color_scheme_to_night_mode(
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
UserProfile = apps.get_model("zerver", "UserProfile")
UserProfile.objects.filter(night_mode=True).update(color_scheme=COLOR_SCHEME_NIGHT)

View File

@ -1,11 +1,11 @@
# Generated by Django 2.2.13 on 2020-06-21 21:13
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def update_invite_as_dict_values(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def update_invite_as_dict_values(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
PreregistrationUser = apps.get_model("zerver", "PreregistrationUser")
MultiuseInvite = apps.get_model("zerver", "MultiuseInvite")

View File

@ -3,11 +3,11 @@
import json
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def update_realmauditlog_values(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def update_realmauditlog_values(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
"""
This migration fixes two issues with the RealmAuditLog format for certain event types:
* The notifications_stream and signup_notifications_stream fields had the

View File

@ -1,12 +1,12 @@
# Generated by Django 2.2.14 on 2020-08-10 20:21
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def remove_default_status_of_default_private_streams(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
DefaultStream = apps.get_model("zerver", "DefaultStream")
DefaultStream.objects.filter(stream__invite_only=True).delete()

View File

@ -2,11 +2,11 @@
from django.contrib.postgres.operations import AddIndexConcurrently
from django.db import connection, migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def backfill_is_user_active(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def backfill_is_user_active(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
Subscription = apps.get_model("zerver", "Subscription")
BATCH_SIZE = 1000
lower_id_bound = 0

View File

@ -1,11 +1,13 @@
# Generated by Django 3.1.7 on 2021-04-01 19:27
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def migrate_to_invite_to_realm_policy(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def migrate_to_invite_to_realm_policy(
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
Realm = apps.get_model("zerver", "Realm")
Realm.INVITE_TO_REALM_POLICY_MEMBERS_ONLY = 1
Realm.INVITE_TO_REALM_POLICY_ADMINS_ONLY = 2

View File

@ -1,12 +1,12 @@
# Generated by Django 3.1.8 on 2021-04-20 10:09
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def backfill_realm_creation_log_events(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
RealmAuditLog = apps.get_model("zerver", "RealmAuditLog")
RealmAuditLog.REALM_CREATED = 215
@ -25,7 +25,7 @@ def backfill_realm_creation_log_events(
RealmAuditLog.objects.bulk_create(objects_to_create)
def reverse_code(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def reverse_code(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
RealmAuditLog = apps.get_model("zerver", "RealmAuditLog")
RealmAuditLog.REALM_CREATED = 215
RealmAuditLog.objects.filter(event_type=RealmAuditLog.REALM_CREATED, backfilled=True).delete()

View File

@ -1,12 +1,14 @@
# Generated by Django 3.1.8 on 2021-05-01 12:34
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
# Set starred_message_count for already existing users to True.
def set_starred_message_count_to_true(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def set_starred_message_count_to_true(
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
UserProfile = apps.get_model("zerver", "UserProfile")
UserProfile.objects.filter(starred_message_counts=False).update(starred_message_counts=True)

View File

@ -1,11 +1,11 @@
# Generated by Django 3.2.2 on 2021-05-26 09:43
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def migrate_to_edit_topic_policy(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def migrate_to_edit_topic_policy(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
Realm = apps.get_model("zerver", "Realm")
Realm.POLICY_EVERYONE = 5
Realm.POLICY_ADMINS_ONLY = 2
@ -18,7 +18,7 @@ def migrate_to_edit_topic_policy(apps: StateApps, schema_editor: DatabaseSchemaE
def reverse_migrate_to_edit_topic_policy(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
Realm = apps.get_model("zerver", "Realm")
Realm.POLICY_EVERYONE = 5

View File

@ -1,11 +1,11 @@
# Generated by Django 3.2.4 on 2021-07-06 20:34
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def reset_realm_org_type(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def reset_realm_org_type(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
UNSPECIFIED = 0
Realm = apps.get_model("zerver", "Realm")
Realm.objects.all().update(org_type=UNSPECIFIED)

View File

@ -1,12 +1,12 @@
# Generated by Django 3.2.2 on 2021-05-15 18:01
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def migrate_to_add_custom_emoji_policy(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
Realm = apps.get_model("zerver", "Realm")
Realm.ADD_CUSTOM_EMOJI_MEMBERS_ONLY = 1
@ -20,7 +20,7 @@ def migrate_to_add_custom_emoji_policy(
def reverse_migrate_to_add_custom_emoji_policy(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
Realm = apps.get_model("zerver", "Realm")
Realm.ADD_CUSTOM_EMOJI_MEMBERS_ONLY = 1

View File

@ -2,11 +2,11 @@
from django.conf import settings
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def rename_system_bot_realm(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def rename_system_bot_realm(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
# Prior to this migration, the system bot realm had name incorrectly set to null.
Realm = apps.get_model("zerver", "Realm")
Realm.objects.filter(name=None, string_id=settings.SYSTEM_BOT_REALM).update(

View File

@ -1,11 +1,13 @@
# Generated by Django 3.2.2 on 2021-06-01 16:19
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def create_realm_user_default_table(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def create_realm_user_default_table(
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
Realm = apps.get_model("zerver", "Realm")
RealmUserDefault = apps.get_model("zerver", "RealmUserDefault")
realms = Realm.objects.all()

View File

@ -1,13 +1,13 @@
# Generated by Django 3.2.6 on 2021-09-17 17:08
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from django.db.models import F
def migrate_twenty_four_hour_time_to_realmuserdefault(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
RealmUserDefault = apps.get_model("zerver", "RealmUserDefault")
realm_user_default_objects = RealmUserDefault.objects.exclude(
@ -20,7 +20,7 @@ def migrate_twenty_four_hour_time_to_realmuserdefault(
def reverse_migrate_twenty_four_hour_time_to_realmuserdefault(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
RealmUserDefault = apps.get_model("zerver", "RealmUserDefault")
realm_user_default_objects = RealmUserDefault.objects.exclude(

View File

@ -1,12 +1,12 @@
# Generated by Django 3.2.4 on 2021-06-14 12:12
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def make_zero_invalid_for_message_delete_limit(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
Realm = apps.get_model("zerver", "Realm")
Realm.DEFAULT_MESSAGE_CONTENT_DELETE_LIMIT_SECONDS = 600
@ -23,7 +23,7 @@ def make_zero_invalid_for_message_delete_limit(
def reverse_make_zero_invalid_for_message_delete_limit(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
Realm = apps.get_model("zerver", "Realm")
Realm.DEFAULT_MESSAGE_CONTENT_DELETE_LIMIT_SECONDS = 600

View File

@ -1,12 +1,12 @@
# Generated by Django 3.2.4 on 2021-06-09 10:02
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def migrate_to_delete_own_message_policy(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
Realm = apps.get_model("zerver", "Realm")
Realm.POLICY_EVERYONE = 5

View File

@ -1,10 +1,10 @@
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from django.db.models import F
def copy_stream_policy_field(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def copy_stream_policy_field(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
Realm = apps.get_model("zerver", "Realm")
Realm.objects.all().update(create_public_stream_policy=F("create_stream_policy"))
Realm.objects.all().update(create_private_stream_policy=F("create_stream_policy"))
@ -15,7 +15,7 @@ def copy_stream_policy_field(apps: StateApps, schema_editor: DatabaseSchemaEdito
# but in most cases downgrades that would reverse migrations happen
# before any real usage, so it's very likely that both values are
# identical.
def reverse_code(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def reverse_code(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
Realm = apps.get_model("zerver", "Realm")
Realm.objects.all().update(create_stream_policy=F("create_public_stream_policy"))

View File

@ -1,10 +1,10 @@
import re2
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def delete_re2_invalid(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def delete_re2_invalid(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
options = re2.Options()
options.log_errors = False

View File

@ -1,7 +1,7 @@
import unicodedata
from django.db import connection, migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
# There are 66 Unicode non-characters; see
@ -18,7 +18,7 @@ def character_is_printable(character: str) -> bool:
return not (unicodedata.category(character) in ["Cc", "Cs"] or character in unicode_non_chars)
def fix_topics(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def fix_topics(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
Message = apps.get_model("zerver", "Message")
BATCH_SIZE = 10000
messages_updated = 0

View File

@ -4,7 +4,7 @@ from django.conf import settings
from django.core.exceptions import ValidationError
from django.core.validators import validate_email
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
@ -40,7 +40,7 @@ def get_fake_email_domain(realm: Any) -> str:
return settings.FAKE_EMAIL_DOMAIN
def fix_dummy_users(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def fix_dummy_users(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
"""
do_delete_users had two bugs:
1. Creating the replacement dummy users with active=True

View File

@ -1,9 +1,9 @@
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def backfill_user_deleted_logs(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def backfill_user_deleted_logs(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
RealmAuditLog = apps.get_model("zerver", "RealmAuditLog")
RealmAuditLog.USER_DELETED = 106
@ -26,7 +26,7 @@ def backfill_user_deleted_logs(apps: StateApps, schema_editor: DatabaseSchemaEdi
RealmAuditLog.objects.bulk_create(objects_to_create)
def reverse_code(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def reverse_code(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
RealmAuditLog = apps.get_model("zerver", "RealmAuditLog")
RealmAuditLog.USER_DELETED = 106

View File

@ -1,7 +1,7 @@
import unicodedata
from django.db import connection, migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
# There are 66 Unicode non-characters; see
@ -18,7 +18,7 @@ def character_is_printable(character: str) -> bool:
return not (unicodedata.category(character) in ["Cc", "Cs"] or character in unicode_non_chars)
def fix_stream_names(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def fix_stream_names(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
Stream = apps.get_model("zerver", "Stream")
Realm = apps.get_model("zerver", "Realm")

View File

@ -1,9 +1,9 @@
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def set_emoji_author(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def set_emoji_author(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
"""
This migration establishes the invariant that all RealmEmoji objects have .author set
and queues events for reuploading all RealmEmoji.

View File

@ -3,7 +3,7 @@ from typing import List, Optional, TypedDict
import orjson
from django.db import migrations, transaction
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from django.db.models import Min, Model
@ -116,7 +116,7 @@ def backfill_message_edit_history_chunk(first_id: int, last_id: int, message_mod
def copy_and_update_message_edit_history(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
Message = apps.get_model("zerver", "Message")
ArchivedMessage = apps.get_model("zerver", "ArchivedMessage")

View File

@ -1,11 +1,11 @@
import uuid
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def backfill_user_profile_uuid(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def backfill_user_profile_uuid(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
UserProfile = apps.get_model("zerver", "UserProfile")
max_id = UserProfile.objects.aggregate(models.Max("id"))["id__max"]

View File

@ -1,12 +1,14 @@
# Generated by Django 3.2.7 on 2021-10-16 12:41
from django.db import migrations, transaction
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from django.utils.timezone import now as timezone_now
def create_role_based_system_groups(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def create_role_based_system_groups(
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
Realm = apps.get_model("zerver", "Realm")
UserProfile = apps.get_model("zerver", "UserProfile")
UserGroup = apps.get_model("zerver", "UserGroup")
@ -118,7 +120,9 @@ def create_role_based_system_groups(apps: StateApps, schema_editor: DatabaseSche
UserGroupMembership.objects.bulk_create(group_membership_objects)
def delete_role_based_system_groups(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def delete_role_based_system_groups(
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
UserGroup = apps.get_model("zerver", "UserGroup")
GroupGroupMembership = apps.get_model("zerver", "GroupGroupMembership")
UserGroupMembership = apps.get_model("zerver", "UserGroupMembership")

View File

@ -1,12 +1,12 @@
from typing import List
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from django.utils.timezone import now as timezone_now
def revoke_invitations(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def revoke_invitations(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
Realm = apps.get_model("zerver", "Realm")
Confirmation = apps.get_model("confirmation", "Confirmation")
Confirmation.INVITATION = 2

View File

@ -1,12 +1,12 @@
# Generated by Django 3.2.12 on 2022-03-23 04:32
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from django.db.models import Exists, Model, OuterRef
def fix_attachment_caches(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def fix_attachment_caches(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
Attachment = apps.get_model("zerver", "Attachment")
ArchivedAttachment = apps.get_model("zerver", "ArchivedAttachment")
Message = apps.get_model("zerver", "Message")

View File

@ -1,12 +1,12 @@
from django.conf import settings
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from zerver.lib.queue import queue_json_publish
def reupload_realm_emoji(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
def reupload_realm_emoji(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
"""As detailed in https://github.com/zulip/zulip/issues/21608, it is
possible for the deferred_work queue from Zulip 4.x to have been
started up by puppet during the deployment before migrations were

View File

@ -1,10 +1,10 @@
from django.db import migrations
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def fix_stream_history_public_to_subscribers(
apps: StateApps, schema_editor: DatabaseSchemaEditor
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
Stream = apps.get_model("zerver", "Stream")
Stream.objects.filter(

Some files were not shown because too many files have changed in this diff Show More