Skip to content
Merged
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
35 changes: 30 additions & 5 deletions hypha/apply/users/migrations/0028_remove_partner_group.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
# Generated by Django 5.2.12 on 2026-03-26 19:48

from django.db import migrations
from django.contrib.auth.models import Group


def migrate_partners_to_coapplicants(apps, schema_editor):
# An edge case that won't apply to most systems
def assigned_review_migrate_from_partners(apps, schema_editor):
PARTNER_GROUP_NAME = "Partner"
REVIEWER_GROUP_NAME = "Reviewer"

if Group.objects.filter(name=PARTNER_GROUP_NAME).exists():
Group.objects.get(name=PARTNER_GROUP_NAME).delete()
Group = apps.get_model("auth", "Group")
AssignedReviewers = apps.get_model("funds", "AssignedReviewers")

try:
reviewer_id = Group.objects.get(name=REVIEWER_GROUP_NAME).id
except Group.DoesNotExist:
return

if id_qs := Group.objects.filter(name=PARTNER_GROUP_NAME).values_list(
"id", flat=True
):
AssignedReviewers.objects.filter(type_id=id_qs.first()).update(
type_id=reviewer_id
)


def delete_partner_group(apps, schema_editor):
PARTNER_GROUP_NAME = "Partner"

Group = apps.get_model("auth", "Group")
Group.objects.filter(name=PARTNER_GROUP_NAME).delete()


class Migration(migrations.Migration):
Expand All @@ -17,4 +37,9 @@ class Migration(migrations.Migration):
("funds", "0133_remove_applicationsubmission_partners"),
]

operations = [migrations.RunPython(migrate_partners_to_coapplicants)]
operations = [
migrations.RunPython(
assigned_review_migrate_from_partners, migrations.RunPython.noop
),
migrations.RunPython(delete_partner_group, migrations.RunPython.noop),
]
Loading