Skip to content

Commit

Permalink
Create default Santa target counters
Browse files Browse the repository at this point in the history
  • Loading branch information
np5 committed Jun 11, 2024
1 parent 698e27e commit 94707ef
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions zentral/contrib/santa/migrations/0037_auto_20240611_1350.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 4.2.13 on 2024-06-11 13:50

from django.db import migrations


def create_all_target_counters(apps, schema_editor):
Configuration = apps.get_model("santa", "Configuration")
Target = apps.get_model("santa", "Target")
TargetCounter = apps.get_model("santa", "TargetCounter")
configurations = list(Configuration.objects.all())
new_target_counters = []
for target in Target.objects.all():
for configuration in configurations:
new_target_counters.append(TargetCounter(target=target, configuration=configuration, collected_count=1))
if len(new_target_counters) >= 500:
TargetCounter.objects.bulk_create(new_target_counters, ignore_conflicts=True)
new_target_counters = []
if new_target_counters:
TargetCounter.objects.bulk_create(new_target_counters, ignore_conflicts=True)


class Migration(migrations.Migration):

dependencies = [
('santa', '0036_remove_target_blocked_count_and_more'),
]

operations = [
migrations.RunPython(create_all_target_counters),
]

0 comments on commit 94707ef

Please sign in to comment.