-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Migrate docevents onto rfc documents (#5872)
* 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
1 parent
b2652e2
commit 106c67e
Showing
5 changed files
with
124 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters