# Generated by Django 5.0.7 on 2024-08-17 01:15

import datetime
import logging
import uuid
from enum import IntEnum

import bitfield.models
import django.contrib.auth.models
import django.contrib.postgres.indexes
import django.contrib.postgres.search
import django.core.serializers.json
import django.core.validators
import django.db.models.deletion
import django.db.models.functions.text
import django.utils.timezone
from django.conf import settings
from django.db import connection, migrations, models, transaction
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from django.db.utils import InternalError

import zerver.lib.utils
import zerver.models.linkifiers
import zerver.models.realms
import zerver.models.streams


class LegacyBotCreationPolicyEnum(IntEnum):
    EVERYONE = 1
    LIMIT_GENERIC_BOTS = 2
    ADMINS_ONLY = 3


class LegacyCommonMessagePolicyEnum(IntEnum):
    MEMBERS_ONLY = 1
    ADMINS_ONLY = 2
    FULL_MEMBERS_ONLY = 3
    MODERATORS_ONLY = 4
    EVERYONE = 5


class LegacyEditTopicPolicyEnum(IntEnum):
    MEMBERS_ONLY = 1
    ADMINS_ONLY = 2
    FULL_MEMBERS_ONLY = 3
    MODERATORS_ONLY = 4
    EVERYONE = 5
    NOBODY = 6


class LegacyInviteToRealmPolicyEnum(IntEnum):
    MEMBERS_ONLY = 1
    ADMINS_ONLY = 2
    FULL_MEMBERS_ONLY = 3
    MODERATORS_ONLY = 4
    NOBODY = 6


