|
| 1 | +# Generated by Django on 2025-03-04 |
| 2 | + |
| 3 | +from django.db import migrations |
| 4 | + |
| 5 | + |
| 6 | +def convert_reference_uri_https_to_http(apps, schema_editor): |
| 7 | + """ |
| 8 | + Converts all reference_uri values from https to http. |
| 9 | + """ |
| 10 | + ConnectivityStatement = apps.get_model("composer", "ConnectivityStatement") |
| 11 | + |
| 12 | + # Get all statements with reference_uri starting with https:// |
| 13 | + statements_with_https = ConnectivityStatement.objects.filter( |
| 14 | + reference_uri__startswith="https://uri.interlex.org/composer/uris/set/" |
| 15 | + ) |
| 16 | + |
| 17 | + # Update each statement to use http instead of https |
| 18 | + for statement in statements_with_https: |
| 19 | + statement.reference_uri = statement.reference_uri.replace("https://", "http://", 1) |
| 20 | + statement.save(update_fields=["reference_uri"]) |
| 21 | + |
| 22 | + |
| 23 | +def reverse_convert_reference_uri_http_to_https(apps, schema_editor): |
| 24 | + """ |
| 25 | + Reverse migration: Converts reference_uri values back from http to https. |
| 26 | + """ |
| 27 | + ConnectivityStatement = apps.get_model("composer", "ConnectivityStatement") |
| 28 | + |
| 29 | + # Get all statements with reference_uri starting with http:// |
| 30 | + statements_with_http = ConnectivityStatement.objects.filter( |
| 31 | + reference_uri__startswith="http://uri.interlex.org/composer/uris/set/" |
| 32 | + ) |
| 33 | + |
| 34 | + # Update each statement to use https instead of http |
| 35 | + for statement in statements_with_http: |
| 36 | + statement.reference_uri = statement.reference_uri.replace("http://", "https://", 1) |
| 37 | + statement.save(update_fields=["reference_uri"]) |
| 38 | + |
| 39 | + |
| 40 | +class Migration(migrations.Migration): |
| 41 | + |
| 42 | + dependencies = [ |
| 43 | + ("composer", "0097_relationship_custom_ingestion_code"), |
| 44 | + ] |
| 45 | + |
| 46 | + operations = [ |
| 47 | + migrations.RunPython( |
| 48 | + convert_reference_uri_https_to_http, |
| 49 | + reverse_code=reverse_convert_reference_uri_http_to_https |
| 50 | + ), |
| 51 | + ] |
0 commit comments