@@ -0,0 +1,1271 @@
+# -*- coding: utf-8 -*-%0Afrom __future__ import unicode_literals%0A%0Afrom uuid import uuid4%0A%0Afrom django.db import migrations%0A%0A%0Adef create_quotas(apps, schema_editor):%0A    Project = apps.get_model('structure', 'Project')%0A    Customer = apps.get_model('structure', 'Customer')%0A    ProjectGroup = apps.get_model('structure', 'ProjectGroup')%0A    Quota = apps.get_model('quotas', 'Quota')%0A%0A    # We can not use model constants in migrations because they can be changed in future%0A    quota_name_map = %7B%0A        Project: 'nc_global_project_count',%0A        Customer: 'nc_global_customer_count',%0A        ProjectGroup: 'nc_global_project_group_count',%0A    %7D%0A%0A    for model in %5BProject, Customer, ProjectGroup%5D:%0A        name = quota_name_map%5Bmodel%5D%0A        usage = model.objects.count()%0A        if not Quota.objects.filter(name=name, object_id__isnull=True).exists():%0A            Quota.objects.create(uuid=uuid4().hex, name=name, usage=usage)%0A        else:%0A            Quota.objects.filter(name=name, object_id__isnull=True).update(usage=usage)%0A%0A%0Aclass Migration(migrations.Migration):%0A%0A    dependencies = %5B%0A        ('structure', '0021_balancehistory'),%0A        ('quotas', '0002_make_quota_scope_nullable'),%0A    %5D%0A%0A    operations = %5B%0A        migrations.RunPython(create_quotas),%0A    %5D%0A

Add global count quotas calculation migration