def set_up_fts_indexes(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
    # Duplicated in 0001_initial.py
    with connection.cursor() as cursor:
        try:
            with transaction.atomic(savepoint=True):
                cursor.execute(
                    """
                    CREATE TEXT SEARCH DICTIONARY english_us_hunspell
                      (template = ispell, DictFile = en_us, AffFile = en_us, StopWords = zulip_english);
                    CREATE TEXT SEARCH CONFIGURATION zulip.english_us_search (COPY=pg_catalog.english);
                    ALTER TEXT SEARCH CONFIGURATION zulip.english_us_search
                      ALTER MAPPING FOR asciiword, asciihword, hword_asciipart, word, hword, hword_part
                      WITH english_us_hunspell, english_stem;
                    """
                )
        except InternalError as e:
            # If we have a remote PostgreSQL server, and we get an
            # error about the tsearch_data paths, assume that we're
            # running with a hosted PostgreSQL which we can't install
            # our stemming/stopword dictionaries in; warn and carry
            # on.  For local PostgreSQL hosts, this is unexpected and
            # we raise the error.
            if (
                settings.REMOTE_POSTGRES_HOST != ""
                and e.__cause__
                and "/tsearch_data/" in str(e.__cause__)
            ):
                logging.warning(
                    "Remote PostgreSQL server %s is not configured with Zulip's improved stemming dictionaries; search quality will be degraded.",
                    settings.REMOTE_POSTGRES_HOST,
                )
                cursor.execute(
                    """
                    CREATE TEXT SEARCH CONFIGURATION zulip.english_us_search (COPY=pg_catalog.english);
                    """
                )
            else:
                raise
        cursor.execute(
            """
            CREATE FUNCTION escape_html(text) RETURNS text IMMUTABLE LANGUAGE 'sql' AS $$
              SELECT replace(replace(replace(replace(replace($1, '&', '&amp;'), '<', '&lt;'),
                                             '>', '&gt;'), '"', '&quot;'), '''', '&#39;');
            $$ ;

            CREATE TABLE fts_update_log (id SERIAL PRIMARY KEY, message_id INTEGER NOT NULL);
            CREATE FUNCTION do_notify_fts_update_log() RETURNS trigger LANGUAGE plpgsql AS
              $$ BEGIN NOTIFY fts_update_log; RETURN NEW; END $$;
            CREATE TRIGGER fts_update_log_notify AFTER INSERT ON fts_update_log
              FOR EACH STATEMENT EXECUTE PROCEDURE do_notify_fts_update_log();
            CREATE FUNCTION append_to_fts_update_log() RETURNS trigger LANGUAGE plpgsql AS
              $$ BEGIN INSERT INTO fts_update_log (message_id) VALUES (NEW.id); RETURN NEW; END $$;
            CREATE TRIGGER zerver_message_update_search_tsvector_async
              BEFORE INSERT OR UPDATE OF subject, rendered_content ON zerver_message
              FOR EACH ROW EXECUTE PROCEDURE append_to_fts_update_log();
            """
        )


class Migration(migrations.Migration):
    initial = True

    replaces = [
        ("zerver", "0001_initial"),
        ("zerver", "0029_realm_subdomain"),
        ("zerver", "0030_realm_org_type"),
        ("zerver", "0031_remove_system_avatar_source"),
        ("zerver", "0032_verify_all_medium_avatar_images"),
        ("zerver", "0033_migrate_domain_to_realmalias"),
        ("zerver", "0034_userprofile_enable_online_push_notifications"),
        ("zerver", "0035_realm_message_retention_period_days"),
        ("zerver", "0036_rename_subdomain_to_string_id"),
        ("zerver", "0037_disallow_null_string_id"),
        ("zerver", "0038_realm_change_to_community_defaults"),
        ("zerver", "0039_realmalias_drop_uniqueness"),
        ("zerver", "0040_realm_authentication_methods"),
        ("zerver", "0041_create_attachments_for_old_messages"),
        ("zerver", "0042_attachment_file_name_length"),
        ("zerver", "0043_realm_filter_validators"),
        ("zerver", "0044_reaction"),
        ("zerver", "0045_realm_waiting_period_threshold"),
        ("zerver", "0046_realmemoji_author"),
        ("zerver", "0047_realm_add_emoji_by_admins_only"),
        ("zerver", "0048_enter_sends_default_to_false"),
        ("zerver", "0049_userprofile_pm_content_in_desktop_notifications"),
        ("zerver", "0050_userprofile_avatar_version"),
        ("zerver", "0051_realmalias_add_allow_subdomains"),
        ("zerver", "0052_auto_fix_realmalias_realm_nullable"),
        ("zerver", "0053_emailchangestatus"),
        ("zerver", "0054_realm_icon"),
        ("zerver", "0055_attachment_size"),
        ("zerver", "0056_userprofile_emoji_alt_code"),
        ("zerver", "0057_realmauditlog"),
        ("zerver", "0058_realm_email_changes_disabled"),
        ("zerver", "0059_userprofile_quota"),
        ("zerver", "0060_move_avatars_to_be_uid_based"),
        ("zerver", "0061_userprofile_timezone"),
        ("zerver", "0062_default_timezone"),
        ("zerver", "0063_realm_description"),
        ("zerver", "0064_sync_uploads_filesize_with_db"),
        ("zerver", "0065_realm_inline_image_preview"),
        ("zerver", "0066_realm_inline_url_embed_preview"),
        ("zerver", "0067_archived_models"),
        ("zerver", "0068_remove_realm_domain"),
        ("zerver", "0069_realmauditlog_extra_data"),
        ("zerver", "0070_userhotspot"),
        ("zerver", "0071_rename_realmalias_to_realmdomain"),
        ("zerver", "0072_realmauditlog_add_index_event_time"),
        ("zerver", "0073_custom_profile_fields"),
        ("zerver", "0074_fix_duplicate_attachments"),
        ("zerver", "0075_attachment_path_id_unique"),
        ("zerver", "0076_userprofile_emojiset"),
        ("zerver", "0077_add_file_name_field_to_realm_emoji"),
        ("zerver", "0078_service"),
        ("zerver", "0079_remove_old_scheduled_jobs"),
        ("zerver", "0080_realm_description_length"),
        ("zerver", "0081_make_emoji_lowercase"),
        ("zerver", "0082_index_starred_user_messages"),
        ("zerver", "0083_index_mentioned_user_messages"),
        ("zerver", "0084_realmemoji_deactivated"),
        ("zerver", "0085_fix_bots_with_none_bot_type"),
        ("zerver", "0086_realm_alter_default_org_type"),
        ("zerver", "0087_remove_old_scheduled_jobs"),
        ("zerver", "0088_remove_referral_and_invites"),
        ("zerver", "0089_auto_20170710_1353"),
        ("zerver", "0090_userprofile_high_contrast_mode"),
        ("zerver", "0091_realm_allow_edit_history"),
        ("zerver", "0092_create_scheduledemail"),
        ("zerver", "0093_subscription_event_log_backfill"),
        ("zerver", "0094_realm_filter_url_validator"),
        ("zerver", "0095_index_unread_user_messages"),
        ("zerver", "0096_add_password_required"),
        ("zerver", "0097_reactions_emoji_code"),
        ("zerver", "0098_index_has_alert_word_user_messages"),
        ("zerver", "0099_index_wildcard_mentioned_user_messages"),
        ("zerver", "0100_usermessage_remove_is_me_message"),
        ("zerver", "0101_muted_topic"),
        ("zerver", "0102_convert_muted_topic"),
        ("zerver", "0103_remove_userprofile_muted_topics"),
        ("zerver", "0104_fix_unreads"),
        ("zerver", "0105_userprofile_enable_stream_push_notifications"),
        ("zerver", "0106_subscription_push_notifications"),
        ("zerver", "0107_multiuseinvite"),
        ("zerver", "0108_fix_default_string_id"),
        ("zerver", "0109_mark_tutorial_status_finished"),
        ("zerver", "0110_stream_is_in_zephyr_realm"),
        ("zerver", "0111_botuserstatedata"),
        ("zerver", "0112_index_muted_topics"),
        ("zerver", "0113_default_stream_group"),
        ("zerver", "0114_preregistrationuser_invited_as_admin"),
        ("zerver", "0115_user_groups"),
        ("zerver", "0116_realm_allow_message_deleting"),
        ("zerver", "0117_add_desc_to_user_group"),
        ("zerver", "0118_defaultstreamgroup_description"),
        ("zerver", "0119_userprofile_night_mode"),
        ("zerver", "0120_botuserconfigdata"),
        ("zerver", "0121_realm_signup_notifications_stream"),
        ("zerver", "0122_rename_botuserstatedata_botstoragedata"),
        ("zerver", "0123_userprofile_make_realm_email_pair_unique"),
        ("zerver", "0124_stream_enable_notifications"),
        ("zerver", "0125_realm_max_invites"),
        ("zerver", "0126_prereg_remove_users_without_realm"),
        ("zerver", "0127_disallow_chars_in_stream_and_user_name"),
        ("zerver", "0128_scheduledemail_realm"),
        ("zerver", "0129_remove_userprofile_autoscroll_forever"),
        ("zerver", "0130_text_choice_in_emojiset"),
        ("zerver", "0131_realm_create_generic_bot_by_admins_only"),
        ("zerver", "0132_realm_message_visibility_limit"),
        ("zerver", "0133_rename_botuserconfigdata_botconfigdata"),
        ("zerver", "0134_scheduledmessage"),
        ("zerver", "0135_scheduledmessage_delivery_type"),
        ("zerver", "0136_remove_userprofile_quota"),
        ("zerver", "0137_realm_upload_quota_gb"),
        ("zerver", "0138_userprofile_realm_name_in_notifications"),
        ("zerver", "0139_fill_last_message_id_in_subscription_logs"),
        ("zerver", "0140_realm_send_welcome_emails"),
        ("zerver", "0141_change_usergroup_description_to_textfield"),
        ("zerver", "0142_userprofile_translate_emoticons"),
        ("zerver", "0143_realm_bot_creation_policy"),
        ("zerver", "0144_remove_realm_create_generic_bot_by_admins_only"),
        ("zerver", "0145_reactions_realm_emoji_name_to_id"),
        ("zerver", "0146_userprofile_message_content_in_email_notifications"),
        ("zerver", "0147_realm_disallow_disposable_email_addresses"),
        ("zerver", "0148_max_invites_forget_default"),
        ("zerver", "0149_realm_emoji_drop_unique_constraint"),
        ("zerver", "0150_realm_allow_community_topic_editing"),
        ("zerver", "0151_last_reminder_default_none"),
        ("zerver", "0152_realm_default_twenty_four_hour_time"),
        ("zerver", "0153_remove_int_float_custom_fields"),
        ("zerver", "0154_fix_invalid_bot_owner"),
        ("zerver", "0155_change_default_realm_description"),
        ("zerver", "0156_add_hint_to_profile_field"),
        ("zerver", "0157_userprofile_is_guest"),
        ("zerver", "0158_realm_video_chat_provider"),
        ("zerver", "0159_realm_google_hangouts_domain"),
        ("zerver", "0160_add_choice_field"),
        ("zerver", "0161_realm_message_content_delete_limit_seconds"),
        ("zerver", "0162_change_default_community_topic_editing"),
        ("zerver", "0163_remove_userprofile_default_desktop_notifications"),
        ("zerver", "0164_stream_history_public_to_subscribers"),
        ("zerver", "0165_add_date_to_profile_field"),
        ("zerver", "0166_add_url_to_profile_field"),
        ("zerver", "0167_custom_profile_fields_sort_order"),
        ("zerver", "0168_stream_is_web_public"),
        ("zerver", "0169_stream_is_announcement_only"),
        ("zerver", "0170_submessage"),
        ("zerver", "0171_userprofile_dense_mode"),
        ("zerver", "0172_add_user_type_of_custom_profile_field"),
        ("zerver", "0173_support_seat_based_plans"),
        ("zerver", "0174_userprofile_delivery_email"),
        ("zerver", "0175_change_realm_audit_log_event_type_tense"),
        ("zerver", "0176_remove_subscription_notifications"),
        ("zerver", "0177_user_message_add_and_index_is_private_flag"),
        ("zerver", "0178_rename_to_emails_restricted_to_domains"),
        ("zerver", "0179_rename_to_digest_emails_enabled"),
        ("zerver", "0180_usermessage_add_active_mobile_push_notification"),
        ("zerver", "0181_userprofile_change_emojiset"),
        ("zerver", "0182_set_initial_value_is_private_flag"),
        ("zerver", "0183_change_custom_field_name_max_length"),
        ("zerver", "0184_rename_custom_field_types"),
        ("zerver", "0185_realm_plan_type"),
        ("zerver", "0186_userprofile_starred_message_counts"),
        ("zerver", "0187_userprofile_is_billing_admin"),
        ("zerver", "0188_userprofile_enable_login_emails"),
        ("zerver", "0189_userprofile_add_some_emojisets"),
        ("zerver", "0190_cleanup_pushdevicetoken"),
        ("zerver", "0191_realm_seat_limit"),
        ("zerver", "0192_customprofilefieldvalue_rendered_value"),
        ("zerver", "0193_realm_email_address_visibility"),
        ("zerver", "0194_userprofile_notification_sound"),
        ("zerver", "0195_realm_first_visible_message_id"),
        ("zerver", "0196_add_realm_logo_fields"),
        ("zerver", "0197_azure_active_directory_auth"),
        ("zerver", "0198_preregistrationuser_invited_as"),
        ("zerver", "0199_userstatus"),
        ("zerver", "0200_remove_preregistrationuser_invited_as_admin"),
        ("zerver", "0201_zoom_video_chat"),
        ("zerver", "0202_add_user_status_info"),
        ("zerver", "0203_realm_message_content_allowed_in_email_notifications"),
        ("zerver", "0204_remove_realm_billing_fields"),
        ("zerver", "0205_remove_realmauditlog_requires_billing_update"),
        ("zerver", "0206_stream_rendered_description"),
        ("zerver", "0207_multiuseinvite_invited_as"),
        ("zerver", "0208_add_realm_night_logo_fields"),
        ("zerver", "0209_stream_first_message_id"),
        ("zerver", "0210_stream_first_message_id"),
        ("zerver", "0211_add_users_field_to_scheduled_email"),
        ("zerver", "0212_make_stream_email_token_unique"),
        ("zerver", "0213_realm_digest_weekday"),
        ("zerver", "0214_realm_invite_to_stream_policy"),
        ("zerver", "0215_realm_avatar_changes_disabled"),
        ("zerver", "0216_add_create_stream_policy"),
        ("zerver", "0217_migrate_create_stream_policy"),
        ("zerver", "0218_remove_create_stream_by_admins_only"),
        ("zerver", "0219_toggle_realm_digest_emails_enabled_default"),
        ("zerver", "0220_subscription_notification_settings"),
        ("zerver", "0221_subscription_notifications_data_migration"),
        ("zerver", "0222_userprofile_fluid_layout_width"),
        ("zerver", "0223_rename_to_is_muted"),
        ("zerver", "0224_alter_field_realm_video_chat_provider"),
        ("zerver", "0225_archived_reaction_model"),
        ("zerver", "0226_archived_submessage_model"),
        ("zerver", "0227_inline_url_embed_preview_default_off"),
        ("zerver", "0228_userprofile_demote_inactive_streams"),
        ("zerver", "0229_stream_message_retention_days"),
        ("zerver", "0230_rename_to_enable_stream_audible_notifications"),
        ("zerver", "0231_add_archive_transaction_model"),
        ("zerver", "0232_make_archive_transaction_field_not_nullable"),
        ("zerver", "0233_userprofile_avatar_hash"),
        ("zerver", "0234_add_external_account_custom_profile_field"),
        ("zerver", "0235_userprofile_desktop_icon_count_display"),
        ("zerver", "0236_remove_illegal_characters_email_full"),
        ("zerver", "0237_rename_zulip_realm_to_zulipinternal"),
        ("zerver", "0238_usermessage_bigint_id"),
        ("zerver", "0239_usermessage_copy_id_to_bigint_id"),
        ("zerver", "0240_usermessage_migrate_bigint_id_into_id"),
        ("zerver", "0241_usermessage_bigint_id_migration_finalize"),
        ("zerver", "0242_fix_bot_email_property"),
        ("zerver", "0243_message_add_date_sent_column"),
        ("zerver", "0244_message_copy_pub_date_to_date_sent"),
        ("zerver", "0245_message_date_sent_finalize_part1"),
        ("zerver", "0246_message_date_sent_finalize_part2"),
        ("zerver", "0247_realmauditlog_event_type_to_int"),
        ("zerver", "0248_userprofile_role_start"),
        ("zerver", "0249_userprofile_role_finish"),
        ("zerver", "0250_saml_auth"),
        ("zerver", "0251_prereg_user_add_full_name"),
        ("zerver", "0252_realm_user_group_edit_policy"),
        ("zerver", "0253_userprofile_wildcard_mentions_notify"),
        ("zerver", "0209_user_profile_no_empty_password"),
        ("zerver", "0254_merge_0209_0253"),
        ("zerver", "0255_userprofile_stream_add_recipient_column"),
        ("zerver", "0256_userprofile_stream_set_recipient_column_values"),
        ("zerver", "0257_fix_has_link_attribute"),
        ("zerver", "0258_enable_online_push_notifications_default"),
        ("zerver", "0259_missedmessageemailaddress"),
        ("zerver", "0260_missed_message_addresses_from_redis_to_db"),
        ("zerver", "0261_realm_private_message_policy"),
        ("zerver", "0262_mutedtopic_date_muted"),
        ("zerver", "0263_stream_stream_post_policy"),
        ("zerver", "0264_migrate_is_announcement_only"),
        ("zerver", "0265_remove_stream_is_announcement_only"),
        ("zerver", "0266_userpresence_realm"),
        ("zerver", "0267_backfill_userpresence_realm_id"),
        ("zerver", "0268_add_userpresence_realm_timestamp_index"),
        ("zerver", "0269_gitlab_auth"),
        ("zerver", "0270_huddle_recipient"),
        ("zerver", "0271_huddle_set_recipient_column_values"),
        ("zerver", "0272_realm_default_code_block_language"),
        ("zerver", "0273_migrate_old_bot_messages"),
        ("zerver", "0274_nullbooleanfield_to_booleanfield"),
        ("zerver", "0275_remove_userprofile_last_pointer_updater"),
        ("zerver", "0276_alertword"),
        ("zerver", "0277_migrate_alert_word"),
        ("zerver", "0278_remove_userprofile_alert_words"),
        ("zerver", "0279_message_recipient_subject_indexes"),
        ("zerver", "0280_userprofile_presence_enabled"),
        ("zerver", "0281_zoom_oauth"),
        ("zerver", "0282_remove_zoom_video_chat"),
        ("zerver", "0283_apple_auth"),
        ("zerver", "0284_convert_realm_admins_to_realm_owners"),
        ("zerver", "0285_remove_realm_google_hangouts_domain"),
        ("zerver", "0261_pregistrationuser_clear_invited_as_admin"),
        ("zerver", "0286_merge_0260_0285"),
        ("zerver", "0287_clear_duplicate_reactions"),
        ("zerver", "0288_reaction_unique_on_emoji_code"),
        ("zerver", "0289_tighten_attachment_size"),
        ("zerver", "0290_remove_night_mode_add_color_scheme"),
        ("zerver", "0291_realm_retention_days_not_null"),
        ("zerver", "0292_update_default_value_of_invited_as"),
        ("zerver", "0293_update_invite_as_dict_values"),
        ("zerver", "0294_remove_userprofile_pointer"),
        ("zerver", "0295_case_insensitive_email_indexes"),
        ("zerver", "0296_remove_userprofile_short_name"),
        ("zerver", "0297_draft"),
        ("zerver", "0298_fix_realmauditlog_format"),
        ("zerver", "0299_subscription_role"),
        ("zerver", "0300_add_attachment_is_web_public"),
        ("zerver", "0301_fix_unread_messages_in_deactivated_streams"),
        ("zerver", "0302_case_insensitive_stream_name_index"),
        ("zerver", "0303_realm_wildcard_mention_policy"),
        ("zerver", "0304_remove_default_status_of_default_private_streams"),
        ("zerver", "0305_realm_deactivated_redirect"),
        ("zerver", "0306_custom_profile_field_date_format"),
        ("zerver", "0307_rename_api_super_user_to_can_forge_sender"),
        ("zerver", "0308_remove_reduntant_realm_meta_permissions"),
        ("zerver", "0309_userprofile_can_create_users"),
        ("zerver", "0310_jsonfield"),
        ("zerver", "0311_userprofile_default_view"),
        ("zerver", "0312_subscription_is_user_active"),
        ("zerver", "0313_finish_is_user_active_migration"),
        ("zerver", "0314_muted_user"),
        ("zerver", "0315_realmplayground"),
        ("zerver", "0316_realm_invite_to_realm_policy"),
        ("zerver", "0317_migrate_to_invite_to_realm_policy"),
        ("zerver", "0318_remove_realm_invite_by_admins_only"),
        ("zerver", "0319_realm_giphy_rating"),
        ("zerver", "0320_realm_move_messages_between_streams_policy"),
        ("zerver", "0321_userprofile_enable_marketing_emails"),
        ("zerver", "0322_realm_create_audit_log_backfill"),
        ("zerver", "0323_show_starred_message_counts"),
        ("zerver", "0324_fix_deletion_cascade_behavior"),
        ("zerver", "0325_alter_realmplayground_unique_together"),
        ("zerver", "0359_re2_linkifiers"),
        ("zerver", "0326_alter_realm_authentication_methods"),
        ("zerver", "0327_realm_edit_topic_policy"),
        ("zerver", "0328_migrate_to_edit_topic_policy"),
        ("zerver", "0329_remove_realm_allow_community_topic_editing"),
        ("zerver", "0330_linkifier_pattern_validator"),
        ("zerver", "0331_scheduledmessagenotificationemail"),
        ("zerver", "0332_realmuserdefault"),
        ("zerver", "0333_alter_realm_org_type"),
        ("zerver", "0334_email_notifications_batching_period"),
        ("zerver", "0335_add_draft_sync_field"),
        ("zerver", "0336_userstatus_status_emoji"),
        ("zerver", "0337_realm_add_custom_emoji_policy"),
        ("zerver", "0338_migrate_to_add_custom_emoji_policy"),
        ("zerver", "0339_remove_realm_add_emoji_by_admins_only"),
        ("zerver", "0340_rename_mutedtopic_to_usertopic"),
        ("zerver", "0341_usergroup_is_system_group"),
        ("zerver", "0342_realm_demo_organization_scheduled_deletion_date"),
        ("zerver", "0343_alter_useractivityinterval_index_together"),
        ("zerver", "0344_alter_emojiset_default_value"),
        ("zerver", "0345_alter_realm_name"),
        ("zerver", "0346_create_realm_user_default_table"),
        ("zerver", "0347_realm_emoji_animated"),
        ("zerver", "0348_rename_date_muted_usertopic_last_updated"),
        ("zerver", "0349_alter_usertopic_table"),
        ("zerver", "0350_usertopic_visibility_policy"),
        ("zerver", "0351_user_topic_visibility_indexes"),
        ("zerver", "0352_migrate_twenty_four_hour_time_to_realmuserdefault"),
        ("zerver", "0353_remove_realm_default_twenty_four_hour_time"),
        ("zerver", "0354_alter_realm_message_content_delete_limit_seconds"),
        ("zerver", "0355_realm_delete_own_message_policy"),
        ("zerver", "0356_migrate_to_delete_own_message_policy"),
        ("zerver", "0357_remove_realm_allow_message_deleting"),
        ("zerver", "0358_split_create_stream_policy"),
        ("zerver", "0360_merge_0358_0359"),
        ("zerver", "0361_realm_create_web_public_stream_policy"),
        ("zerver", "0362_send_typing_notifications_user_setting"),
        ("zerver", "0363_send_read_receipts_user_setting"),
        ("zerver", "0364_rename_members_usergroup_direct_members"),
        ("zerver", "0365_alter_user_group_related_fields"),
        ("zerver", "0366_group_group_membership"),
        ("zerver", "0367_scimclient"),
        ("zerver", "0368_alter_realmfilter_url_format_string"),
        ("zerver", "0369_add_escnav_default_display_user_setting"),
        ("zerver", "0370_realm_enable_spectator_access"),
        ("zerver", "0371_invalid_characters_in_topics"),
        ("zerver", "0372_realmemoji_unique_realm_emoji_when_false_deactivated"),
        ("zerver", "0373_fix_deleteduser_dummies"),
        ("zerver", "0374_backfill_user_delete_realmauditlog"),
        ("zerver", "0375_invalid_characters_in_stream_names"),
        ("zerver", "0376_set_realmemoji_author_and_reupload_realmemoji"),
        ("zerver", "0377_message_edit_history_format"),
        ("zerver", "0378_alter_realmuserdefault_realm"),
        ("zerver", "0379_userprofile_uuid"),
        ("zerver", "0380_userprofile_uuid_backfill"),
        ("zerver", "0381_alter_userprofile_uuid"),
        ("zerver", "0382_create_role_based_system_groups"),
        ("zerver", "0383_revoke_invitations_from_deactivated_users"),
        ("zerver", "0384_alter_realm_not_null"),
        ("zerver", "0385_attachment_flags_cache"),
        ("zerver", "0386_fix_attachment_caches"),
        ("zerver", "0387_reupload_realmemoji_again"),
        ("zerver", "0388_preregistrationuser_created_user"),
        ("zerver", "0389_userprofile_display_emoji_reaction_users"),
        ("zerver", "0390_fix_stream_history_public_to_subscribers"),
        ("zerver", "0391_alter_stream_history_public_to_subscribers"),
        ("zerver", "0392_non_nullable_fields"),
        ("zerver", "0393_realm_want_advertise_in_communities_directory"),
        ("zerver", "0394_alter_realm_want_advertise_in_communities_directory"),
        ("zerver", "0395_alter_realm_wildcard_mention_policy"),
        ("zerver", "0396_remove_subscription_role"),
        ("zerver", "0397_remove_custom_field_values_for_deleted_options"),
        ("zerver", "0398_tsvector_statistics"),
        ("zerver", "0399_preregistrationuser_multiuse_invite"),
        ("zerver", "0400_realmreactivationstatus"),
        ("zerver", "0401_migrate_old_realm_reactivation_links"),
        ("zerver", "0402_alter_usertopic_visibility_policy"),
        ("zerver", "0403_create_role_based_groups_for_internal_realms"),
        ("zerver", "0404_realm_enable_read_receipts"),
        ("zerver", "0405_set_default_for_enable_read_receipts"),
        ("zerver", "0406_alter_realm_message_content_edit_limit_seconds"),
        ("zerver", "0407_userprofile_user_list_style"),
        ("zerver", "0408_stream_can_remove_subscribers_group"),
        ("zerver", "0409_set_default_for_can_remove_subscribers_group"),
        ("zerver", "0410_alter_stream_can_remove_subscribers_group"),
        ("zerver", "0411_alter_muteduser_muted_user_and_more"),
        ("zerver", "0412_customprofilefield_display_in_profile_summary"),
        ("zerver", "0413_set_presence_enabled_false_for_user_status_away"),
        ("zerver", "0414_remove_userstatus_status"),
        ("zerver", "0415_delete_scimclient"),
        ("zerver", "0416_set_default_emoji_style"),
        ("zerver", "0417_alter_customprofilefield_field_type"),
        ("zerver", "0418_archivedmessage_realm_message_realm"),
        ("zerver", "0419_backfill_message_realm"),
        ("zerver", "0420_alter_archivedmessage_realm_alter_message_realm"),
        ("zerver", "0421_migrate_pronouns_custom_profile_fields"),
        ("zerver", "0422_multiuseinvite_status"),
        ("zerver", "0423_fix_email_gateway_attachment_owner"),
        ("zerver", "0424_realm_move_messages_within_stream_limit_seconds"),
        ("zerver", "0425_realm_move_messages_between_streams_limit_seconds"),
        ("zerver", "0426_add_email_address_visibility_setting"),
        ("zerver", "0427_migrate_to_user_level_email_address_visibility_setting"),
        ("zerver", "0428_remove_realm_email_address_visibility"),
        ("zerver", "0429_user_topic_case_insensitive_unique_toghether"),
        ("zerver", "0430_fix_audit_log_objects_for_group_based_stream_settings"),
        ("zerver", "0431_alter_archivedreaction_unique_together_and_more"),
        ("zerver", "0432_alter_and_migrate_realm_name_in_notifications"),
        ("zerver", "0433_preregistrationrealm"),
        ("zerver", "0434_create_nobody_system_group"),
        ("zerver", "0435_scheduledmessage_rendered_content"),
        ("zerver", "0436_realmauthenticationmethods"),
        ("zerver", "0437_remove_realm_authentication_methods"),
        ("zerver", "0438_add_web_mark_read_on_scroll_policy_setting"),
        ("zerver", "0439_fix_deleteduser_email"),
        ("zerver", "0440_realmfilter_url_template"),
        ("zerver", "0441_backfill_realmfilter_url_template"),
        ("zerver", "0442_remove_realmfilter_url_format_string"),
        ("zerver", "0443_userpresence_new_table_schema"),
        ("zerver", "0444_userpresence_fill_data"),
        ("zerver", "0445_drop_userpresenceold"),
        ("zerver", "0446_realmauditlog_zerver_realmauditlog_user_subscriptions_idx"),
        ("zerver", "0447_attachment_scheduled_messages_and_more"),
        ("zerver", "0448_scheduledmessage_new_fields"),
        ("zerver", "0449_scheduledmessage_zerver_unsent_scheduled_messages_indexes"),
        ("zerver", "0450_backfill_subscription_auditlogs"),
        ("zerver", "0451_add_userprofile_api_key_index"),
        ("zerver", "0452_realmauditlog_extra_data_json"),
        ("zerver", "0453_followed_topic_notifications"),
        ("zerver", "0454_usergroup_can_mention_group"),
        ("zerver", "0455_set_default_for_can_mention_group"),
        ("zerver", "0456_alter_usergroup_can_mention_group"),
        ("zerver", "0457_backfill_scheduledmessagenotificationemail_trigger"),
        ("zerver", "0458_realmauditlog_modified_user_group"),
        ("zerver", "0459_remove_invalid_characters_from_user_group_name"),
        ("zerver", "0460_backfill_realmauditlog_extradata_to_json_field"),
        ("zerver", "0461_alter_realm_default_code_block_language"),
        ("zerver", "0462_realmplayground_url_template"),
        ("zerver", "0463_backfill_realmplayground_url_template"),
        ("zerver", "0464_remove_realmplayground_url_prefix"),
        ("zerver", "0465_backfill_scheduledmessagenotificationemail_trigger"),
        ("zerver", "0466_realmfilter_order"),
        ("zerver", "0467_rename_extradata_realmauditlog_extra_data_json"),
        ("zerver", "0468_rename_followup_day_email_templates"),
        ("zerver", "0469_realm_create_multiuse_invite_group"),
        ("zerver", "0470_set_default_value_for_create_multiuse_invite_group"),
        ("zerver", "0471_alter_realm_create_multiuse_invite_group"),
        ("zerver", "0472_add_message_realm_id_indexes"),
        ("zerver", "0473_remove_message_non_realm_id_indexes"),
        ("zerver", "0474_realmuserdefault_web_stream_unreads_count_display_policy_and_more"),
        ("zerver", "0475_realm_jitsi_server_url"),
        ("zerver", "0476_realmuserdefault_automatically_follow_topics_policy_and_more"),
        ("zerver", "0477_alter_realmuserdefault_automatically_follow_topics_policy_and_more"),
        ("zerver", "0478_realm_enable_guest_user_indicator"),
        ("zerver", "0479_realm_uuid_realm_uuid_owner_secret"),
        ("zerver", "0480_realm_backfill_uuid_and_secret"),
        ("zerver", "0481_alter_realm_uuid_alter_realm_uuid_owner_secret"),
        ("zerver", "0482_automatically_follow_unmute_topics_policy_defaults"),
        (
            "zerver",
            "0483_rename_escape_navigates_to_default_view_realmuserdefault_web_escape_navigates_to_home_view_and_more",
        ),
        ("zerver", "0484_preregistrationrealm_default_language"),
        ("zerver", "0485_alter_usermessage_flags_and_add_index"),
        ("zerver", "0486_clear_old_data_for_unused_usermessage_flags"),
        ("zerver", "0487_realm_can_access_all_users_group"),
        ("zerver", "0488_set_default_value_for_can_access_all_users_group"),
        ("zerver", "0489_alter_realm_can_access_all_users_group"),
        ("zerver", "0490_renumber_options_desktop_icon_count_display"),
        ("zerver", "0491_alter_realmuserdefault_web_home_view_and_more"),
        ("zerver", "0492_realm_push_notifications_enabled_and_more"),
        ("zerver", "0493_rename_userhotspot_to_onboardingstep"),
        ("zerver", "0494_realmuserdefault_automatically_follow_topics_where_mentioned_and_more"),
        ("zerver", "0495_scheduledmessage_read_by_sender"),
        ("zerver", "0496_alter_scheduledmessage_read_by_sender"),
        ("zerver", "0501_delete_dangling_usermessages"),
        ("zerver", "0517_resort_edit_history"),
        ("zerver", "0497_resort_edit_history"),
