Skip to content

Commit

Permalink
chore: Migrate SearchRules for the rfc state
Browse files Browse the repository at this point in the history
  • Loading branch information
jennifer-richards committed Jul 11, 2023
1 parent 7127062 commit 5385760
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions ietf/community/migrations/0003_track_rfcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def forward(apps, schema_editor):
CommunityList = apps.get_model("community", "CommunityList")
RelatedDocument = apps.get_model("doc", "RelatedDocument")

# Handle individually tracked documents
for cl in CommunityList.objects.all():
for rfc in set(
RelatedDocument.objects.filter(
Expand All @@ -17,11 +18,30 @@ def forward(apps, schema_editor):
):
cl.added_docs.add(rfc)

# Handle rules
SearchRule = apps.get_model("community", "SearchRule")
State = apps.get_model("doc", "State")
draft_rfc_state = State.objects.get(type_id="draft", slug="rfc")
rfc_published_state = State.objects.get(type_id="rfc", slug="published")
SearchRule.objects.filter(state=draft_rfc_state).update(state=rfc_published_state)


def reverse(apps, schema_editor):
Document = apps.get_model("doc", "Document")
for rfc in Document.objects.filter(type__slug="rfc"):
rfc.communitylist_set.clear()

SearchRule = apps.get_model("community", "SearchRule")
State = apps.get_model("doc", "State")
draft_rfc_state = State.objects.get(type_id="draft", slug="rfc")
rfc_published_state = State.objects.get(type_id="rfc", slug="published")
SearchRule.objects.filter(state=rfc_published_state).update(state=draft_rfc_state)


class Migration(migrations.Migration):
dependencies = [
("community", "0002_auto_20230320_1222"),
("doc", "0010_move_rfc_docaliases"),
]

operations = [migrations.RunPython(forward)]
operations = [migrations.RunPython(forward, reverse)]

0 comments on commit 5385760

Please sign in to comment.