migrations: Deprecate migration 0064 into a noop.

This ancient migration imports boto, which interferes
with our upgrade to boto3.

> git name-rev 8ae35211b5
8ae35211b5 tags/1.6.0~1924

We can safely assume nobody is upgrading from a server on <1.6.0,
since we have no supported platforms in common with those releases.
This commit is contained in:
Wyatt Hoodes
2020-04-21 14:23:23 -10:00
committed by Tim Abbott
parent 3e8d877564
commit 6d686d0e4b

View File

@@ -1,61 +1,8 @@
# Generated by Django 1.10.5 on 2017-03-18 12:38
import os
from typing import Optional
from boto.s3.connection import S3Connection
from boto.s3.key import Key
from django.conf import settings
from django.db import migrations
from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps
class MissingUploadFileException(Exception):
pass
def get_file_size_local(path_id: str) -> int:
file_path = os.path.join(settings.LOCAL_UPLOADS_DIR, 'files', path_id)
try:
size = os.path.getsize(file_path)
except OSError:
raise MissingUploadFileException
return size
def sync_filesizes(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
attachments = apps.get_model('zerver', 'Attachment')
if settings.LOCAL_UPLOADS_DIR is not None:
for attachment in attachments.objects.all():
if attachment.size is None:
try:
new_size = get_file_size_local(attachment.path_id)
except MissingUploadFileException:
new_size = 0
attachment.size = new_size
attachment.save(update_fields=["size"])
else:
conn = S3Connection(settings.S3_KEY, settings.S3_SECRET_KEY)
bucket_name = settings.S3_AUTH_UPLOADS_BUCKET
bucket = conn.get_bucket(bucket_name, validate=False)
for attachment in attachments.objects.all():
if attachment.size is None:
file_key: Optional[Key] = bucket.get_key(attachment.path_id)
if file_key is None:
new_size = 0
else:
new_size = file_key.size
attachment.size = new_size
attachment.save(update_fields=["size"])
def reverse_sync_filesizes(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
"""Does nothing"""
return None
class Migration(migrations.Migration):
dependencies = [
('zerver', '0063_realm_description'),
]
operations = [
migrations.RunPython(sync_filesizes, reverse_sync_filesizes),
]