Skip to content

Commit ac61e35

Browse files
committedJan 20, 2025
Add prepare prepare_for_update for role migration
1 parent e12d458 commit ac61e35

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed
 

‎rbac/migration_tool/migrate.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,19 @@ def migrate_roles_for_tenant(tenant, exclude_apps, replicator):
7878
roles = roles.exclude(access__permission__application__in=exclude_apps)
7979

8080
for role in roles:
81-
logger.info(f"Migrating role: {role.name} with UUID {role.uuid}.")
82-
81+
# The migrator deals with concurrency control and roles needs to be locked.
8382
with transaction.atomic():
83+
logger.info(f"Migrating role: {role.name} with UUID {role.uuid}.")
84+
# Requery and lock role
8485
role = Role.objects.select_for_update().get(pk=role.pk)
8586
dual_write_handler = RelationApiDualWriteHandler(
8687
role, ReplicationEventType.MIGRATE_CUSTOM_ROLE, replicator
8788
)
88-
89+
dual_write_handler.prepare_for_update()
8990
dual_write_handler.replicate_new_or_updated_role(role)
90-
91+
# End of transaction, locks on role is released.
9192
logger.info(f"Migration completed for role: {role.name} with UUID {role.uuid}.")
93+
9294
logger.info(f"Migrated {roles.count()} roles for tenant: {tenant.org_id}")
9395

9496

0 commit comments

Comments
 (0)