# Generated by Django 2.0 on 2018-02-27 17:33

from django.db import connection, migrations, models, transaction
from gzip import decompress


def update_sizes(apps, schema_editor):
    RequestProfile = apps.get_model('django_profiler_vmprof', 'RequestProfile')
    for profile in RequestProfile.objects.iterator():
        if (profile.data is None):
            continue
        profile.size_base = len(decompress(profile.data))
        profile.size_gzip = len(profile.data)
        profile.save(force_update=True, update_fields=['size_base', 'size_gzip'])


class Migration(migrations.Migration):

    dependencies = [
        ('django_profiler_vmprof', '0005_remove_requestprofile_depth'),
    ]

    operations = [
        migrations.AddField(
            model_name='requestprofile',
            name='data_json',
            field=models.BooleanField(default=False),
            preserve_default=False,
        ),
        migrations.AddField(
            model_name='requestprofile',
            name='data_path',
            field=models.TextField(blank=True),
        ),
        migrations.AddField(
            model_name='requestprofile',
            name='size_base',
            field=models.BigIntegerField(null=True),
        ),
        migrations.AddField(
            model_name='requestprofile',
            name='size_gzip',
            field=models.BigIntegerField(null=True),
        ),
        migrations.AddField(
            model_name='requestprofile',
            name='size_json',
            field=models.BigIntegerField(null=True),
        ),
        migrations.RunPython(update_sizes, migrations.RunPython.noop),
    ]
