Skip to content

Commit 27f27a5

Browse files
committed
Clear RBAC data in intermediate step
1 parent a4e709a commit 27f27a5

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

ansible_ai_connect/main/settings/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"import_export",
8080
"ansible_base.resource_registry",
8181
"ansible_base.jwt_consumer",
82+
"ansible_base.rbac",
8283
]
8384

8485
MIDDLEWARE = [

ansible_ai_connect/organizations/migrations/0005_organization.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,35 @@
1-
# Generated manually to create new Organization model
1+
# Generated manually to create new Organization model and clear dab_rbac data
22

33
from django.db import migrations, models
44

55

6+
def clear_dab_rbac_data(apps, schema_editor):
7+
"""Delete all entries from dab_rbac models"""
8+
db_alias = schema_editor.connection.alias
9+
10+
# Get all dab_rbac models
11+
from django.apps import apps as django_apps
12+
dab_rbac_config = django_apps.get_app_config('dab_rbac')
13+
14+
# Delete all data from dab_rbac models in reverse dependency order
15+
for model in reversed(dab_rbac_config.get_models()):
16+
model.objects.using(db_alias).all().delete()
17+
18+
19+
def reverse_clear_dab_rbac_data(apps, schema_editor):
20+
"""Reverse operation - no-op since we can't restore deleted data"""
21+
pass
22+
23+
624
class Migration(migrations.Migration):
725

826
dependencies = [
927
("organizations", "0004_organization_enable_anonymization"),
28+
("dab_rbac", "0004_remote_permissions_additions"),
29+
]
30+
31+
run_before = [
32+
("dab_rbac", "0005_remote_permissions_data"),
1033
]
1134

1235
operations = [
@@ -29,4 +52,8 @@ class Migration(migrations.Migration):
2952
"ordering": ["id"],
3053
},
3154
),
55+
migrations.RunPython(
56+
clear_dab_rbac_data,
57+
reverse_clear_dab_rbac_data,
58+
),
3259
]

0 commit comments

Comments
 (0)