Skip to content

Commit 91b22cc

Browse files
committed
Migrate topics to tags
1 parent 0b298ff commit 91b22cc

File tree

5 files changed

+117
-19
lines changed

5 files changed

+117
-19
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Generated by Django 4.2.19 on 2025-08-07 17:25
2+
3+
from django.db import migrations
4+
5+
6+
def create_missing_tags_and_map_topics(apps, schema_editor):
7+
"""
8+
Create missing tags and map existing topics to appropriate tags
9+
"""
10+
Tag = apps.get_model("commitfest", "Tag")
11+
Patch = apps.get_model("commitfest", "Patch")
12+
Topic = apps.get_model("commitfest", "Topic")
13+
14+
# Create missing tags
15+
Tag.objects.get_or_create(
16+
name="SQL Commands",
17+
defaults={
18+
"color": "#198754",
19+
"description": "SQL command implementation and enhancement",
20+
},
21+
)
22+
23+
Tag.objects.get_or_create(
24+
name="System Administration",
25+
defaults={
26+
"color": "#495057",
27+
"description": "System administration and configuration",
28+
},
29+
)
30+
31+
# Topic to Tag mapping
32+
topic_tag_mapping = {
33+
"Testing": "Testing",
34+
"Refactoring": "Refactoring Only",
35+
"Documentation": "Docs Only",
36+
"Code Comments": "Comments Only",
37+
"Bug Fixes": "Bugfix",
38+
"Performance": "Performance",
39+
"Security": "Security",
40+
"Monitoring & Control": "Monitoring",
41+
"Procedural Languages": "PL/pgSQL",
42+
"Replication & Recovery": "Physical Replication",
43+
"Clients": "libpq",
44+
"SQL Commands": "SQL Commands",
45+
"System Administration": "System Administration",
46+
# 'Miscellaneous' and 'Server Features' are left untagged
47+
}
48+
49+
# Apply tags to existing patches based on their topics
50+
for topic_name, tag_name in topic_tag_mapping.items():
51+
try:
52+
topic = Topic.objects.get(topic=topic_name)
53+
tag = Tag.objects.get(name=tag_name)
54+
55+
# Get all patches with this topic
56+
patches_with_topic = Patch.objects.filter(topic=topic)
57+
58+
# Add the corresponding tag to each patch
59+
for patch in patches_with_topic:
60+
patch.tags.add(tag)
61+
62+
print(
63+
f"Mapped {patches_with_topic.count()} patches from topic '{topic_name}' to tag '{tag_name}'"
64+
)
65+
66+
except Topic.DoesNotExist:
67+
print(f"Topic '{topic_name}' not found, skipping...")
68+
except Tag.DoesNotExist:
69+
print(f"Tag '{tag_name}' not found, skipping...")
70+
71+
72+
def reverse_mapping(apps, schema_editor):
73+
"""
74+
Reverse the migration by removing topic-based tags from patches
75+
"""
76+
Tag = apps.get_model("commitfest", "Tag")
77+
78+
# List of tags that were added by this migration
79+
topic_based_tag_names = [
80+
"Testing",
81+
"Refactoring Only",
82+
"Docs Only",
83+
"Comments Only",
84+
"Bugfix",
85+
"Performance",
86+
"Security",
87+
"Monitoring",
88+
"PL/pgSQL",
89+
"Physical Replication",
90+
"libpq",
91+
"SQL Commands",
92+
"System Administration",
93+
]
94+
95+
for tag_name in topic_based_tag_names:
96+
try:
97+
tag = Tag.objects.get(name=tag_name)
98+
# Remove this tag from all patches
99+
tag.patches.clear()
100+
except Tag.DoesNotExist:
101+
pass
102+
103+
104+
class Migration(migrations.Migration):
105+
dependencies = [
106+
("commitfest", "0014_add_paused_cfbot_task_state"),
107+
]
108+
109+
operations = [
110+
migrations.RunPython(
111+
create_missing_tags_and_map_topics,
112+
reverse_mapping,
113+
),
114+
]

