You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
725 B

  1. # Generated by Django 3.2.2 on 2021-05-21 09:15
  2. import json
  3. from django.db import migrations
  4. def normalize_sms_values(apps, schema_editor):
  5. Channel = apps.get_model("api", "Channel")
  6. for ch in Channel.objects.filter(kind="sms").only("value"):
  7. if ch.value.startswith("{"):
  8. doc = json.loads(ch.value)
  9. phone_number = doc["value"]
  10. else:
  11. phone_number = ch.value
  12. ch.value = json.dumps({"value": phone_number, "up": False, "down": True})
  13. ch.save()
  14. class Migration(migrations.Migration):
  15. dependencies = [
  16. ("api", "0077_auto_20210506_0755"),
  17. ]
  18. operations = [migrations.RunPython(normalize_sms_values, migrations.RunPython.noop)]