0002_auto_20210314_2022.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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,
  35. to="alerts.projectalert",
  36. ),
  37. preserve_default=False,
  38. ),
  39. migrations.RemoveField(
  40. model_name="notification",
  41. name="project",
  42. ),
  43. migrations.CreateModel(
  44. name="AlertRecipient",
  45. fields=[
  46. (
  47. "id",
  48. models.AutoField(
  49. auto_created=True,
  50. primary_key=True,
  51. serialize=False,
  52. verbose_name="ID",
  53. ),
  54. ),
  55. (
  56. "recipient_type",
  57. models.CharField(
  58. choices=[("email", "Email"), ("webhook", "Webhook")],
  59. max_length=16,
  60. ),
  61. ),
  62. ("url", models.URLField(blank=True)),
  63. (
  64. "alert",
  65. models.ForeignKey(
  66. on_delete=django.db.models.deletion.CASCADE,
  67. to="alerts.projectalert",
  68. ),
  69. ),
  70. ],
  71. ),
  72. ]