From 00fd546776b001892ac8e2db0a68e02981b55a70 Mon Sep 17 00:00:00 2001 From: feng <1304903146@qq.com> Date: Thu, 13 Apr 2023 20:54:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=86=B2=E7=AA=81bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrations/0113_auto_20230411_1814.py | 66 ------------------- .../migrations/0114_baseautomation_params.py | 57 +++++++++++++++- 2 files changed, 55 insertions(+), 68 deletions(-) delete mode 100644 apps/assets/migrations/0113_auto_20230411_1814.py diff --git a/apps/assets/migrations/0113_auto_20230411_1814.py b/apps/assets/migrations/0113_auto_20230411_1814.py deleted file mode 100644 index 58fd2fa92..000000000 --- a/apps/assets/migrations/0113_auto_20230411_1814.py +++ /dev/null @@ -1,66 +0,0 @@ -# Generated by Django 3.2.16 on 2023-04-11 10:14 - -from django.db import migrations, models - -from assets.const import AllTypes - - -def migrate_automation_push_account_params(apps, schema_editor): - platform_automation_model = apps.get_model('assets', 'PlatformAutomation') - platform_automation_methods = AllTypes.get_automation_methods() - methods_id_data_map = { - i['id']: None if i['params_serializer'] is None else i['params_serializer']({}).data - for i in platform_automation_methods - if i['method'] == 'push_account' - } - automation_objs = [] - for automation in platform_automation_model.objects.all(): - push_account_method = automation.push_account_method - if not push_account_method: - continue - value = methods_id_data_map.get(push_account_method) - if value is None: - continue - automation.push_account_params = value - automation_objs.append(automation) - platform_automation_model.objects.bulk_update(automation_objs, ['push_account_params']) - - -class Migration(migrations.Migration): - dependencies = [ - ('assets', '0112_auto_20230404_1631'), - ] - - operations = [ - migrations.AddField( - model_name='platformautomation', - name='change_secret_params', - field=models.JSONField(default=dict, verbose_name='Change secret params'), - ), - migrations.AddField( - model_name='platformautomation', - name='gather_accounts_params', - field=models.JSONField(default=dict, verbose_name='Gather facts params'), - ), - migrations.AddField( - model_name='platformautomation', - name='gather_facts_params', - field=models.JSONField(default=dict, verbose_name='Gather facts params'), - ), - migrations.AddField( - model_name='platformautomation', - name='ping_params', - field=models.JSONField(default=dict, verbose_name='Ping params'), - ), - migrations.AddField( - model_name='platformautomation', - name='push_account_params', - field=models.JSONField(default=dict, verbose_name='Push account params'), - ), - migrations.AddField( - model_name='platformautomation', - name='verify_account_params', - field=models.JSONField(default=dict, verbose_name='Verify account params'), - ), - migrations.RunPython(migrate_automation_push_account_params), - ] diff --git a/apps/assets/migrations/0114_baseautomation_params.py b/apps/assets/migrations/0114_baseautomation_params.py index 2e6d87f8e..857c5d795 100644 --- a/apps/assets/migrations/0114_baseautomation_params.py +++ b/apps/assets/migrations/0114_baseautomation_params.py @@ -2,11 +2,33 @@ from django.db import migrations, models +from assets.const import AllTypes + + +def migrate_automation_push_account_params(apps, schema_editor): + platform_automation_model = apps.get_model('assets', 'PlatformAutomation') + platform_automation_methods = AllTypes.get_automation_methods() + methods_id_data_map = { + i['id']: None if i['params_serializer'] is None else i['params_serializer']({}).data + for i in platform_automation_methods + if i['method'] == 'push_account' + } + automation_objs = [] + for automation in platform_automation_model.objects.all(): + push_account_method = automation.push_account_method + if not push_account_method: + continue + value = methods_id_data_map.get(push_account_method) + if value is None: + continue + automation.push_account_params = value + automation_objs.append(automation) + platform_automation_model.objects.bulk_update(automation_objs, ['push_account_params']) + class Migration(migrations.Migration): - dependencies = [ - ('assets', '0113_auto_20230411_1814'), + ('assets', '0113_auto_20230411_1917'), ] operations = [ @@ -15,4 +37,35 @@ class Migration(migrations.Migration): name='params', field=models.JSONField(default=dict, verbose_name='Params'), ), + migrations.AddField( + model_name='platformautomation', + name='change_secret_params', + field=models.JSONField(default=dict, verbose_name='Change secret params'), + ), + migrations.AddField( + model_name='platformautomation', + name='gather_accounts_params', + field=models.JSONField(default=dict, verbose_name='Gather facts params'), + ), + migrations.AddField( + model_name='platformautomation', + name='gather_facts_params', + field=models.JSONField(default=dict, verbose_name='Gather facts params'), + ), + migrations.AddField( + model_name='platformautomation', + name='ping_params', + field=models.JSONField(default=dict, verbose_name='Ping params'), + ), + migrations.AddField( + model_name='platformautomation', + name='push_account_params', + field=models.JSONField(default=dict, verbose_name='Push account params'), + ), + migrations.AddField( + model_name='platformautomation', + name='verify_account_params', + field=models.JSONField(default=dict, verbose_name='Verify account params'), + ), + migrations.RunPython(migrate_automation_push_account_params), ]