# Generated by Django 2.2.6 on 2019-12-29 19:09

from django.db import migrations
from django.db.models import QuerySet


def forwards(apps, schema_editor):
    version_queryset: QuerySet = apps.get_model("repository", "PackageVersion").objects

    versions = version_queryset.all()
    for version in versions:
        version.file_size = version.file.size

    version_queryset.bulk_update(objs=versions, fields=("file_size",), batch_size=100)


# noinspection PyPep8Naming
def backwards(apps, schema_editor):
    version_queryset: QuerySet = apps.get_model("repository", "PackageVersion").objects
    version_queryset.update(file_size=None)


class Migration(migrations.Migration):

    dependencies = [
        ("repository", "0019_add_version_file_size"),
    ]

    operations = [migrations.RunPython(code=forwards, reverse_code=backwards)]
