Skip to content

Commit 662d89b

Browse files
committed
Split out into 4 migrations
1 parent cde9eda commit 662d89b

File tree

4 files changed

+42
-29
lines changed

4 files changed

+42
-29
lines changed

ansible_base/rbac/migrations/0004_remote_permissions_additions.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,6 @@
55
from django.db import migrations, models
66

77

8-
def create_types_and_permissions(apps, schema_editor):
9-
"""Before we can migrate to the new DABContentType, entries in that table must be created.
10-
11-
This method runs what is ordinarily the post_migrate logic, but in the migration case here.
12-
"""
13-
from ansible_base.rbac.management import create_dab_permissions
14-
15-
create_dab_permissions(apps.get_app_config('dab_rbac'), apps=apps)
16-
17-
18-
def migrate_content_type(apps, schema_editor):
19-
ct_cls = apps.get_model('dab_rbac', 'DABContentType')
20-
ct_cls.objects.clear_cache()
21-
for model_name in ('dabpermission', 'objectrole', 'roledefinition', 'roleuserassignment', 'roleteamassignment'):
22-
cls = apps.get_model('dab_rbac', model_name)
23-
for obj in cls.objects.all():
24-
old_ct = obj.content_type
25-
# NOTE: could give duplicate normally, but that is impossible in migration path
26-
obj.new_content_type = ct_cls.objects.get_by_natural_key(old_ct.app_label, old_ct.model)
27-
obj.save()
28-
for model_name in ('roleevaluation', 'roleevaluationuuid'):
29-
cls = apps.get_model('dab_rbac', model_name)
30-
cls.objects.all().delete()
31-
32-
338
class Migration(migrations.Migration):
349

3510
dependencies = [
@@ -200,6 +175,4 @@ class Migration(migrations.Migration):
200175
name='api_slug',
201176
field=models.CharField(default='', help_text='String to use for references to this type from other models in the API.', max_length=201),
202177
),
203-
migrations.RunPython(create_types_and_permissions, migrations.RunPython.noop),
204-
migrations.RunPython(migrate_content_type, migrations.RunPython.noop),
205178
]
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Generated by Django 4.2.23 on 2025-06-30 12:48
2+
3+
from django.db import migrations
4+
5+
6+
def create_types_and_permissions(apps, schema_editor):
7+
"""Before we can migrate to the new DABContentType, entries in that table must be created.
8+
9+
This method runs what is ordinarily the post_migrate logic, but in the migration case here.
10+
"""
11+
from ansible_base.rbac.management import create_dab_permissions
12+
13+
create_dab_permissions(apps.get_app_config('dab_rbac'), apps=apps)
14+
15+
16+
def migrate_content_type(apps, schema_editor):
17+
ct_cls = apps.get_model('dab_rbac', 'DABContentType')
18+
ct_cls.objects.clear_cache()
19+
for model_name in ('dabpermission', 'objectrole', 'roledefinition', 'roleuserassignment', 'roleteamassignment'):
20+
cls = apps.get_model('dab_rbac', model_name)
21+
for obj in cls.objects.all():
22+
old_ct = obj.content_type
23+
# NOTE: could give duplicate normally, but that is impossible in migration path
24+
obj.new_content_type = ct_cls.objects.get_by_natural_key(old_ct.app_label, old_ct.model)
25+
obj.save()
26+
for model_name in ('roleevaluation', 'roleevaluationuuid'):
27+
cls = apps.get_model('dab_rbac', model_name)
28+
cls.objects.all().delete()
29+
30+
31+
class Migration(migrations.Migration):
32+
33+
dependencies = [
34+
('dab_rbac', '0004_remote_permissions_additions'),
35+
]
36+
37+
operations = [
38+
migrations.RunPython(create_types_and_permissions, migrations.RunPython.noop),
39+
migrations.RunPython(migrate_content_type, migrations.RunPython.noop),
40+
]

ansible_base/rbac/migrations/0005_remote_permissions_removals.py renamed to ansible_base/rbac/migrations/0006_remote_permissions_removals.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
class Migration(migrations.Migration):
77

88
dependencies = [
9-
('dab_rbac', '0004_remote_permissions_additions'),
9+
('dab_rbac', '0005_remote_permissions_data'),
1010
]
1111

1212
operations = [

ansible_base/rbac/migrations/0006_remote_permissions_cleanup.py renamed to ansible_base/rbac/migrations/0007_remote_permissions_cleanup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
class Migration(migrations.Migration):
77

88
dependencies = [
9-
('dab_rbac', '0005_remote_permissions_removals'),
9+
('dab_rbac', '0006_remote_permissions_removals'),
1010
]
1111

1212
operations = [

0 commit comments

Comments
 (0)