diff --git a/apps/applications/migrations/0006_application.py b/apps/applications/migrations/0006_application.py index 2ff518883..fbe629873 100644 --- a/apps/applications/migrations/0006_application.py +++ b/apps/applications/migrations/0006_application.py @@ -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): diff --git a/apps/perms/migrations/0016_applicationpermission.py b/apps/perms/migrations/0016_applicationpermission.py index d11162b3d..640022c6b 100644 --- a/apps/perms/migrations/0016_applicationpermission.py +++ b/apps/perms/migrations/0016_applicationpermission.py @@ -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)