-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add data models for ScanReport Job overview (#916)
Co-authored-by: Andy Rae <[email protected]>
- Loading branch information
1 parent
87c8534
commit 67b0309
Showing
6 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,7 @@ | |
"revproxy", | ||
"shared", | ||
"shared.files", | ||
"shared.jobs", | ||
] | ||
|
||
MIDDLEWARE = [ | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class JobsConfig(AppConfig): | ||
name = "shared.jobs" | ||
label = "jobs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
# Generated by Django 4.2.15 on 2024-11-28 09:27 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
from django.conf import settings | ||
|
||
|
||
def seeding_objects(apps, schema_editor): | ||
JobStage = apps.get_model("jobs", "JobStage") | ||
StageStatus = apps.get_model("jobs", "StageStatus") | ||
|
||
job_stages = [ | ||
{"id": 1, "value": "UPLOAD_SCAN_REPORT", "display_name": "Upload Scan Report"}, | ||
{ | ||
"id": 2, | ||
"value": "BUILD_CONCEPTS_FROM_DICT", | ||
"display_name": "Build concepts from OMOP Data dictionary", | ||
}, | ||
{ | ||
"id": 3, | ||
"value": "REUSE_CONCEPTS", | ||
"display_name": "Reuse concepts from other scan reports", | ||
}, | ||
{ | ||
"id": 4, | ||
"value": "GENERATE_RULES", | ||
"display_name": "Auto generate mapping rules from available concepts", | ||
}, | ||
{ | ||
"id": 5, | ||
"value": "DOWNLOAD_RULES", | ||
"display_name": "Generate and download mapping rules JSON", | ||
}, | ||
] | ||
|
||
for stage in job_stages: | ||
JobStage.objects.create( | ||
id=stage["id"], | ||
value=stage["value"], | ||
display_name=stage["display_name"], | ||
) | ||
|
||
stage_statuses = [ | ||
{ | ||
"id": 1, | ||
"value": "IN_PROGRESS", | ||
"display_name": "Job in Progress", | ||
}, | ||
{ | ||
"id": 2, | ||
"value": "COMPLETE", | ||
"display_name": "Job Complete", | ||
}, | ||
{"id": 3, "value": "FAILED", "display_name": "Job Failed"}, | ||
] | ||
|
||
for status in stage_statuses: | ||
StageStatus.objects.create( | ||
id=status["id"], | ||
value=status["value"], | ||
display_name=status["display_name"], | ||
) | ||
|
||
|
||
def unseeding_objects(apps, schema_editor): | ||
JobStage = apps.get_model("jobs", "JobStage") | ||
StageStatus = apps.get_model("jobs", "StageStatus") | ||
# Remove all objects | ||
JobStage.objects.all().delete() | ||
StageStatus.objects.all().delete() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
("mapping", "0005_auto_20241015_0900"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="JobStage", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("value", models.CharField(max_length=64)), | ||
("display_name", models.CharField(max_length=64)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name="StageStatus", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("value", models.CharField(max_length=64)), | ||
("display_name", models.CharField(max_length=64)), | ||
], | ||
), | ||
migrations.RunPython(seeding_objects, unseeding_objects), | ||
migrations.CreateModel( | ||
name="Job", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("scan_report_id", models.IntegerField(null=True)), | ||
("scan_report_table_id", models.IntegerField(null=True)), | ||
( | ||
"stage", | ||
models.ForeignKey( | ||
blank=True, | ||
null=True, | ||
on_delete=django.db.models.deletion.DO_NOTHING, | ||
related_name="job_stage", | ||
to="jobs.jobstage", | ||
), | ||
), | ||
( | ||
"status", | ||
models.ForeignKey( | ||
blank=True, | ||
null=True, | ||
on_delete=django.db.models.deletion.DO_NOTHING, | ||
related_name="stage_status", | ||
to="jobs.stagestatus", | ||
), | ||
), | ||
("details", models.CharField(blank=True, max_length=256, null=True)), | ||
("created_at", models.DateTimeField(auto_now_add=True)), | ||
("updated_at", models.DateTimeField(auto_now=True)), | ||
], | ||
options={ | ||
"abstract": False, | ||
}, | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from django.db import models | ||
from shared.mapping.models import BaseModel | ||
|
||
|
||
class JobStage(models.Model): | ||
value = models.CharField(max_length=64) | ||
display_name = models.CharField(max_length=64) | ||
|
||
|
||
class StageStatus(models.Model): | ||
value = models.CharField(max_length=64) | ||
display_name = models.CharField(max_length=64) | ||
|
||
|
||
class Job(BaseModel): | ||
scan_report_id = models.IntegerField(null=True) | ||
scan_report_table_id = models.IntegerField(null=True) | ||
stage = models.ForeignKey( | ||
"JobStage", | ||
null=True, | ||
blank=True, | ||
on_delete=models.DO_NOTHING, | ||
related_name="job_stage", | ||
) | ||
status = models.ForeignKey( | ||
"StageStatus", | ||
null=True, | ||
blank=True, | ||
on_delete=models.DO_NOTHING, | ||
related_name="stage_status", | ||
) | ||
details = models.CharField(max_length=256, null=True, blank=True) |