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 @@