Skip to content

Commit

Permalink
protect base object before removing through removing service(_env) or…
Browse files Browse the repository at this point in the history
… conf. class/module (allegro#2985)
  • Loading branch information
mkurek authored Mar 22, 2017
1 parent 07236ad commit e61c062
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
30 changes: 30 additions & 0 deletions src/ralph/assets/migrations/0024_auto_20170322_1148.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('assets', '0023_category_allow_deployment'),
]

operations = [
migrations.AlterField(
model_name='baseobject',
name='configuration_path',
field=models.ForeignKey(verbose_name='configuration path', blank=True, help_text='path to configuration for this object, for example path to puppet class', on_delete=django.db.models.deletion.PROTECT, null=True, to='assets.ConfigurationClass'),
),
migrations.AlterField(
model_name='baseobject',
name='parent',
field=models.ForeignKey(related_name='children', to='assets.BaseObject', blank=True, on_delete=django.db.models.deletion.SET_NULL, null=True),
),
migrations.AlterField(
model_name='baseobject',
name='service_env',
field=models.ForeignKey(to='assets.ServiceEnvironment', on_delete=django.db.models.deletion.PROTECT, null=True),
),
]
10 changes: 7 additions & 3 deletions src/ralph/assets/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,13 @@ class BaseObject(
"""Base object mixin."""
# TODO: dynamically limit parent basing on model
parent = models.ForeignKey(
'self', null=True, blank=True, related_name='children'
'self', null=True, blank=True, related_name='children',
on_delete=models.SET_NULL
)
remarks = models.TextField(blank=True)
service_env = models.ForeignKey('ServiceEnvironment', null=True)
service_env = models.ForeignKey(
'ServiceEnvironment', null=True, on_delete=models.PROTECT
)

@property
def _str_with_type(self):
Expand All @@ -89,7 +92,8 @@ def _str_with_type(self):
help_text=_(
'path to configuration for this object, for example path to puppet '
'class'
)
),
on_delete=models.PROTECT
)

@property
Expand Down

0 comments on commit e61c062

Please sign in to comment.