diff --git a/lms/djangoapps/verify_student/migrations/0017_cleanup_retired_manualverification.py b/lms/djangoapps/verify_student/migrations/0017_cleanup_retired_manualverification.py new file mode 100644 index 000000000000..63512e62cdc5 --- /dev/null +++ b/lms/djangoapps/verify_student/migrations/0017_cleanup_retired_manualverification.py @@ -0,0 +1,38 @@ +# Generated by Django 5.2.15 on 2026-07-24 06:03 + +from django.conf import settings +from django.db import migrations + + +def cleanup_retired_manual_verifications(apps, schema_editor): + """ + Clear PII, then delete manual verification rows for retired users. + """ + if not getattr(settings, "REDACT_MANUAL_VERIFICATION_HISTORICAL_PII", False): + return + + db_alias = schema_editor.connection.alias + ManualVerification = apps.get_model('verify_student', 'ManualVerification') + + retired_records = ManualVerification.objects.using(db_alias).filter( + user__userretirementrequest__isnull=False, + ) + + # Clear PII, then delete matching records to take care of any soft delete setup in downstream systems. + retired_records.update(name='') + retired_records.delete() + + +class Migration(migrations.Migration): + + dependencies = [ + ("verify_student", "0016_remove_verificationattempt_created_and_more"), + ("user_api", "0003_userretirementrequest"), + ] + + operations = [ + migrations.RunPython( + cleanup_retired_manual_verifications, + reverse_code=migrations.RunPython.noop, + ), + ]