mirror of https://github.com/jumpserver/jumpserver
perf: 优化资产迁移,避免冲突
parent
44d7165674
commit
082af029a7
|
@ -34,8 +34,9 @@ def migrate_database_to_asset(apps, *args):
|
|||
_attrs = app.attrs or {}
|
||||
attrs.update(_attrs)
|
||||
|
||||
name = 'DB-{}'.format(app.name)
|
||||
db = db_model(
|
||||
id=app.id, name=app.name, address=attrs['host'],
|
||||
id=app.id, name=name, address=attrs['host'],
|
||||
protocols='{}/{}'.format(app.type, attrs['port']),
|
||||
db_name=attrs['database'] or '',
|
||||
platform=platforms_map[app.type],
|
||||
|
@ -61,8 +62,9 @@ def migrate_cloud_to_asset(apps, *args):
|
|||
for app in applications:
|
||||
attrs = app.attrs
|
||||
print("\t- Create cloud: {}".format(app.name))
|
||||
name = 'Cloud-{}'.format(app.name)
|
||||
cloud = cloud_model(
|
||||
id=app.id, name=app.name,
|
||||
id=app.id, name=name,
|
||||
address=attrs.get('cluster', ''),
|
||||
protocols='k8s/443', platform=platform,
|
||||
org_id=app.org_id,
|
||||
|
|
|
@ -23,6 +23,7 @@ def migrate_app_perms_to_assets(apps, schema_editor):
|
|||
asset_permission = asset_permission_model()
|
||||
for attr in attrs:
|
||||
setattr(asset_permission, attr, getattr(app_perm, attr))
|
||||
asset_permission.name = f"App-{app_perm.name}"
|
||||
asset_permissions.append(asset_permission)
|
||||
asset_permission_model.objects.bulk_create(asset_permissions, ignore_conflicts=True)
|
||||
|
||||
|
|
|
@ -9,11 +9,11 @@ def migrate_system_user_to_accounts(apps, schema_editor):
|
|||
bulk_size = 10000
|
||||
while True:
|
||||
asset_permissions = asset_permission_model.objects \
|
||||
.prefetch_related('system_users')[count:bulk_size]
|
||||
.prefetch_related('system_users')[count:bulk_size]
|
||||
if not asset_permissions:
|
||||
break
|
||||
count += len(asset_permissions)
|
||||
|
||||
count += len(asset_permissions)
|
||||
updated = []
|
||||
for asset_permission in asset_permissions:
|
||||
asset_permission.accounts = [s.username for s in asset_permission.system_users.all()]
|
||||
|
|
Loading…
Reference in New Issue