|
| 1 | +# Generated by Django 5.2.7 on 2025-10-06 07:15 |
| 2 | + |
| 3 | +from django.db import migrations |
| 4 | + |
| 5 | +def alter_choices_certificates(apps, schema_editor): |
| 6 | + """Alter old digest choices to new digest choices (also mentioning the encryption algorithm).""" |
| 7 | + Ca = apps.get_model("django_x509", "Ca") |
| 8 | + Ca.objects.filter(digest="sha1").update(digest="sha1WithRSAEncryption") |
| 9 | + Ca.objects.filter(digest="sha224").update(digest="sha224WithRSAEncryption") |
| 10 | + Ca.objects.filter(digest="sha256").update(digest="sha256WithRSAEncryption") |
| 11 | + Ca.objects.filter(digest="sha384").update(digest="sha384WithRSAEncryption") |
| 12 | + Ca.objects.filter(digest="sha512").update(digest="sha512WithRSAEncryption") |
| 13 | + |
| 14 | + Cert = apps.get_model("django_x509", "Cert") |
| 15 | + Cert.objects.filter(digest="sha1").update(digest="sha1WithRSAEncryption") |
| 16 | + Cert.objects.filter(digest="sha224").update(digest="sha224WithRSAEncryption") |
| 17 | + Cert.objects.filter(digest="sha256").update(digest="sha256WithRSAEncryption") |
| 18 | + Cert.objects.filter(digest="sha384").update(digest="sha384WithRSAEncryption") |
| 19 | + Cert.objects.filter(digest="sha512").update(digest="sha512WithRSAEncryption") |
| 20 | + |
| 21 | + |
| 22 | +def alter_choices_certificate_reverse(apps, schema_editor): |
| 23 | + """Reverse the operations of alter_choices_certificates.""" |
| 24 | + Ca = apps.get_model("django_x509", "Ca") |
| 25 | + Ca.objects.filter(digest="sha1WithRSAEncryption").update(digest="sha1") |
| 26 | + Ca.objects.filter(digest="sha224WithRSAEncryption").update(digest="sha224") |
| 27 | + Ca.objects.filter(digest="sha256WithRSAEncryption").update(digest="sha256") |
| 28 | + Ca.objects.filter(digest="sha384WithRSAEncryption").update(digest="sha384") |
| 29 | + Ca.objects.filter(digest="sha512WithRSAEncryption").update(digest="sha512") |
| 30 | + |
| 31 | + Cert = apps.get_model("django_x509", "Cert") |
| 32 | + Cert.objects.filter(digest="sha1WithRSAEncryption").update(digest="sha1") |
| 33 | + Cert.objects.filter(digest="sha224WithRSAEncryption").update(digest="sha224") |
| 34 | + Cert.objects.filter(digest="sha256WithRSAEncryption").update(digest="sha256") |
| 35 | + Cert.objects.filter(digest="sha384WithRSAEncryption").update(digest="sha384") |
| 36 | + Cert.objects.filter(digest="sha512WithRSAEncryption").update(digest="sha512") |
| 37 | + |
| 38 | + |
| 39 | +class Migration(migrations.Migration): |
| 40 | + |
| 41 | + dependencies = [ |
| 42 | + ("django_x509", "0010_alter_ca_digest_alter_cert_digest"), |
| 43 | + ] |
| 44 | + |
| 45 | + operations = [ |
| 46 | + migrations.RunPython( |
| 47 | + alter_choices_certificates, |
| 48 | + reverse_code=alter_choices_certificate_reverse |
| 49 | + ) |
| 50 | + ] |
0 commit comments