diff --git a/pgcommitfest/commitfest/migrations/0015_migrate_topics_to_tags.py b/pgcommitfest/commitfest/migrations/0015_migrate_topics_to_tags.py new file mode 100644 index 00000000..4bc1bd27 --- /dev/null +++ b/pgcommitfest/commitfest/migrations/0015_migrate_topics_to_tags.py @@ -0,0 +1,114 @@ +# Generated by Django 4.2.19 on 2025-08-07 17:25 + +from django.db import migrations + + +def create_missing_tags_and_map_topics(apps, schema_editor): + """ + Create missing tags and map existing topics to appropriate tags + """ + Tag = apps.get_model("commitfest", "Tag") + Patch = apps.get_model("commitfest", "Patch") + Topic = apps.get_model("commitfest", "Topic") + + # Create missing tags + Tag.objects.get_or_create( + name="SQL Commands", + defaults={ + "color": "#198754", + "description": "SQL command implementation and enhancement", + }, + ) + + Tag.objects.get_or_create( + name="System Administration", + defaults={ + "color": "#495057", + "description": "System administration and configuration", + }, + ) + + # Topic to Tag mapping + topic_tag_mapping = { + "Testing": "Testing", + "Refactoring": "Refactoring Only", + "Documentation": "Docs Only", + "Code Comments": "Comments Only", + "Bug Fixes": "Bugfix", + "Performance": "Performance", + "Security": "Security", + "Monitoring & Control": "Monitoring", + "Procedural Languages": "PL/pgSQL", + "Replication & Recovery": "Physical Replication", + "Clients": "libpq", + "SQL Commands": "SQL Commands", + "System Administration": "System Administration", + # 'Miscellaneous' and 'Server Features' are left untagged + } + + # Apply tags to existing patches based on their topics + for topic_name, tag_name in topic_tag_mapping.items(): + try: + topic = Topic.objects.get(topic=topic_name) + tag = Tag.objects.get(name=tag_name) + + # Get all patches with this topic + patches_with_topic = Patch.objects.filter(topic=topic) + + # Add the corresponding tag to each patch + for patch in patches_with_topic: + patch.tags.add(tag) + + print( + f"Mapped {patches_with_topic.count()} patches from topic '{topic_name}' to tag '{tag_name}'" + ) + + except Topic.DoesNotExist: + print(f"Topic '{topic_name}' not found, skipping...") + except Tag.DoesNotExist: + print(f"Tag '{tag_name}' not found, skipping...") + + +def reverse_mapping(apps, schema_editor): + """ + Reverse the migration by removing topic-based tags from patches + """ + Tag = apps.get_model("commitfest", "Tag") + + # List of tags that were added by this migration + topic_based_tag_names = [ + "Testing", + "Refactoring Only", + "Docs Only", + "Comments Only", + "Bugfix", + "Performance", + "Security", + "Monitoring", + "PL/pgSQL", + "Physical Replication", + "libpq", + "SQL Commands", + "System Administration", + ] + + for tag_name in topic_based_tag_names: + try: + tag = Tag.objects.get(name=tag_name) + # Remove this tag from all patches + tag.patches.clear() + except Tag.DoesNotExist: + pass + + +class Migration(migrations.Migration): + dependencies = [ + ("commitfest", "0014_add_paused_cfbot_task_state"), + ] + + operations = [ + migrations.RunPython( + create_missing_tags_and_map_topics, + reverse_mapping, + ), + ] diff --git a/pgcommitfest/commitfest/templates/commitfest.html b/pgcommitfest/commitfest/templates/commitfest.html index 99ccebc9..9111fef4 100644 --- a/pgcommitfest/commitfest/templates/commitfest.html +++ b/pgcommitfest/commitfest/templates/commitfest.html @@ -46,11 +46,6 @@

{{p.is_open|yesno:"Active patches,Closed patches"}}

{%endifchanged%} - {%if grouping%} - {%ifchanged p.topic%} - {{p.topic}} - {%endifchanged%} - {%endif%} {{p.name}} {{p.id}} diff --git a/pgcommitfest/commitfest/templates/home.html b/pgcommitfest/commitfest/templates/home.html index 931978e6..c76d3432 100644 --- a/pgcommitfest/commitfest/templates/home.html +++ b/pgcommitfest/commitfest/templates/home.html @@ -143,11 +143,6 @@

{%if user.is_authenticated%}Open patches you are subscribed to{%elif p.is_op {%endifchanged%} - {%if grouping%} - {%ifchanged p.topic%} - {{p.topic}} - {%endifchanged%} - {%endif%} {{p.name}} {{p.id}} diff --git a/pgcommitfest/commitfest/templates/patch.html b/pgcommitfest/commitfest/templates/patch.html index 40ff9b5d..d616a035 100644 --- a/pgcommitfest/commitfest/templates/patch.html +++ b/pgcommitfest/commitfest/templates/patch.html @@ -65,10 +65,6 @@ Unknown {%endif%} - - Topic - {{patch.topic}} - Tags diff --git a/pgcommitfest/commitfest/views.py b/pgcommitfest/commitfest/views.py index 215ffcb7..5fc40862 100644 --- a/pgcommitfest/commitfest/views.py +++ b/pgcommitfest/commitfest/views.py @@ -437,7 +437,7 @@ def patchlist(request, cf, personalized=False): joins_str = "INNER JOIN commitfest_commitfest cf ON poc.commitfest_id=cf.id" groupby_str = "cf.id," else: - columns_str = "t.topic as topic," + columns_str = "" joins_str = "" groupby_str = "" @@ -498,7 +498,7 @@ def patchlist(request, cf, personalized=False): lastmail DESC""" whereparams["cf_closed_status"] = CommitFest.STATUS_CLOSED else: - orderby_str = "topic, created" + orderby_str = "created" sortkey = 0 if not has_filter and sortkey == 0 and request.GET: @@ -555,13 +555,12 @@ def patchlist(request, cf, personalized=False): ) FROM commitfest_patch p INNER JOIN commitfest_patchoncommitfest poc ON poc.patch_id=p.id -INNER JOIN commitfest_topic t ON t.id=p.topic_id {joins_str} LEFT JOIN auth_user committer ON committer.id=p.committer_id LEFT JOIN commitfest_targetversion v ON p.targetversion_id=v.id LEFT JOIN commitfest_cfbotbranch branch ON branch.patch_id=p.id WHERE {where_str} -GROUP BY p.id, poc.id, {groupby_str} committer.id, t.id, v.version, branch.patch_id +GROUP BY p.id, poc.id, {groupby_str} committer.id, v.version, branch.patch_id ORDER BY is_open DESC, {orderby_str}""", params, ) @@ -631,7 +630,6 @@ def commitfest(request, cfid): "all_tags": {t.id: t for t in Tag.objects.all()}, "has_filter": patch_list.has_filter, "title": f"{cf.title} ({cf.periodstring})", - "grouping": patch_list.sortkey == 0, "sortkey": patch_list.sortkey, "openpatchids": [p["id"] for p in patch_list.patches if p["is_open"]], "header_activity": "Activity log",