fix: 修复迁移应用时(组织下只有根节点,同步后的应用资产没有设置节点的问题)

pull/10384/head
Bai 2023-05-04 16:31:55 +08:00 committed by Jiangjie.Bai
parent 9934456af4
commit 22b56d73b6
1 changed files with 13 additions and 5 deletions

View File

@ -20,6 +20,7 @@ def get_prop_name_id(apps, app, category):
def migrate_database_to_asset(apps, *args):
node_model = apps.get_model('assets', 'Node')
app_model = apps.get_model('applications', 'Application')
db_model = apps.get_model('assets', 'Database')
platform_model = apps.get_model('assets', 'Platform')
@ -84,11 +85,18 @@ def create_app_nodes(apps, org_id):
node_keys = node_model.objects.filter(org_id=org_id) \
.filter(key__regex=child_pattern) \
.values_list('key', flat=True)
if not node_keys:
return
node_key_split = [key.split(':') for key in node_keys]
next_value = max([int(k[1]) for k in node_key_split]) + 1
parent_key = node_key_split[0][0]
if node_keys:
node_key_split = [key.split(':') for key in node_keys]
next_value = max([int(k[1]) for k in node_key_split]) + 1
parent_key = node_key_split[0][0]
else:
root_node = node_model.objects.filter(org_id=org_id)\
.filter(parent_key='', key__regex=r'^[0-9]+$').exclude(key__startswith='-').first()
if not root_node:
return
parent_key = root_node.key
next_value = 0
next_key = '{}:{}'.format(parent_key, next_value)
name = 'Apps'
parent = node_model.objects.get(key=parent_key)