|
| 1 | +# Generated by Django 4.2.16 on 2024-11-28 12:37 |
| 2 | + |
| 3 | +from django.contrib.postgres.operations import RemoveIndexConcurrently |
| 4 | +from django.db import migrations |
| 5 | + |
| 6 | + |
| 7 | +class Migration(migrations.Migration): |
| 8 | + atomic = False |
| 9 | + |
| 10 | + dependencies = [ |
| 11 | + ("reports", "0035_upload_indices_part1"), |
| 12 | + ] |
| 13 | + |
| 14 | + operations = [ |
| 15 | + # We drop these indices for the following reasons: |
| 16 | + # - `upload_index_id_type_number`: This matches the above state migration, |
| 17 | + # and it looks like the index does not actually exist in the production DB. |
| 18 | + RemoveIndexConcurrently( |
| 19 | + model_name="reportsession", |
| 20 | + name="upload_index_id_type_number", |
| 21 | + ), |
| 22 | + # The following indices exist in the production DB, but not in django state/migrations: |
| 23 | + # - `reports_upload_order_number_idx`: |
| 24 | + # We never query by the `order_number` alone, so this index is likely unused. |
| 25 | + # - `reports_upload_report_id_f6b4ffae`: Queries on `report_id` should already been covered by the |
| 26 | + # newly added index on `report_id`+`upload_type`. |
| 27 | + # - `reports_upload_report_id_upload_type_index_ccnew`: |
| 28 | + # This seems to be a manually added variant of the `upload_report_type_idx` index and is thus duplicated. |
| 29 | + # - `reports_upload_report_id_upload_type_order_number_index`: |
| 30 | + # This is the same as the above, except with an additional `order_number`. |
| 31 | + # We do use it in queries, but I doubt the index pulls its weight, as the `order_number` changes quite |
| 32 | + # frequently so the index is costly to maintain. |
| 33 | + *( |
| 34 | + # Interestingly, we have to run these in individual `RunSQL` statements, otherwise django would create a |
| 35 | + # transaction around them, which is not supported for these `DROP INDEX CONCURRENTLY` statements. |
| 36 | + migrations.RunSQL( |
| 37 | + sql=f"""DROP INDEX CONCURRENTLY IF EXISTS "{idx}";""", |
| 38 | + hints={"tables": ["reports_upload"]}, |
| 39 | + ) |
| 40 | + for idx in [ |
| 41 | + "reports_upload_order_number_idx", |
| 42 | + "reports_upload_report_id_f6b4ffae", |
| 43 | + "reports_upload_report_id_upload_type_index_ccnew", |
| 44 | + "reports_upload_report_id_upload_type_order_number_index", |
| 45 | + ] |
| 46 | + ), |
| 47 | + ] |
0 commit comments