|
| 1 | +# Generated by Django 4.2.9 on 2024-12-13 19:57 |
| 2 | + |
| 3 | +from django.db import migrations, models |
| 4 | + |
| 5 | + |
| 6 | +def migrate_reindexing_statuses(apps, schema_editor): |
| 7 | + Collection = apps.get_model("sde_collections", "Collection") |
| 8 | + ReindexingHistory = apps.get_model("sde_collections", "ReindexingHistory") |
| 9 | + |
| 10 | + # Update Collections |
| 11 | + Collection.objects.filter(reindexing_status=6).update(reindexing_status=7) # Move "Indexed on Prod" first |
| 12 | + Collection.objects.filter(reindexing_status=5).update(reindexing_status=6) # Then move "Curated" |
| 13 | + # 5 is now free for "Curation in Progress" |
| 14 | + |
| 15 | + # Update ReindexingHistory |
| 16 | + ReindexingHistory.objects.filter(reindexing_status=6).update(reindexing_status=7) |
| 17 | + ReindexingHistory.objects.filter(reindexing_status=5).update(reindexing_status=6) |
| 18 | + |
| 19 | + ReindexingHistory.objects.filter(old_status=6).update(old_status=7) |
| 20 | + ReindexingHistory.objects.filter(old_status=5).update(old_status=6) |
| 21 | + |
| 22 | + |
| 23 | +def reverse_migrate_reindexing_statuses(apps, schema_editor): |
| 24 | + Collection = apps.get_model("sde_collections", "Collection") |
| 25 | + ReindexingHistory = apps.get_model("sde_collections", "ReindexingHistory") |
| 26 | + |
| 27 | + # Reverse Collections |
| 28 | + Collection.objects.filter(reindexing_status=5).update(reindexing_status=None) # Clear new status |
| 29 | + Collection.objects.filter(reindexing_status=6).update(reindexing_status=5) |
| 30 | + Collection.objects.filter(reindexing_status=7).update(reindexing_status=6) |
| 31 | + |
| 32 | + # Reverse ReindexingHistory |
| 33 | + ReindexingHistory.objects.filter(reindexing_status=5).update(reindexing_status=None) |
| 34 | + ReindexingHistory.objects.filter(reindexing_status=6).update(reindexing_status=5) |
| 35 | + ReindexingHistory.objects.filter(reindexing_status=7).update(reindexing_status=6) |
| 36 | + |
| 37 | + ReindexingHistory.objects.filter(old_status=5).update(old_status=None) |
| 38 | + ReindexingHistory.objects.filter(old_status=6).update(old_status=5) |
| 39 | + ReindexingHistory.objects.filter(old_status=7).update(old_status=6) |
| 40 | + |
| 41 | + |
| 42 | +class Migration(migrations.Migration): |
| 43 | + |
| 44 | + dependencies = [ |
| 45 | + ("sde_collections", "0074_alter_collection_reindexing_status_and_more"), |
| 46 | + ] |
| 47 | + |
| 48 | + operations = [ |
| 49 | + migrations.RunPython(migrate_reindexing_statuses, reverse_migrate_reindexing_statuses), |
| 50 | + migrations.AlterField( |
| 51 | + model_name="collection", |
| 52 | + name="reindexing_status", |
| 53 | + field=models.IntegerField( |
| 54 | + choices=[ |
| 55 | + (1, "Re-Indexing Not Needed"), |
| 56 | + (2, "Re-Indexing Needed"), |
| 57 | + (3, "Re-Indexing Finished"), |
| 58 | + (4, "Ready for Re-Curation"), |
| 59 | + (5, "Re-Curation in Progress"), |
| 60 | + (6, "Re-Curation Finished"), |
| 61 | + (7, "Re-Indexed on Prod"), |
| 62 | + ], |
| 63 | + default=1, |
| 64 | + verbose_name="Reindexing Status", |
| 65 | + ), |
| 66 | + ), |
| 67 | + migrations.AlterField( |
| 68 | + model_name="reindexinghistory", |
| 69 | + name="old_status", |
| 70 | + field=models.IntegerField( |
| 71 | + choices=[ |
| 72 | + (1, "Re-Indexing Not Needed"), |
| 73 | + (2, "Re-Indexing Needed"), |
| 74 | + (3, "Re-Indexing Finished"), |
| 75 | + (4, "Ready for Re-Curation"), |
| 76 | + (5, "Re-Curation in Progress"), |
| 77 | + (6, "Re-Curation Finished"), |
| 78 | + (7, "Re-Indexed on Prod"), |
| 79 | + ], |
| 80 | + null=True, |
| 81 | + ), |
| 82 | + ), |
| 83 | + migrations.AlterField( |
| 84 | + model_name="reindexinghistory", |
| 85 | + name="reindexing_status", |
| 86 | + field=models.IntegerField( |
| 87 | + choices=[ |
| 88 | + (1, "Re-Indexing Not Needed"), |
| 89 | + (2, "Re-Indexing Needed"), |
| 90 | + (3, "Re-Indexing Finished"), |
| 91 | + (4, "Ready for Re-Curation"), |
| 92 | + (5, "Re-Curation in Progress"), |
| 93 | + (6, "Re-Curation Finished"), |
| 94 | + (7, "Re-Indexed on Prod"), |
| 95 | + ], |
| 96 | + default=1, |
| 97 | + ), |
| 98 | + ), |
| 99 | + ] |
0 commit comments