Skip to content

Migrate topics to tags #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions pgcommitfest/commitfest/migrations/0015_migrate_topics_to_tags.py
Original file line number Diff line number Diff line change
@@ -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,
),
]
5 changes: 0 additions & 5 deletions pgcommitfest/commitfest/templates/commitfest.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ <h3>{{p.is_open|yesno:"Active patches,Closed patches"}}</h3>
<tbody>
{%endifchanged%}

{%if grouping%}
{%ifchanged p.topic%}
<tr><th colspan="{%if user.is_staff%}12{%else%}11{%endif%}">{{p.topic}}</th></tr>
{%endifchanged%}
{%endif%}
<tr>
<td><a href="/patch/{{p.id}}/">{{p.name}}</a></td>
<td>{{p.id}}</td>
Expand Down
5 changes: 0 additions & 5 deletions pgcommitfest/commitfest/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,6 @@ <h3>{%if user.is_authenticated%}Open patches you are subscribed to{%elif p.is_op
<tbody>
{%endifchanged%}

{%if grouping%}
{%ifchanged p.topic%}
<tr><th colspan="{%if user.is_authenticated %}13{%else%}12{%endif%}">{{p.topic}}</th></tr>
{%endifchanged%}
{%endif%}
<tr>
<td><a href="/patch/{{p.id}}/">{{p.name}}</a></td>
<td>{{p.id}}</td>
Expand Down
4 changes: 0 additions & 4 deletions pgcommitfest/commitfest/templates/patch.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@
Unknown
{%endif%}
</tr>
<tr>
<th>Topic</th>
<td>{{patch.topic}}</td>
</tr>
<tr>
<th>Tags</th>
<td>
Expand Down
8 changes: 3 additions & 5 deletions pgcommitfest/commitfest/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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",
Expand Down