-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create default Santa target counters
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
zentral/contrib/santa/migrations/0037_auto_20240611_1350.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
] |