From 71270621b78e47e31e4135876ec868eed3ec0c2e Mon Sep 17 00:00:00 2001
From: Jennifer Richards <jennifer@staff.ietf.org>
Date: Fri, 7 Jul 2023 17:27:55 -0300
Subject: [PATCH] chore: Track RFCs if they were tracked as a draft

---
 ietf/community/migrations/0003_track_rfcs.py | 27 ++++++++++++++++++++
 1 file changed, 27 insertions(+)
 create mode 100644 ietf/community/migrations/0003_track_rfcs.py

diff --git a/ietf/community/migrations/0003_track_rfcs.py b/ietf/community/migrations/0003_track_rfcs.py
new file mode 100644
index 000000000..61caabb77
--- /dev/null
+++ b/ietf/community/migrations/0003_track_rfcs.py
@@ -0,0 +1,27 @@
+# Generated by Django 4.2.3 on 2023-07-07 18:33
+
+from django.db import migrations
+
+
+def forward(apps, schema_editor):
+    """Track any RFCs that were created from tracked drafts"""
+    CommunityList = apps.get_model("community", "CommunityList")
+    RelatedDocument = apps.get_model("doc", "RelatedDocument")
+
+    for cl in CommunityList.objects.all():
+        for rfc in set(
+            RelatedDocument.objects.filter(
+                source__in=cl.added_docs.all(),
+                relationship__slug="became_rfc",
+            ).values_list("target__docs", flat=True)
+        ):
+            cl.added_docs.add(rfc)
+
+
+class Migration(migrations.Migration):
+    dependencies = [
+        ("community", "0002_auto_20230320_1222"),
+        ("doc", "0010_move_rfc_docaliases"),
+    ]
+
+    operations = [migrations.RunPython(forward)]