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

31 lines
840 B
Python

# Generated by Django 3.2.2 on 2021-05-21 09:15
from __future__ import annotations
import json
from typing import Any
from django.apps.registry import Apps
from django.db import migrations
def normalize_sms_values(apps: Apps, schema_editor: Any) -> None:
Channel = apps.get_model("api", "Channel")
for ch in Channel.objects.filter(kind="sms").only("value"):
if ch.value.startswith("{"):
doc = json.loads(ch.value)
phone_number = doc["value"]
else:
phone_number = ch.value
ch.value = json.dumps({"value": phone_number, "up": False, "down": True})
ch.save()
class Migration(migrations.Migration):
dependencies = [
("api", "0077_auto_20210506_0755"),
]
operations = [migrations.RunPython(normalize_sms_values, migrations.RunPython.noop)]