Skip to content

Commit

Permalink
feat: Migrate docevents onto rfc documents (#5872)
Browse files Browse the repository at this point in the history
* refactor: Separately migrate DocAliases to rfc Documents

The gap in numbering is intentional, another migration will be along
shortly.

* feat: Migrate docevents onto rfc documents

* chore: Refining DocEvent migration (WIP)

* chore: Move IANA Action state change docevents to rfc docs

* chore: Fix typo

* refactor: Eliminate "created" rfc state

* chore: Leave "ballot set" comments on drafts
  • Loading branch information
jennifer-richards authored Jun 23, 2023
1 parent b2652e2 commit 106c67e
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 27 deletions.
8 changes: 2 additions & 6 deletions ietf/doc/migrations/0005_add_rfc_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ def forward(apps, schema_editor):
rfc_statetype, _ = StateType.objects.get_or_create(slug="rfc", label="State")

State = apps.get_model("doc", "State")
created_state, _ = State.objects.get_or_create(
type=rfc_statetype, slug="created", name="Created", used=True, order=1
State.objects.get_or_create(
type=rfc_statetype, slug="published", name="Published", used=True, order=1
)
published_state, _ = State.objects.get_or_create(
type=rfc_statetype, slug="published", name="Published", used=True, order=2
)
created_state.next_states.add(published_state)


class Migration(migrations.Migration):
Expand Down
4 changes: 0 additions & 4 deletions ietf/doc/migrations/0007_create_rfc_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def forward(apps, schema_editor):
rfc.rfc_number = int(draft.name[3:])
rfc.save()
rfc.states.set([rfc_published_state])
# Alias already points at the rfc document
else:
rfc = Document.objects.create(
type=rfc_doctype,
Expand Down Expand Up @@ -63,9 +62,6 @@ def forward(apps, schema_editor):
country=da.country,
order=da.order,
)

# Point alias at the new rfc Document
rfc_alias.docs.set([rfc])


class Migration(migrations.Migration):
Expand Down
98 changes: 98 additions & 0 deletions ietf/doc/migrations/0008_move_rfc_docevents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Generated by Django 4.2.2 on 2023-06-20 18:36

from django.db import migrations
from django.db.models import Q


def forward(apps, schema_editor):
"""Move RFC events from the draft to the rfc Document"""
DocAlias = apps.get_model("doc", "DocAlias")
DocEvent = apps.get_model("doc", "DocEvent")
Document = apps.get_model("doc", "Document")

# queryset with events migrated regardless of whether before or after the "published_rfc" event
events_always_migrated = DocEvent.objects.filter(
Q(
type__in=[
"published_rfc", # do not remove this one!
"sync_from_rfc_editor",
"rfc_editor_received_announcement", # problematic for new RFCs until RPC tools enhancements come in?
]
)
| Q(
type="changed_state",
desc__startswith="RFC Editor state",
)
| Q(
type="changed_state",
desc__startswith="IANA Action state",
)
)

# queryset with events migrated only after the "published_rfc" event
events_migrated_after_pub = DocEvent.objects.exclude(
type__in=[
"created_ballot",
"closed_ballot",
"sent_ballot_announcement",
"changed_ballot_position",
"changed_ballot_approval_text",
"changed_ballot_writeup_text",
]
).exclude(
type="added_comment",
desc__contains="ballot set", # excludes 311 comments that all apply to drafts
)

# special case for rfc 6312/6342 draft, which has two published_rfc events
ignore = ["rfc6312", "rfc6342"] # do not reprocess these later
rfc6312 = Document.objects.get(name="rfc6312")
rfc6342 = Document.objects.get(name="rfc6342")
draft = DocAlias.objects.get(name="rfc6312").docs.first()
assert draft == DocAlias.objects.get(name="rfc6342").docs.first()
published_events = list(
DocEvent.objects.filter(doc=draft, type="published_rfc").order_by("time")
)
assert len(published_events) == 2
(
pub_event_6312,
pub_event_6342,
) = published_events # order matches pub dates at rfc-editor.org

pub_event_6312.doc = rfc6312
pub_event_6312.save()
events_migrated_after_pub.filter(
doc=draft,
time__gte=pub_event_6312.time,
time__lt=pub_event_6342.time,
).update(doc=rfc6312)

pub_event_6342.doc = rfc6342
pub_event_6342.save()
events_migrated_after_pub.filter(
doc=draft,
time__gte=pub_event_6342.time,
).update(doc=rfc6342)

# Now handle all the rest
for rfc in Document.objects.filter(type_id="rfc").exclude(name__in=ignore):
draft = DocAlias.objects.get(name=rfc.name).docs.first()
assert draft is not None
published_event = DocEvent.objects.get(doc=draft, type="published_rfc")
events_always_migrated.filter(
doc=draft,
).update(doc=rfc)
events_migrated_after_pub.filter(
doc=draft,
time__gte=published_event.time,
).update(doc=rfc)


class Migration(migrations.Migration):
dependencies = [
("doc", "0007_create_rfc_documents"),
]

operations = [
migrations.RunPython(forward),
]
22 changes: 22 additions & 0 deletions ietf/doc/migrations/0009_move_rfc_docaliases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.2.2 on 2023-06-20 18:36

from django.db import migrations


def forward(apps, schema_editor):
"""Point "rfc..." DocAliases at the rfc-type Document"""
DocAlias = apps.get_model("doc", "DocAlias")
Document = apps.get_model("doc", "Document")
for rfc_alias in DocAlias.objects.filter(name__startswith="rfc"):
rfc = Document.objects.get(name=rfc_alias.name)
rfc_alias.docs.set([rfc])


class Migration(migrations.Migration):
dependencies = [
("doc", "0008_move_rfc_docevents"),
]

operations = [
migrations.RunPython(forward),
]
19 changes: 2 additions & 17 deletions ietf/name/fixtures/names.json
Original file line number Diff line number Diff line change
Expand Up @@ -2539,33 +2539,18 @@
"model": "doc.state",
"pk": 174
},
{
"fields": {
"desc": "",
"name": "Created",
"next_states": [
176
],
"order": 1,
"slug": "created",
"type": "rfc",
"used": true
},
"model": "doc.state",
"pk": 175
},
{
"fields": {
"desc": "",
"name": "Published",
"next_states": [],
"order": 2,
"order": 1,
"slug": "published",
"type": "rfc",
"used": true
},
"model": "doc.state",
"pk": 176
"pk": 175
},
{
"fields": {
Expand Down

0 comments on commit 106c67e

Please sign in to comment.