From f14d279dadf66336c519368424c37dad2acc6d88 Mon Sep 17 00:00:00 2001 From: Deborah Kaplan Date: Thu, 25 Jan 2024 22:13:02 +0000 Subject: [PATCH 1/2] feat: data migration for some ancient legacy problems one time data migration for certificates that ended up in a broken state (not marked is unavailable, but having invalidation records). FIXES: APER-1322 --- .../0037_fix_legacy_broken_invalid_certs.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 lms/djangoapps/certificates/migrations/0037_fix_legacy_broken_invalid_certs.py diff --git a/lms/djangoapps/certificates/migrations/0037_fix_legacy_broken_invalid_certs.py b/lms/djangoapps/certificates/migrations/0037_fix_legacy_broken_invalid_certs.py new file mode 100644 index 000000000000..00a9d8aaf0a1 --- /dev/null +++ b/lms/djangoapps/certificates/migrations/0037_fix_legacy_broken_invalid_certs.py @@ -0,0 +1,28 @@ +# Generated by Django 3.2.23 on 2024-01-25 21:56 + +from django.db import migrations + + +class Migration(migrations.Migration): + """ + If any certificates exist with an invalidation record that are not marked as unavailable, + change their status. Irreversible. + """ + + dependencies = [ + ("certificates", "0036_modifiedcertificatetemplatecommandconfiguration"), + ] + + def make_invalid_certificates_unavailable(apps, schema_editor): + GeneratedCertificate = apps.get_model("certificates", "GeneratedCertificate") + + GeneratedCertificate.objects.filter( + certificateinvalidation__active=True + ).exclude(status="unavailable").update(status="unavailable") + + operations = [ + migrations.RunPython( + make_invalid_certificates_unavailable, + reverse_code=migrations.RunPython.noop, + ) + ] From 1c049a3f39dbea8aae9feec485aacbd60d2dbfe8 Mon Sep 17 00:00:00 2001 From: Deborah Kaplan Date: Mon, 29 Jan 2024 16:48:52 +0000 Subject: [PATCH 2/2] feat: switching to a defined enum feedback from code review FIXES: APER-1322 --- .../migrations/0037_fix_legacy_broken_invalid_certs.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/certificates/migrations/0037_fix_legacy_broken_invalid_certs.py b/lms/djangoapps/certificates/migrations/0037_fix_legacy_broken_invalid_certs.py index 00a9d8aaf0a1..99e57eeed2fe 100644 --- a/lms/djangoapps/certificates/migrations/0037_fix_legacy_broken_invalid_certs.py +++ b/lms/djangoapps/certificates/migrations/0037_fix_legacy_broken_invalid_certs.py @@ -2,6 +2,8 @@ from django.db import migrations +from lms.djangoapps.certificates.data import CertificateStatuses + class Migration(migrations.Migration): """ @@ -18,7 +20,9 @@ def make_invalid_certificates_unavailable(apps, schema_editor): GeneratedCertificate.objects.filter( certificateinvalidation__active=True - ).exclude(status="unavailable").update(status="unavailable") + ).exclude(status=CertificateStatuses.unavailable).update( + status=CertificateStatuses.unavailable + ) operations = [ migrations.RunPython(