From a29c1f71b581671a29bca45407221eb14b75b21e Mon Sep 17 00:00:00 2001 From: James Meakin <12661555+jmsmkn@users.noreply.github.com> Date: Mon, 2 Jun 2025 19:32:37 +0200 Subject: [PATCH 1/2] Remove deprecated fields --- .../0075_remove_job_completed_at_and_more.py | 28 +++++++++++++++++++ app/grandchallenge/components/models.py | 10 ------- ...remove_evaluation_completed_at_and_more.py | 28 +++++++++++++++++++ 3 files changed, 56 insertions(+), 10 deletions(-) create mode 100644 app/grandchallenge/algorithms/migrations/0075_remove_job_completed_at_and_more.py create mode 100644 app/grandchallenge/evaluation/migrations/0088_remove_evaluation_completed_at_and_more.py diff --git a/app/grandchallenge/algorithms/migrations/0075_remove_job_completed_at_and_more.py b/app/grandchallenge/algorithms/migrations/0075_remove_job_completed_at_and_more.py new file mode 100644 index 0000000000..bbfcb10b5d --- /dev/null +++ b/app/grandchallenge/algorithms/migrations/0075_remove_job_completed_at_and_more.py @@ -0,0 +1,28 @@ +# Generated by Django 4.2.21 on 2025-06-02 17:32 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ( + "algorithms", + "0074_algorithmimageuserobjectpermission_algorithms__user_id_ba5ee9_idx_and_more", + ), + ] + + operations = [ + migrations.RemoveField( + model_name="job", + name="completed_at", + ), + migrations.RemoveField( + model_name="job", + name="compute_cost_euro_millicents", + ), + migrations.RemoveField( + model_name="job", + name="started_at", + ), + ] diff --git a/app/grandchallenge/components/models.py b/app/grandchallenge/components/models.py index 4d9d7ed47b..82ee62aa9c 100644 --- a/app/grandchallenge/components/models.py +++ b/app/grandchallenge/components/models.py @@ -1655,16 +1655,6 @@ class ComponentJob(FieldChangeMixin, UUIDModel): runtime_metrics = models.JSONField(default=dict, editable=False) error_message = models.CharField(max_length=1024, default="") detailed_error_message = models.JSONField(blank=True, default=dict) - started_at = models.DateTimeField(null=True) - completed_at = models.DateTimeField(null=True) - compute_cost_euro_millicents = models.PositiveIntegerField( - # We store euro here as the costs were incurred at a time when - # the exchange rate may have been different - editable=False, - null=True, - default=None, - help_text="The total compute cost for this job in Euro Cents, including Tax", - ) input_prefixes = models.JSONField( default=dict, editable=False, diff --git a/app/grandchallenge/evaluation/migrations/0088_remove_evaluation_completed_at_and_more.py b/app/grandchallenge/evaluation/migrations/0088_remove_evaluation_completed_at_and_more.py new file mode 100644 index 0000000000..622b16bd19 --- /dev/null +++ b/app/grandchallenge/evaluation/migrations/0088_remove_evaluation_completed_at_and_more.py @@ -0,0 +1,28 @@ +# Generated by Django 4.2.21 on 2025-06-02 17:32 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ( + "evaluation", + "0087_evaluationgroundtruthuserobjectpermission_evaluation__user_id_3b94cc_idx_and_more", + ), + ] + + operations = [ + migrations.RemoveField( + model_name="evaluation", + name="completed_at", + ), + migrations.RemoveField( + model_name="evaluation", + name="compute_cost_euro_millicents", + ), + migrations.RemoveField( + model_name="evaluation", + name="started_at", + ), + ] From 6ad8e2adee701250c093c2ca5b949577f073b39f Mon Sep 17 00:00:00 2001 From: James Meakin <12661555+jmsmkn@users.noreply.github.com> Date: Mon, 2 Jun 2025 19:53:40 +0200 Subject: [PATCH 2/2] Only run data migration with data --- .../migrations/0003_auto_20250520_1012.py | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/app/grandchallenge/utilization/migrations/0003_auto_20250520_1012.py b/app/grandchallenge/utilization/migrations/0003_auto_20250520_1012.py index b267d54d9b..b310edd2e7 100644 --- a/app/grandchallenge/utilization/migrations/0003_auto_20250520_1012.py +++ b/app/grandchallenge/utilization/migrations/0003_auto_20250520_1012.py @@ -10,6 +10,9 @@ def create_evaluation_utilizations(apps, schema_editor): evaluations_to_create = [] n_created = 0 + if not Evaluation.objects.exists(): + return + for evaluation in ( Evaluation.objects.filter(evaluation_utilization__isnull=True) .only( @@ -72,6 +75,9 @@ def create_job_utilizations(apps, schema_editor): job_utlizations_to_create = [] n_created = 0 + if not Job.objects.exists(): + return + for job in ( Job.objects.filter(job_utilization__isnull=True) .only( @@ -120,20 +126,21 @@ def set_challenges_to_job_utilizations(apps, schema_editor): Permission = apps.get_model("auth", "Permission") # noqa: N806 Challenge = apps.get_model("challenges", "Challenge") # noqa: N806 - challenges = Challenge.objects.all() + if not Challenge.objects.exists(): + return - if challenges.exists(): - permission = Permission.objects.get( - codename="view_job", - content_type__app_label="algorithms", - content_type__model="job", - ) - for challenge in challenges: - job_utilizations = JobUtilization.objects.filter( - job__jobgroupobjectpermission__group=challenge.admins_group, - job__jobgroupobjectpermission__permission=permission, - ).distinct() - job_utilizations.update(challenge=challenge) + permission = Permission.objects.get( + codename="view_job", + content_type__app_label="algorithms", + content_type__model="job", + ) + + for challenge in Challenge.objects.all(): + job_utilizations = JobUtilization.objects.filter( + job__jobgroupobjectpermission__group=challenge.admins_group, + job__jobgroupobjectpermission__permission=permission, + ).distinct() + job_utilizations.update(challenge=challenge) def set_phases_and_archive_to_job_utilizations(apps, schema_editor): @@ -142,6 +149,9 @@ def set_phases_and_archive_to_job_utilizations(apps, schema_editor): ) Phase = apps.get_model("evaluation", "Phase") # noqa: N806 + if not Phase.objects.exists(): + return + for phase in Phase.objects.all(): job_utilizations = JobUtilization.objects.filter( job__inputs__archive_items__archive__phase=phase,