pgcommitfest/commitfest/templates/commitfest.html

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@ <h3>{{p.is_open|yesno:"Active patches,Closed patches"}}</h3>
4646
<tbody>
4747
{%endifchanged%}
4848

49-
{%if grouping%}
50-
{%ifchanged p.topic%}
51-
<tr><th colspan="{%if user.is_staff%}12{%else%}11{%endif%}">{{p.topic}}</th></tr>
52-
{%endifchanged%}
53-
{%endif%}
5449
<tr>
5550
<td><a href="/patch/{{p.id}}/">{{p.name}}</a></td>
5651
<td>{{p.id}}</td>

pgcommitfest/commitfest/templates/home.html

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,6 @@ <h3>{%if user.is_authenticated%}Open patches you are subscribed to{%elif p.is_op
143143
<tbody>
144144
{%endifchanged%}
145145

146-
{%if grouping%}
147-
{%ifchanged p.topic%}
148-
<tr><th colspan="{%if user.is_authenticated %}13{%else%}12{%endif%}">{{p.topic}}</th></tr>
149-
{%endifchanged%}
150-
{%endif%}
151146
<tr>
152147
<td><a href="/patch/{{p.id}}/">{{p.name}}</a></td>
153148
<td>{{p.id}}</td>

pgcommitfest/commitfest/templates/patch.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@
6565
Unknown
6666
{%endif%}
6767
</tr>
68-
<tr>
69-
<th>Topic</th>
70-
<td>{{patch.topic}}</td>
71-
</tr>
7268
<tr>
7369
<th>Tags</th>
7470
<td>

pgcommitfest/commitfest/views.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ def patchlist(request, cf, personalized=False):
437437
joins_str = "INNER JOIN commitfest_commitfest cf ON poc.commitfest_id=cf.id"
438438
groupby_str = "cf.id,"
439439
else:
440-
columns_str = "t.topic as topic,"
440+
columns_str = ""
441441
joins_str = ""
442442
groupby_str = ""
443443

@@ -498,7 +498,7 @@ def patchlist(request, cf, personalized=False):
498498
lastmail DESC"""
499499
whereparams["cf_closed_status"] = CommitFest.STATUS_CLOSED
500500
else:
501-
orderby_str = "topic, created"
501+
orderby_str = "created"
502502
sortkey = 0
503503

504504
if not has_filter and sortkey == 0 and request.GET:
@@ -555,13 +555,12 @@ def patchlist(request, cf, personalized=False):
555555
)
556556
FROM commitfest_patch p
557557
INNER JOIN commitfest_patchoncommitfest poc ON poc.patch_id=p.id
558-
INNER JOIN commitfest_topic t ON t.id=p.topic_id
559558
{joins_str}
560559
LEFT JOIN auth_user committer ON committer.id=p.committer_id
561560
LEFT JOIN commitfest_targetversion v ON p.targetversion_id=v.id
562561
LEFT JOIN commitfest_cfbotbranch branch ON branch.patch_id=p.id
563562
WHERE {where_str}
564-
GROUP BY p.id, poc.id, {groupby_str} committer.id, t.id, v.version, branch.patch_id
563+
GROUP BY p.id, poc.id, {groupby_str} committer.id, v.version, branch.patch_id
565564
ORDER BY is_open DESC, {orderby_str}""",
566565
params,
567566
)
@@ -631,7 +630,6 @@ def commitfest(request, cfid):
631630
"all_tags": {t.id: t for t in Tag.objects.all()},
632631
"has_filter": patch_list.has_filter,
633632
"title": f"{cf.title} ({cf.periodstring})",
634-
"grouping": patch_list.sortkey == 0,
635633
"sortkey": patch_list.sortkey,
636634
"openpatchids": [p["id"] for p in patch_list.patches if p["is_open"]],
637635
"header_activity": "Activity log",

0 commit comments

Comments
 (0)