0002_auto_20210314_2022.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # Generated by Django 3.1.7 on 2021-03-14 20:22
  2. from django.db import migrations, models
  3. import django.db.models.deletion
  4. def forwards_func(apps, schema_editor):
  5. Notification = apps.get_model("alerts", "Notification")
  6. ProjectAlert = apps.get_model("alerts", "ProjectAlert")
  7. for notification in Notification.objects.all():
  8. notification.project_alert = ProjectAlert.objects.filter(
  9. project=notification.project
  10. ).first()
  11. notification.save()
  12. def reverse_func(apps, schema_editor):
  13. pass
  14. class Migration(migrations.Migration):
  15. dependencies = [
  16. ("alerts", "0001_initial"),
  17. ]
  18. operations = [
  19. migrations.AddField(
  20. model_name="notification",
  21. name="project_alert",
  22. field=models.ForeignKey(
  23. null=True,
  24. on_delete=django.db.models.deletion.CASCADE,
  25. to="alerts.projectalert",
  26. ),
  27. preserve_default=False,
  28. ),
  29. migrations.RunPython(forwards_func, reverse_func),
  30. migrations.AlterField(
  31. model_name="notification",
  32. name="project_alert",
  33. field=models.ForeignKey(
  34. on_delete=django.db.models.deletion.CASCADE, to="alerts.projectalert",
  35. ),
  36. preserve_default=False,
  37. ),
  38. migrations.RemoveField(model_name="notification", name="project",),
  39. migrations.CreateModel(
  40. name="AlertRecipient",
  41. fields=[
  42. (
  43. "id",
  44. models.AutoField(
  45. auto_created=True,
  46. primary_key=True,
  47. serialize=False,
  48. verbose_name="ID",
  49. ),
  50. ),
  51. (
  52. "recipient_type",
  53. models.CharField(
  54. choices=[("email", "Email"), ("webhook", "Webhook")],
  55. max_length=16,
  56. ),
  57. ),
  58. ("url", models.URLField(blank=True)),
  59. (
  60. "alert",
  61. models.ForeignKey(
  62. on_delete=django.db.models.deletion.CASCADE,
  63. to="alerts.projectalert",
  64. ),
  65. ),
  66. ],
  67. ),
  68. ]