feat: Migrate docevents onto rfc documents ()

* 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
This commit is contained in:
Jennifer Richards 2023-06-23 17:16:04 -03:00 committed by GitHub
parent b2652e245f
commit 106c67ec95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 124 additions and 27 deletions

View file

@ -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):

View file

@ -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,
@ -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):

View file

@ -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),
]

View file

@ -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),
]

View file

@ -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": {