healthchecks_healthchecks/hc/api/migrations/0067_last_error_values.py
2023-10-25 18:12:12 +03:00

32 lines
816 B
Python

# Generated by Django 3.0.1 on 2020-01-02 14:28
from __future__ import annotations
from typing import Any
from django.apps.registry import Apps
from django.db import migrations
def fill_last_errors(apps: Apps, schema_editor: Any) -> None:
Channel = apps.get_model("api", "Channel")
Notification = apps.get_model("api", "Notification")
for ch in Channel.objects.all():
error = ""
try:
n = Notification.objects.filter(channel=ch).latest()
error = n.error
except Notification.DoesNotExist:
pass
ch.last_error = error
ch.save()
class Migration(migrations.Migration):
dependencies = [
("api", "0066_channel_last_error"),
]
operations = [migrations.RunPython(fill_last_errors, migrations.RunPython.noop)]