Skip to content
This repository has been archived by the owner on Mar 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #89 from scaleoutsystems/FIX/fk_constraints
Browse files Browse the repository at this point in the history
Set proper Foreign Key constraints across the DB models
  • Loading branch information
dstoyanova authored May 12, 2020
2 parents 40a0c0d + e12c0d5 commit 04cb1f2
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 9 deletions.
6 changes: 3 additions & 3 deletions components/studio/deployments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DeploymentDefinition(models.Model):
]

project = models.ForeignKey('projects.Project',
on_delete=models.DO_NOTHING,
on_delete=models.CASCADE,
related_name='project_owner', blank=True, null=True)
access = models.CharField(max_length=2, choices=ACCESS, default=PRIVATE)
name = models.CharField(max_length=512, unique=True)
Expand All @@ -41,9 +41,9 @@ class DeploymentInstance(models.Model):
(PUBLIC, 'Public'),
]

deployment = models.ForeignKey('deployments.DeploymentDefinition', on_delete=models.DO_NOTHING)
deployment = models.ForeignKey('deployments.DeploymentDefinition', on_delete=models.CASCADE)

model = models.OneToOneField('models.Model', on_delete=models.DO_NOTHING, related_name='deployed_model', unique=True)
model = models.OneToOneField('models.Model', on_delete=models.CASCADE, related_name='deployed_model', unique=True)
access = models.CharField(max_length=2, choices=ACCESS, default=PRIVATE)
endpoint = models.CharField(max_length=512)
release = models.CharField(max_length=512)
Expand Down
2 changes: 1 addition & 1 deletion components/studio/experiments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class Experiment(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
command = models.CharField(max_length=1024)
environment = models.ForeignKey('projects.Environment', on_delete=models.DO_NOTHING, related_name='job_environment')
environment = models.ForeignKey('projects.Environment', on_delete=models.CASCADE, related_name='job_environment')
project = models.ForeignKey('projects.Project', on_delete=models.CASCADE, related_name='job_project')
created_at = models.DateTimeField(auto_now_add=True)
uploaded_at = models.DateTimeField(auto_now=True)
2 changes: 1 addition & 1 deletion components/studio/labs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Session(models.Model):
(FINISHED, 'Finished'),
(ABORTED, 'Aborted'),
]
project = models.ForeignKey('projects.Project', on_delete=models.DO_NOTHING, related_name='session')
project = models.ForeignKey('projects.Project', on_delete=models.CASCADE, related_name='session')

session_key = models.CharField(max_length=512)
session_secret = models.CharField(max_length=512)
Expand Down
8 changes: 7 additions & 1 deletion components/studio/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ class Model(models.Model):

CREATED = 'CR'
DEPLOYED = 'DP'
ARCHIVED = 'AR'
STATUS = [
(CREATED, 'Created'),
(DEPLOYED, 'Deployed'),
(ARCHIVED, 'Archived'),
]
uid = models.CharField(max_length=255)
name = models.CharField(max_length=255)
Expand All @@ -27,7 +29,11 @@ class Model(models.Model):
resource = models.URLField(max_length=2048, null=True, blank=True)
url = models.URLField(max_length=512, null=True, blank=True)
uploaded_at = models.DateTimeField(auto_now_add=True)
project = models.ForeignKey('projects.Project', on_delete=models.DO_NOTHING, related_name='model_owner')
project = models.ForeignKey(
'projects.Project',
on_delete=models.SET_NULL,
related_name='model_owner',
null=True)
status = models.CharField(max_length=2, choices=STATUS, default=CREATED)
tag = models.CharField(max_length=10, default='latest')

Expand Down
6 changes: 6 additions & 0 deletions components/studio/projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import markdown
from .forms import TransferProjectOwnershipForm
from django.db.models import Q
from models.models import Model

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -172,6 +173,11 @@ def delete(request, user, project_slug):

print("PROJECT RESOURCES DELETED SUCCESFULLY!")

models = Model.objects.filter(project=project)
for model in models:
model.status = 'AR'
model.save()

project.delete()

return HttpResponseRedirect(next_page, {'message': 'Deleted project successfully.'})
Expand Down
2 changes: 1 addition & 1 deletion components/studio/reports/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ class Report(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
report = models.TextField(blank=True)
job_id = models.CharField(max_length=256)
generator = models.ForeignKey('reports.ReportGenerator', on_delete=models.CASCADE)
generator = models.ForeignKey('reports.ReportGenerator', on_delete=models.SET_NULL, null=True)
status = models.CharField(max_length=1, choices=REPORT_STATUS, default='I')
4 changes: 2 additions & 2 deletions components/studio/workflows/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ class WorkflowInstance(models.Model):
(FINISHED, 'Finished'),
(ABORTED, 'Aborted'),
]
project = models.ForeignKey('projects.Project', on_delete=models.DO_NOTHING, related_name='project')
project = models.ForeignKey('projects.Project', on_delete=models.CASCADE, related_name='project')
status = models.CharField(max_length=2, choices=STATUS, default=CREATED)

workflow = models.ForeignKey('workflows.WorkflowDefinition', on_delete=models.DO_NOTHING,
workflow = models.ForeignKey('workflows.WorkflowDefinition', on_delete=models.CASCADE,
related_name='workflow_definition')
name = models.CharField(max_length=512, unique=False)
created_at = models.DateTimeField(auto_now_add=True)
Expand Down

0 comments on commit 04cb1f2

Please sign in to comment.