From 082af029a7150b9bfa59f7be01d954f907608be0 Mon Sep 17 00:00:00 2001 From: ibuler Date: Mon, 13 Mar 2023 13:56:37 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E8=B5=84=E4=BA=A7?= =?UTF-8?q?=E8=BF=81=E7=A7=BB=EF=BC=8C=E9=81=BF=E5=85=8D=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/migrations/0098_auto_20220430_2126.py | 6 ++++-- apps/perms/migrations/0029_auto_20220728_1728.py | 1 + apps/perms/migrations/0030_auto_20220816_1132.py | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/assets/migrations/0098_auto_20220430_2126.py b/apps/assets/migrations/0098_auto_20220430_2126.py index 89a168316..5fd333262 100644 --- a/apps/assets/migrations/0098_auto_20220430_2126.py +++ b/apps/assets/migrations/0098_auto_20220430_2126.py @@ -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, diff --git a/apps/perms/migrations/0029_auto_20220728_1728.py b/apps/perms/migrations/0029_auto_20220728_1728.py index fce1f43a4..0230e9aff 100644 --- a/apps/perms/migrations/0029_auto_20220728_1728.py +++ b/apps/perms/migrations/0029_auto_20220728_1728.py @@ -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) diff --git a/apps/perms/migrations/0030_auto_20220816_1132.py b/apps/perms/migrations/0030_auto_20220816_1132.py index d6b2710fc..3915b8b1a 100644 --- a/apps/perms/migrations/0030_auto_20220816_1132.py +++ b/apps/perms/migrations/0030_auto_20220816_1132.py @@ -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()]