prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Migrate DocHistory objects for RFCs
  ### Describe the issue
  
  `DocHistory` objects that pertain to the RFC rather than the I-D need to be migrated to hang off the new `type_id="rfc"` `Document`. The `name` and `rfc_number` fields should be updated to match.
  
  ### Code of Conduct
  
  - [X] I agree to follow the [IETF's Code of Conduct](https://github.com/ietf-tools/.github/blob/main/CODE_OF_CONDUCT.md)
  
  </issue>
  <code>
  [start of ietf/doc/migrations/0017_move_dochistory.py]
  1 # Generated by Django 4.2.5 on 2023-09-11 17:52
  2 
  3 from django.db import migrations
  4 
  5 from django.db.models import Subquery, OuterRef, F
  6 
  7 
  8 def forward(apps, schema_editor):
  9     DocHistory = apps.get_model("doc", "DocHistory")
  10     RelatedDocument = apps.get_model("doc", "RelatedDocument")
  11     DocHistory.objects.filter(type_id="draft", doc__type_id="rfc").update(type_id="rfc")
  12     DocHistory.objects.filter(
  13         type_id="draft", doc__type_id="draft", name__startswith="rfc"
  14     ).annotate(
  15         rfc_id=Subquery(
  16             RelatedDocument.objects.filter(
  17                 source_id=OuterRef("doc_id"), relationship_id="became_rfc"
  18             ).values_list("target_id", flat=True)[:1]
  19         )
  20     ).update(
  21         doc_id=F("rfc_id"), type_id="rfc"
  22     )
  23     assert not DocHistory.objects.filter(
  24         name__startswith="rfc", type_id="draft"
  25     ).exists()
  26 
  27 
  28 class Migration(migrations.Migration):
  29     dependencies = [
  30         ("doc", "0016_delete_docalias"),
  31     ]
  32 
  33     # There is no going back
  34     operations = [migrations.RunPython(forward)]
  35
  [end of ietf/doc/migrations/0017_move_dochistory.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/ietf/doc/migrations/0017_move_dochistory.py b/ietf/doc/migrations/0017_move_dochistory.py
  --- a/ietf/doc/migrations/0017_move_dochistory.py
  +++ b/ietf/doc/migrations/0017_move_dochistory.py
  @@ -8,6 +8,7 @@
   def forward(apps, schema_editor):
       DocHistory = apps.get_model("doc", "DocHistory")
       RelatedDocument = apps.get_model("doc", "RelatedDocument")
  +    Document = apps.get_model("doc", "Document")
       DocHistory.objects.filter(type_id="draft", doc__type_id="rfc").update(type_id="rfc")
       DocHistory.objects.filter(
           type_id="draft", doc__type_id="draft", name__startswith="rfc"
  @@ -20,9 +21,19 @@
       ).update(
           doc_id=F("rfc_id"), type_id="rfc"
       )
  +    DocHistory.objects.filter(type_id="rfc").annotate(
  +        rfcno=Subquery(
  +            Document.objects.filter(pk=OuterRef("doc_id")).values_list(
  +                "rfc_number", flat=True
  +            )[:1]
  +        )
  +    ).update(rfc_number=F("rfcno"))
       assert not DocHistory.objects.filter(
           name__startswith="rfc", type_id="draft"
       ).exists()
  +    assert not DocHistory.objects.filter(
  +        type_id="rfc", rfc_number__isnull=True
  +    ).exists()
   
   
   class Migration(migrations.Migration):
  
verification_info: {"golden_diff": "diff --git a/ietf/doc/migrations/0017_move_dochistory.py b/ietf/doc/migrations/0017_move_dochistory.py\n--- a/ietf/doc/migrations/0017_move_dochistory.py\n+++ b/ietf/doc/migrations/0017_move_dochistory.py\n@@ -8,6 +8,7 @@\n def forward(apps, schema_editor):\n     DocHistory = apps.get_model(\"doc\", \"DocHistory\")\n     RelatedDocument = apps.get_model(\"doc\", \"RelatedDocument\")\n+    Document = apps.get_model(\"doc\", \"Document\")\n     DocHistory.objects.filter(type_id=\"draft\", doc__type_id=\"rfc\").update(type_id=\"rfc\")\n     DocHistory.objects.filter(\n         type_id=\"draft\", doc__type_id=\"draft\", name__startswith=\"rfc\"\n@@ -20,9 +21,19 @@\n     ).update(\n         doc_id=F(\"rfc_id\"), type_id=\"rfc\"\n     )\n+    DocHistory.objects.filter(type_id=\"rfc\").annotate(\n+        rfcno=Subquery(\n+            Document.objects.filter(pk=OuterRef(\"doc_id\")).values_list(\n+                \"rfc_number\", flat=True\n+            )[:1]\n+        )\n+    ).update(rfc_number=F(\"rfcno\"))\n     assert not DocHistory.objects.filter(\n         name__startswith=\"rfc\", type_id=\"draft\"\n     ).exists()\n+    assert not DocHistory.objects.filter(\n+        type_id=\"rfc\", rfc_number__isnull=True\n+    ).exists()\n \n \n class Migration(migrations.Migration):\n", "issue": "Migrate DocHistory objects for RFCs\n### Describe the issue\n\n`DocHistory` objects that pertain to the RFC rather than the I-D need to be migrated to hang off the new `type_id=\"rfc\"` `Document`. The `name` and `rfc_number` fields should be updated to match.\n\n### Code of Conduct\n\n- [X] I agree to follow the [IETF's Code of Conduct](https://github.com/ietf-tools/.github/blob/main/CODE_OF_CONDUCT.md)\n", "before_files": [{"content": "# Generated by Django 4.2.5 on 2023-09-11 17:52\n\nfrom django.db import migrations\n\nfrom django.db.models import Subquery, OuterRef, F\n\n\ndef forward(apps, schema_editor):\n    DocHistory = apps.get_model(\"doc\", \"DocHistory\")\n    RelatedDocument = apps.get_model(\"doc\", \"RelatedDocument\")\n    DocHistory.objects.filter(type_id=\"draft\", doc__type_id=\"rfc\").update(type_id=\"rfc\")\n    DocHistory.objects.filter(\n        type_id=\"draft\", doc__type_id=\"draft\", name__startswith=\"rfc\"\n    ).annotate(\n        rfc_id=Subquery(\n            RelatedDocument.objects.filter(\n                source_id=OuterRef(\"doc_id\"), relationship_id=\"became_rfc\"\n            ).values_list(\"target_id\", flat=True)[:1]\n        )\n    ).update(\n        doc_id=F(\"rfc_id\"), type_id=\"rfc\"\n    )\n    assert not DocHistory.objects.filter(\n        name__startswith=\"rfc\", type_id=\"draft\"\n    ).exists()\n\n\nclass Migration(migrations.Migration):\n    dependencies = [\n        (\"doc\", \"0016_delete_docalias\"),\n    ]\n\n    # There is no going back\n    operations = [migrations.RunPython(forward)]\n", "path": "ietf/doc/migrations/0017_move_dochistory.py"}]}