mirror of https://github.com/jumpserver/jumpserver
perf: 优化 platform automation 结构
parent
2b00e6e3a1
commit
20e7efcd70
|
@ -0,0 +1,53 @@
|
||||||
|
# Generated by Django 3.2.17 on 2023-04-17 06:32
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_platform_automation_id(apps, schema_editor):
|
||||||
|
platform_model = apps.get_model('assets', 'Platform')
|
||||||
|
for platform in platform_model.objects.all():
|
||||||
|
platform._automation_id = platform.automation.id
|
||||||
|
platform.save(update_fields=['_automation_id'])
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_automation_platform(apps, schema_editor):
|
||||||
|
platform_model = apps.get_model('assets', 'Platform')
|
||||||
|
automation_model = apps.get_model('assets', 'PlatformAutomation')
|
||||||
|
platforms = platform_model.objects.all()
|
||||||
|
for platform in platforms:
|
||||||
|
if not platform._automation_id:
|
||||||
|
continue
|
||||||
|
automation = automation_model.objects.filter(id=platform._automation_id).first()
|
||||||
|
if not automation:
|
||||||
|
continue
|
||||||
|
automation.platform = platform
|
||||||
|
automation.save(update_fields=['platform'])
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_null_platform_automation(apps, schema_editor):
|
||||||
|
automation_model = apps.get_model('assets', 'PlatformAutomation')
|
||||||
|
null_platform_automations = automation_model.objects.filter(platform__isnull=True)
|
||||||
|
null_platform_automations.delete()
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
('assets', '0114_baseautomation_params'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='platform',
|
||||||
|
name='_automation_id',
|
||||||
|
field=models.UUIDField(editable=False, null=True),
|
||||||
|
),
|
||||||
|
migrations.RunPython(migrate_platform_automation_id),
|
||||||
|
migrations.RemoveField(model_name='platform', name='automation'),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='platformautomation',
|
||||||
|
name='platform',
|
||||||
|
field=models.OneToOneField(null=True, on_delete=models.deletion.CASCADE,
|
||||||
|
related_name='automation', to='assets.platform'),
|
||||||
|
),
|
||||||
|
migrations.RunPython(migrate_automation_platform),
|
||||||
|
]
|
|
@ -72,6 +72,7 @@ class PlatformAutomation(models.Model):
|
||||||
max_length=32, blank=True, null=True, verbose_name=_("Gather facts method")
|
max_length=32, blank=True, null=True, verbose_name=_("Gather facts method")
|
||||||
)
|
)
|
||||||
gather_accounts_params = models.JSONField(default=dict, verbose_name=_("Gather facts params"))
|
gather_accounts_params = models.JSONField(default=dict, verbose_name=_("Gather facts params"))
|
||||||
|
platform = models.OneToOneField('Platform', on_delete=models.CASCADE, related_name='automation', null=True)
|
||||||
|
|
||||||
|
|
||||||
class Platform(JMSBaseModel):
|
class Platform(JMSBaseModel):
|
||||||
|
@ -99,11 +100,8 @@ class Platform(JMSBaseModel):
|
||||||
# 账号有关的
|
# 账号有关的
|
||||||
su_enabled = models.BooleanField(default=False, verbose_name=_("Su enabled"))
|
su_enabled = models.BooleanField(default=False, verbose_name=_("Su enabled"))
|
||||||
su_method = models.CharField(max_length=32, blank=True, null=True, verbose_name=_("Su method"))
|
su_method = models.CharField(max_length=32, blank=True, null=True, verbose_name=_("Su method"))
|
||||||
automation = models.OneToOneField(
|
|
||||||
PlatformAutomation, on_delete=models.CASCADE, related_name='platform',
|
|
||||||
blank=True, null=True, verbose_name=_("Automation")
|
|
||||||
)
|
|
||||||
custom_fields = models.JSONField(null=True, default=list, verbose_name=_("Custom fields"))
|
custom_fields = models.JSONField(null=True, default=list, verbose_name=_("Custom fields"))
|
||||||
|
_automation_id = models.UUIDField(null=True, editable=False)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def type_constraints(self):
|
def type_constraints(self):
|
||||||
|
|
Loading…
Reference in New Issue