mirror of
https://github.com/ansible/awx.git
synced 2026-03-17 17:07:33 -02:30
Add output of the update and deletion counts to fix.py
This commit is contained in:
@@ -125,16 +125,24 @@ sys.stderr.write('===================================\n')
|
|||||||
|
|
||||||
|
|
||||||
print(f"""\
|
print(f"""\
|
||||||
|
from collections import Counter
|
||||||
|
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
|
||||||
from awx.main.models.rbac import Role
|
from awx.main.models.rbac import Role
|
||||||
|
|
||||||
|
|
||||||
|
delete_counts = Counter()
|
||||||
|
update_counts = Counter()
|
||||||
|
|
||||||
""")
|
""")
|
||||||
|
|
||||||
print("# Role objects that are assigned to objects that do not exist")
|
print("# Role objects that are assigned to objects that do not exist")
|
||||||
for r in orphaned_roles:
|
for r in orphaned_roles:
|
||||||
print(f"Role.objects.filter(id={r}).update(object_id=None)")
|
print(f"c = Role.objects.filter(id={r}).update(object_id=None)")
|
||||||
print(f"Role.objects.filter(id={r}).delete()")
|
print("update_counts.update({'main.Role': c})")
|
||||||
|
print(f"_, c = Role.objects.filter(id={r}).delete()")
|
||||||
|
print("delete_counts.update(c)")
|
||||||
|
|
||||||
|
|
||||||
print("\n")
|
print("\n")
|
||||||
@@ -145,13 +153,17 @@ print("queue = []\n")
|
|||||||
for ct, objs in crosslinked.items():
|
for ct, objs in crosslinked.items():
|
||||||
print(f"cls = ContentType.objects.get(id={ct}).model_class()\n")
|
print(f"cls = ContentType.objects.get(id={ct}).model_class()\n")
|
||||||
for obj, kv in objs.items():
|
for obj, kv in objs.items():
|
||||||
print(f"cls.objects.filter(id={obj}).update(**{kv!r})")
|
print(f"c = cls.objects.filter(id={obj}).update(**{kv!r})")
|
||||||
|
print("update_counts.update({repr(cls): c})")
|
||||||
print(f"queue.append((cls, {obj}))")
|
print(f"queue.append((cls, {obj}))")
|
||||||
|
|
||||||
for child, parents in crosslinked_parents.items():
|
for child, parents in crosslinked_parents.items():
|
||||||
print(f"\n\nr = Role.objects.get(id={child})")
|
print(f"\n\nr = Role.objects.get(id={child})")
|
||||||
print(f"r.parents.remove(*Role.objects.filter(id__in={parents!r}))")
|
print(f"r.parents.remove(*Role.objects.filter(id__in={parents!r}))")
|
||||||
|
|
||||||
|
print('print("Objects deleted:", delete_counts)')
|
||||||
|
print('print("Objects updated:", update_counts)')
|
||||||
|
|
||||||
print(f"\n\nfor cls, obj_id in queue:")
|
print(f"\n\nfor cls, obj_id in queue:")
|
||||||
print(f" obj = cls.objects.get(id=obj_id)")
|
print(f" obj = cls.objects.get(id=obj_id)")
|
||||||
print(f" obj.save()")
|
print(f" obj.save()")
|
||||||
|
|||||||
Reference in New Issue
Block a user