feat(applications): 修改应用/应用授权的迁移文件,解决多种应用/应用授权name字段重复的问题

pull/4886/head
Bai 2020-10-27 16:42:53 +08:00 committed by 老广
parent ca2fc3cb5e
commit 038582a8c1
2 changed files with 8 additions and 5 deletions

View File

@ -102,10 +102,10 @@ def migrate_and_integrate_applications(apps, schema_editor):
for application_json in applications_json
if application_json['category'] in CATEGORY_LIST
]
applications_created = application_model.objects.bulk_create(applications)
print('Migrate and integrate applications count: {}/{}'.format(
len(applications_created), len(applications_json)
))
for application in applications:
if application_model.objects.using(db_alias).filter(name=application.name).exists():
application.name = '{}-{}'.format(application.name, application.type)
application.save()
class Migration(migrations.Migration):

View File

@ -156,7 +156,10 @@ def migrate_and_integrate_application_permissions(apps, schema_editor):
]
# create
new_app_perm_model.objects.using(db_alias).bulk_create(new_app_perm_objects)
for new_app_perm_object in new_app_perm_objects:
if new_app_perm_model.objects.using(db_alias).filter(name=new_app_perm_object.name).exists():
new_app_perm_object.name = '{}-{}'.format(new_app_perm_object.name, str(new_app_perm_object.id)[:4])
new_app_perm_object.save()
new_app_perm_relation_app_model.objects.using(db_alias).bulk_create(new_app_perm_relation_app_objects)
new_app_perm_relation_system_user_model.objects.using(db_alias).bulk_create(new_app_perm_relation_system_user_objects)
new_app_perm_relation_user_group_model.objects.using(db_alias).bulk_create(new_app_perm_relation_user_group_objects)