zerver/migrations: Use python 3 syntax for typing.

This commit is contained in:
rht
2017-10-26 11:36:30 +02:00
committed by Tim Abbott
parent a311678190
commit c2a5b5f160
22 changed files with 50 additions and 86 deletions

View File

@@ -12,8 +12,8 @@ import zerver.models
from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps from django.db.migrations.state import StateApps
def migrate_existing_attachment_data(apps, schema_editor): def migrate_existing_attachment_data(apps: StateApps,
# type: (StateApps, DatabaseSchemaEditor) -> None schema_editor: DatabaseSchemaEditor) -> None:
Attachment = apps.get_model('zerver', 'Attachment') Attachment = apps.get_model('zerver', 'Attachment')
Recipient = apps.get_model('zerver', 'Recipient') Recipient = apps.get_model('zerver', 'Recipient')
Stream = apps.get_model('zerver', 'Stream') Stream = apps.get_model('zerver', 'Stream')

View File

@@ -6,8 +6,7 @@ from django.db.migrations.state import StateApps
from django.conf import settings from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
def set_subdomain_of_default_realm(apps, schema_editor): def set_subdomain_of_default_realm(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
# type: (StateApps, DatabaseSchemaEditor) -> None
if settings.DEVELOPMENT: if settings.DEVELOPMENT:
Realm = apps.get_model('zerver', 'Realm') Realm = apps.get_model('zerver', 'Realm')
try: try:

View File

@@ -18,15 +18,13 @@ import hashlib
# from zerver.lib.upload (which would pretty annoying, but would be a # from zerver.lib.upload (which would pretty annoying, but would be a
# pain) and just using the current version, which doesn't work # pain) and just using the current version, which doesn't work
# since we rearranged the avatars in Zulip 1.6. # since we rearranged the avatars in Zulip 1.6.
def patched_user_avatar_path(user_profile): def patched_user_avatar_path(user_profile: UserProfile) -> Text:
# type: (UserProfile) -> Text
email = user_profile.email email = user_profile.email
user_key = email.lower() + settings.AVATAR_SALT user_key = email.lower() + settings.AVATAR_SALT
return make_safe_digest(user_key, hashlib.sha1) return make_safe_digest(user_key, hashlib.sha1)
@patch('zerver.lib.upload.user_avatar_path', patched_user_avatar_path) @patch('zerver.lib.upload.user_avatar_path', patched_user_avatar_path)
def verify_medium_avatar_image(apps, schema_editor): def verify_medium_avatar_image(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
# type: (StateApps, DatabaseSchemaEditor) -> None
user_profile_model = apps.get_model('zerver', 'UserProfile') user_profile_model = apps.get_model('zerver', 'UserProfile')
for user_profile in user_profile_model.objects.filter(avatar_source=u"U"): for user_profile in user_profile_model.objects.filter(avatar_source=u"U"):
upload_backend.ensure_medium_avatar_image(user_profile) upload_backend.ensure_medium_avatar_image(user_profile)

View File

@@ -4,8 +4,7 @@ from django.db import migrations
from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps from django.db.migrations.state import StateApps
def add_domain_to_realm_alias_if_needed(apps, schema_editor): def add_domain_to_realm_alias_if_needed(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
# type: (StateApps, DatabaseSchemaEditor) -> None
Realm = apps.get_model('zerver', 'Realm') Realm = apps.get_model('zerver', 'Realm')
RealmAlias = apps.get_model('zerver', 'RealmAlias') RealmAlias = apps.get_model('zerver', 'RealmAlias')

View File

@@ -5,8 +5,7 @@ from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps from django.db.migrations.state import StateApps
from django.db import migrations, models from django.db import migrations, models
def set_string_id_using_domain(apps, schema_editor): def set_string_id_using_domain(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
# type: (StateApps, DatabaseSchemaEditor) -> None
Realm = apps.get_model('zerver', 'Realm') Realm = apps.get_model('zerver', 'Realm')
for realm in Realm.objects.all(): for realm in Realm.objects.all():
if not realm.string_id: if not realm.string_id:

View File

@@ -10,8 +10,8 @@ from django.db.migrations.state import StateApps
from zerver.lib.upload import attachment_url_re, attachment_url_to_path_id from zerver.lib.upload import attachment_url_re, attachment_url_to_path_id
def check_and_create_attachments(apps, schema_editor): def check_and_create_attachments(apps: StateApps,
# type: (StateApps, DatabaseSchemaEditor) -> None schema_editor: DatabaseSchemaEditor) -> None:
STREAM = 2 STREAM = 2
Message = apps.get_model('zerver', 'Message') Message = apps.get_model('zerver', 'Message')
Attachment = apps.get_model('zerver', 'Attachment') Attachment = apps.get_model('zerver', 'Attachment')

View File

@@ -10,8 +10,7 @@ import django.db.models.deletion
from django.utils.timezone import now as timezone_now from django.utils.timezone import now as timezone_now
def backfill_user_activations_and_deactivations(apps, schema_editor): def backfill_user_activations_and_deactivations(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
# type: (StateApps, DatabaseSchemaEditor) -> None
migration_time = timezone_now() migration_time = timezone_now()
RealmAuditLog = apps.get_model('zerver', 'RealmAuditLog') RealmAuditLog = apps.get_model('zerver', 'RealmAuditLog')
UserProfile = apps.get_model('zerver', 'UserProfile') UserProfile = apps.get_model('zerver', 'UserProfile')
@@ -26,8 +25,7 @@ def backfill_user_activations_and_deactivations(apps, schema_editor):
event_type='user_deactivated', event_time=migration_time, event_type='user_deactivated', event_time=migration_time,
backfilled=True) backfilled=True)
def reverse_code(apps, schema_editor): def reverse_code(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
# type: (StateApps, DatabaseSchemaEditor) -> None
RealmAuditLog = apps.get_model('zerver', 'RealmAuditLog') RealmAuditLog = apps.get_model('zerver', 'RealmAuditLog')
RealmAuditLog.objects.filter(event_type='user_created').delete() RealmAuditLog.objects.filter(event_type='user_created').delete()
RealmAuditLog.objects.filter(event_type='user_deactivated').delete() RealmAuditLog.objects.filter(event_type='user_deactivated').delete()

View File

@@ -15,8 +15,7 @@ import requests
import os import os
def mkdirs(path): def mkdirs(path: Text) -> None:
# type: (Text) -> None
dirname = os.path.dirname(path) dirname = os.path.dirname(path)
if not os.path.isdir(dirname): if not os.path.isdir(dirname):
os.makedirs(dirname) os.makedirs(dirname)
@@ -24,8 +23,7 @@ def mkdirs(path):
class MissingAvatarException(Exception): class MissingAvatarException(Exception):
pass pass
def move_local_file(type, path_src, path_dst): def move_local_file(type: Text, path_src: Text, path_dst: Text) -> None:
# type: (Text, Text, Text) -> None
src_file_path = os.path.join(settings.LOCAL_UPLOADS_DIR, type, path_src) src_file_path = os.path.join(settings.LOCAL_UPLOADS_DIR, type, path_src)
dst_file_path = os.path.join(settings.LOCAL_UPLOADS_DIR, type, path_dst) dst_file_path = os.path.join(settings.LOCAL_UPLOADS_DIR, type, path_dst)
if os.path.exists(dst_file_path): if os.path.exists(dst_file_path):
@@ -37,8 +35,7 @@ def move_local_file(type, path_src, path_dst):
mkdirs(dst_file_path) mkdirs(dst_file_path)
os.rename(src_file_path, dst_file_path) os.rename(src_file_path, dst_file_path)
def move_avatars_to_be_uid_based(apps, schema_editor): def move_avatars_to_be_uid_based(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
# type: (StateApps, DatabaseSchemaEditor) -> None
user_profile_model = apps.get_model('zerver', 'UserProfile') user_profile_model = apps.get_model('zerver', 'UserProfile')
if settings.LOCAL_UPLOADS_DIR is not None: if settings.LOCAL_UPLOADS_DIR is not None:
for user_profile in user_profile_model.objects.filter(avatar_source=u"U"): for user_profile in user_profile_model.objects.filter(avatar_source=u"U"):

View File

@@ -14,8 +14,7 @@ import os
class MissingUploadFileException(Exception): class MissingUploadFileException(Exception):
pass pass
def get_file_size_local(path_id): def get_file_size_local(path_id: Text) -> int:
# type: (Text) -> int
file_path = os.path.join(settings.LOCAL_UPLOADS_DIR, 'files', path_id) file_path = os.path.join(settings.LOCAL_UPLOADS_DIR, 'files', path_id)
try: try:
size = os.path.getsize(file_path) size = os.path.getsize(file_path)
@@ -23,8 +22,7 @@ def get_file_size_local(path_id):
raise MissingUploadFileException raise MissingUploadFileException
return size return size
def sync_filesizes(apps, schema_editor): def sync_filesizes(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
# type: (StateApps, DatabaseSchemaEditor) -> None
attachments = apps.get_model('zerver', 'Attachment') attachments = apps.get_model('zerver', 'Attachment')
if settings.LOCAL_UPLOADS_DIR is not None: if settings.LOCAL_UPLOADS_DIR is not None:
for attachment in attachments.objects.all(): for attachment in attachments.objects.all():
@@ -49,8 +47,7 @@ def sync_filesizes(apps, schema_editor):
attachment.size = new_size attachment.size = new_size
attachment.save(update_fields=["size"]) attachment.save(update_fields=["size"])
def reverse_sync_filesizes(apps, schema_editor): def reverse_sync_filesizes(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
# type: (StateApps, DatabaseSchemaEditor) -> None
"""Does nothing""" """Does nothing"""
return None return None

View File

@@ -6,8 +6,7 @@ from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps from django.db.migrations.state import StateApps
from django.db.models import Count from django.db.models import Count
def fix_duplicate_attachments(apps, schema_editor): def fix_duplicate_attachments(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
# type: (StateApps, DatabaseSchemaEditor) -> None
"""Migration 0041 had a bug, where if multiple messages referenced the """Migration 0041 had a bug, where if multiple messages referenced the
same attachment, rather than creating a single attachment object same attachment, rather than creating a single attachment object
for all of them, we would incorrectly create one for each message. for all of them, we would incorrectly create one for each message.

View File

@@ -25,8 +25,7 @@ from typing import Dict, Text, Tuple, Optional, Union
from six import binary_type from six import binary_type
def force_str(s, encoding='utf-8'): def force_str(s: Union[Text, binary_type], encoding: Text='utf-8') -> str:
# type: (Union[Text, binary_type], Text) -> str
"""converts a string to a native string""" """converts a string to a native string"""
if isinstance(s, str): if isinstance(s, str):
return s return s
@@ -39,23 +38,20 @@ def force_str(s, encoding='utf-8'):
class Uploader(object): class Uploader(object):
def __init__(self): def __init__(self) -> None:
# type: () -> None
self.path_template = "{realm_id}/emoji/{emoji_file_name}" self.path_template = "{realm_id}/emoji/{emoji_file_name}"
self.emoji_size = (64, 64) self.emoji_size = (64, 64)
def upload_files(self, response, resized_image, dst_path_id): def upload_files(self, response: Response, resized_image: binary_type,
# type: (Response, binary_type, Text) -> None dst_path_id: Text) -> None:
raise NotImplementedError() raise NotImplementedError()
def get_dst_path_id(self, realm_id, url, emoji_name): def get_dst_path_id(self, realm_id: int, url: Text, emoji_name: Text) -> Tuple[Text, Text]:
# type: (int, Text, Text) -> Tuple[Text,Text]
_, image_ext = os.path.splitext(url) _, image_ext = os.path.splitext(url)
file_name = ''.join((emoji_name, image_ext)) file_name = ''.join((emoji_name, image_ext))
return file_name, self.path_template.format(realm_id=realm_id, emoji_file_name=file_name) return file_name, self.path_template.format(realm_id=realm_id, emoji_file_name=file_name)
def resize_emoji(self, image_data): def resize_emoji(self, image_data: binary_type) -> Optional[binary_type]:
# type: (binary_type) -> Optional[binary_type]
im = Image.open(io.BytesIO(image_data)) im = Image.open(io.BytesIO(image_data))
format_ = im.format format_ = im.format
if format_ == 'GIF' and im.is_animated: if format_ == 'GIF' and im.is_animated:
@@ -65,8 +61,8 @@ class Uploader(object):
im.save(out, format_) im.save(out, format_)
return out.getvalue() return out.getvalue()
def upload_emoji(self, realm_id, image_url, emoji_name): def upload_emoji(self, realm_id: int, image_url: Text,
# type: (int, Text, Text) -> Optional[Text] emoji_name: Text) -> Optional[Text]:
file_name, dst_path_id = self.get_dst_path_id(realm_id, image_url, emoji_name) file_name, dst_path_id = self.get_dst_path_id(realm_id, image_url, emoji_name)
if image_url.startswith("/"): if image_url.startswith("/"):
# Handle relative URLs. # Handle relative URLs.
@@ -86,25 +82,22 @@ class Uploader(object):
class LocalUploader(Uploader): class LocalUploader(Uploader):
def __init__(self): def __init__(self) -> None:
# type: () -> None
super(LocalUploader, self).__init__() super(LocalUploader, self).__init__()
@staticmethod @staticmethod
def mkdirs(path): def mkdirs(path: Text) -> None:
# type: (Text) -> None
dirname = os.path.dirname(path) dirname = os.path.dirname(path)
if not os.path.isdir(dirname): if not os.path.isdir(dirname):
os.makedirs(dirname) os.makedirs(dirname)
def write_local_file(self, path, file_data): def write_local_file(self, path: Text, file_data: binary_type) -> None:
# type: (Text, binary_type) -> None
self.mkdirs(path) self.mkdirs(path)
with open(path, 'wb') as f: with open(path, 'wb') as f:
f.write(file_data) f.write(file_data)
def upload_files(self, response, resized_image, dst_path_id): def upload_files(self, response: Response, resized_image: binary_type,
# type: (Response, binary_type, Text) -> None dst_path_id: Text) -> None:
dst_file = os.path.join(settings.LOCAL_UPLOADS_DIR, 'avatars', dst_path_id) dst_file = os.path.join(settings.LOCAL_UPLOADS_DIR, 'avatars', dst_path_id)
if resized_image: if resized_image:
self.write_local_file(dst_file, resized_image) self.write_local_file(dst_file, resized_image)
@@ -114,21 +107,20 @@ class LocalUploader(Uploader):
class S3Uploader(Uploader): class S3Uploader(Uploader):
def __init__(self): def __init__(self) -> None:
# type: () -> None
super(S3Uploader, self).__init__() super(S3Uploader, self).__init__()
conn = S3Connection(settings.S3_KEY, settings.S3_SECRET_KEY) conn = S3Connection(settings.S3_KEY, settings.S3_SECRET_KEY)
bucket_name = settings.S3_AVATAR_BUCKET bucket_name = settings.S3_AVATAR_BUCKET
self.bucket = conn.get_bucket(bucket_name, validate=False) self.bucket = conn.get_bucket(bucket_name, validate=False)
def upload_to_s3(self, path, file_data, headers): def upload_to_s3(self, path: Text, file_data: binary_type,
# type: (Text, binary_type, Optional[Dict[Text, Text]]) -> None headers: Optional[Dict[Text, Text]]) -> None:
key = Key(self.bucket) key = Key(self.bucket)
key.key = path key.key = path
key.set_contents_from_string(force_str(file_data), headers=headers) key.set_contents_from_string(force_str(file_data), headers=headers)
def upload_files(self, response, resized_image, dst_path_id): def upload_files(self, response: Response, resized_image: binary_type,
# type: (Response, binary_type, Text) -> None dst_path_id: Text) -> None:
headers = None # type: Optional[Dict[Text, Text]] headers = None # type: Optional[Dict[Text, Text]]
content_type = response.headers.get(str("Content-Type")) or guess_type(dst_path_id)[0] content_type = response.headers.get(str("Content-Type")) or guess_type(dst_path_id)[0]
if content_type: if content_type:
@@ -139,15 +131,13 @@ class S3Uploader(Uploader):
self.upload_to_s3(dst_path_id, response.content, headers) self.upload_to_s3(dst_path_id, response.content, headers)
self.upload_to_s3('.'.join((dst_path_id, 'original')), response.content, headers) self.upload_to_s3('.'.join((dst_path_id, 'original')), response.content, headers)
def get_uploader(): def get_uploader() -> Uploader:
# type: () -> Uploader
if settings.LOCAL_UPLOADS_DIR is None: if settings.LOCAL_UPLOADS_DIR is None:
return S3Uploader() return S3Uploader()
return LocalUploader() return LocalUploader()
def upload_emoji_to_storage(apps, schema_editor): def upload_emoji_to_storage(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
# type: (StateApps, DatabaseSchemaEditor) -> None
realm_emoji_model = apps.get_model('zerver', 'RealmEmoji') realm_emoji_model = apps.get_model('zerver', 'RealmEmoji')
uploader = get_uploader() # type: Uploader uploader = get_uploader() # type: Uploader
for emoji in realm_emoji_model.objects.all(): for emoji in realm_emoji_model.objects.all():

View File

@@ -5,8 +5,7 @@ from django.db import migrations
from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps from django.db.migrations.state import StateApps
def delete_old_scheduled_jobs(apps, schema_editor): def delete_old_scheduled_jobs(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
# type: (StateApps, DatabaseSchemaEditor) -> None
"""Delete any old scheduled jobs, to handle changes in the format of """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 that table. Ideally, we'd translate the jobs, but it's not really
worth the development effort to save a few invitation reminders worth the development effort to save a few invitation reminders

View File

@@ -13,8 +13,7 @@ class Migration(migrations.Migration):
('zerver', '0080_realm_description_length'), ('zerver', '0080_realm_description_length'),
] ]
def emoji_to_lowercase(apps, schema_editor): def emoji_to_lowercase(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
# type: (StateApps, DatabaseSchemaEditor) -> None
RealmEmoji = apps.get_model("zerver", "RealmEmoji") RealmEmoji = apps.get_model("zerver", "RealmEmoji")
emoji = RealmEmoji.objects.all() emoji = RealmEmoji.objects.all()
for e in emoji: for e in emoji:

View File

@@ -5,8 +5,7 @@ from django.db import migrations, models
from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps from django.db.migrations.state import StateApps
def fix_bot_type(apps, schema_editor): def fix_bot_type(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
# type: (StateApps, DatabaseSchemaEditor) -> None
UserProfile = apps.get_model("zerver", "UserProfile") UserProfile = apps.get_model("zerver", "UserProfile")
bots = UserProfile.objects.filter(is_bot=True, bot_type=None) bots = UserProfile.objects.filter(is_bot=True, bot_type=None)
for bot in bots: for bot in bots:

View File

@@ -5,8 +5,7 @@ from django.db import migrations
from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps from django.db.migrations.state import StateApps
def delete_old_scheduled_jobs(apps, schema_editor): def delete_old_scheduled_jobs(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
# type: (StateApps, DatabaseSchemaEditor) -> None
"""Delete any old scheduled jobs, to handle changes in the format of """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 send_email. Ideally, we'd translate the jobs, but it's not really
worth the development effort to save a few invitation reminders worth the development effort to save a few invitation reminders

View File

@@ -9,8 +9,7 @@ from django.utils.timezone import now as timezone_now
from typing import List from typing import List
def backfill_subscription_log_events(apps, schema_editor): def backfill_subscription_log_events(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
# type: (StateApps, DatabaseSchemaEditor) -> None
migration_time = timezone_now() migration_time = timezone_now()
RealmAuditLog = apps.get_model('zerver', 'RealmAuditLog') RealmAuditLog = apps.get_model('zerver', 'RealmAuditLog')
Subscription = apps.get_model('zerver', 'Subscription') Subscription = apps.get_model('zerver', 'Subscription')
@@ -47,8 +46,7 @@ def backfill_subscription_log_events(apps, schema_editor):
RealmAuditLog.objects.bulk_create(objects_to_create) RealmAuditLog.objects.bulk_create(objects_to_create)
objects_to_create = [] objects_to_create = []
def reverse_code(apps, schema_editor): def reverse_code(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
# type: (StateApps, DatabaseSchemaEditor) -> None
RealmAuditLog = apps.get_model('zerver', 'RealmAuditLog') RealmAuditLog = apps.get_model('zerver', 'RealmAuditLog')
RealmAuditLog.objects.filter(event_type='subscription_created').delete() RealmAuditLog.objects.filter(event_type='subscription_created').delete()
RealmAuditLog.objects.filter(event_type='subscription_deactivated').delete() RealmAuditLog.objects.filter(event_type='subscription_deactivated').delete()

View File

@@ -9,8 +9,7 @@ from django.db import migrations, models
from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps from django.db.migrations.state import StateApps
def populate_new_fields(apps, schema_editor): def populate_new_fields(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
# type: (StateApps, DatabaseSchemaEditor) -> None
# Open the JSON file which contains the data to be used for migration. # 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") MIGRATION_DATA_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "management", "data")
path_to_unified_reactions = os.path.join(MIGRATION_DATA_PATH, "unified_reactions.json") path_to_unified_reactions = os.path.join(MIGRATION_DATA_PATH, "unified_reactions.json")

View File

@@ -6,8 +6,7 @@ from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps from django.db.migrations.state import StateApps
from django.db import connection, migrations from django.db import connection, migrations
def convert_muted_topics(apps, schema_editor): def convert_muted_topics(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
# type: (StateApps, DatabaseSchemaEditor) -> None
stream_query = ''' stream_query = '''
SELECT SELECT
zerver_stream.name, zerver_stream.name,

View File

@@ -8,8 +8,7 @@ from django.db import migrations
from zerver.lib.fix_unreads import fix from zerver.lib.fix_unreads import fix
def fix_unreads(apps, schema_editor): def fix_unreads(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
# type: (StateApps, DatabaseSchemaEditor) -> None
UserProfile = apps.get_model("zerver", "UserProfile") UserProfile = apps.get_model("zerver", "UserProfile")
user_profiles = list(UserProfile.objects.filter(is_bot=False)) user_profiles = list(UserProfile.objects.filter(is_bot=False))
for user_profile in user_profiles: for user_profile in user_profiles:

View File

@@ -5,8 +5,7 @@ from django.db import migrations
from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps from django.db.migrations.state import StateApps
def fix_realm_string_ids(apps, schema_editor): def fix_realm_string_ids(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
# type: (StateApps, DatabaseSchemaEditor) -> None
Realm = apps.get_model('zerver', 'Realm') Realm = apps.get_model('zerver', 'Realm')
if Realm.objects.filter(deactivated=False).count() != 2: if Realm.objects.filter(deactivated=False).count() != 2:
return return

View File

@@ -3,8 +3,7 @@ from django.db import models, migrations
from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps from django.db.migrations.state import StateApps
def set_tutorial_status_to_finished(apps, schema_editor): def set_tutorial_status_to_finished(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
# type: (StateApps, DatabaseSchemaEditor) -> None
UserProfile = apps.get_model('zerver', 'UserProfile') UserProfile = apps.get_model('zerver', 'UserProfile')
UserProfile.objects.update(tutorial_status=u'F') UserProfile.objects.update(tutorial_status=u'F')

View File

@@ -4,8 +4,7 @@ from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps from django.db.migrations.state import StateApps
from django.db import connection, migrations, models from django.db import connection, migrations, models
def populate_is_zephyr(apps, schema_editor): def populate_is_zephyr(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
# type: (StateApps, DatabaseSchemaEditor) -> None
Realm = apps.get_model("zerver", "Realm") Realm = apps.get_model("zerver", "Realm")
Stream = apps.get_model("zerver", "Stream") Stream = apps.get_model("zerver", "Stream")