mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-17 21:18:16 -06:00
14438 update migration for event rules
This commit is contained in:
parent
0100857e92
commit
1a6099fce9
@ -1,6 +1,5 @@
|
|||||||
# Generated by Django 4.2.9 on 2024-02-05 21:37
|
# Generated by Django 4.2.9 on 2024-02-05 21:37
|
||||||
|
|
||||||
from django.contrib.contenttypes.models import ContentType
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
|
|
||||||
@ -9,7 +8,7 @@ def update_scripts(apps, schema_editor):
|
|||||||
from extras.models import ScriptModule
|
from extras.models import ScriptModule
|
||||||
ScriptModuleNew = apps.get_model('extras', 'ScriptModule')
|
ScriptModuleNew = apps.get_model('extras', 'ScriptModule')
|
||||||
Script = apps.get_model('extras', 'Script')
|
Script = apps.get_model('extras', 'Script')
|
||||||
# ContentType = apps.get_model('contenttypes', 'ContentType')
|
ContentType = apps.get_model('contenttypes', 'ContentType')
|
||||||
ct = ContentType.objects.filter(app_label='extras', model='script').first()
|
ct = ContentType.objects.filter(app_label='extras', model='script').first()
|
||||||
|
|
||||||
for module in ScriptModule.objects.all():
|
for module in ScriptModule.objects.all():
|
||||||
@ -20,18 +19,22 @@ def update_scripts(apps, schema_editor):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# update all jobs associated with this module/name to point to the new script obj
|
# update all jobs associated with this module/name to point to the new script obj
|
||||||
module.jobs.filter(name=script).update(object_type=ct, object_id=obj.id)
|
if ct:
|
||||||
|
module.jobs.filter(name=script).update(object_type=ct, object_id=obj.id)
|
||||||
|
|
||||||
EventRule = apps.get_model('extras', 'EventRule')
|
EventRule = apps.get_model('extras', 'EventRule')
|
||||||
ct_script_module = ContentType.objects.filter(app_label='extras', model='scriptmodule').first()
|
ct_script_module = ContentType.objects.filter(app_label='extras', model='scriptmodule').first()
|
||||||
for rule in EventRule.objects.filter(action_object_type=ct_script_module):
|
for rule in EventRule.objects.filter(action_object_type=ct_script_module):
|
||||||
name = rule.action_parameters.get('script_name')
|
name = rule.action_parameters.get('script_name')
|
||||||
if name:
|
obj, created = Script.objects.get_or_create(
|
||||||
obj = Script.objects.filter(module=rule.action_object, name=name).first()
|
module_id=rule.action_object_id,
|
||||||
if obj:
|
name=name,
|
||||||
rule.action_paramter = obj
|
)
|
||||||
rule.action_parameters.pop(name, None)
|
|
||||||
rule.save()
|
if created:
|
||||||
|
# script in action_parameters was deleted?
|
||||||
|
obj.is_valid = False
|
||||||
|
obj.save()
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
@ -65,4 +68,8 @@ class Migration(migrations.Migration):
|
|||||||
code=update_scripts,
|
code=update_scripts,
|
||||||
reverse_code=migrations.RunPython.noop
|
reverse_code=migrations.RunPython.noop
|
||||||
),
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='eventrule',
|
||||||
|
name='action_parameters',
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
@ -115,10 +115,6 @@ class EventRule(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin, ChangeLogged
|
|||||||
ct_field='action_object_type',
|
ct_field='action_object_type',
|
||||||
fk_field='action_object_id'
|
fk_field='action_object_id'
|
||||||
)
|
)
|
||||||
action_parameters = models.JSONField(
|
|
||||||
blank=True,
|
|
||||||
null=True
|
|
||||||
)
|
|
||||||
action_data = models.JSONField(
|
action_data = models.JSONField(
|
||||||
verbose_name=_('data'),
|
verbose_name=_('data'),
|
||||||
blank=True,
|
blank=True,
|
||||||
|
Loading…
Reference in New Issue
Block a user