Skip to content

Commit 655af0a

Browse files
committed
Fix pending trigger events migration error
1 parent f90f9df commit 655af0a

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

ansible_base/rbac/migrations/0004_remote_permissions_additions.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,31 @@
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+
833
class Migration(migrations.Migration):
934

1035
dependencies = [
@@ -175,4 +200,6 @@ class Migration(migrations.Migration):
175200
name='api_slug',
176201
field=models.CharField(default='', help_text='String to use for references to this type from other models in the API.', max_length=201),
177202
),
203+
migrations.RunPython(create_types_and_permissions, migrations.RunPython.noop),
204+
migrations.RunPython(migrate_content_type, migrations.RunPython.noop),
178205
]

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

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,13 @@
33
from django.db import migrations
44

55

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-
316
class Migration(migrations.Migration):
327

338
dependencies = [
349
('dab_rbac', '0004_remote_permissions_additions'),
3510
]
3611

3712
operations = [
38-
migrations.RunPython(create_types_and_permissions, migrations.RunPython.noop),
39-
migrations.RunPython(migrate_content_type, migrations.RunPython.noop),
4013
migrations.RemoveField(
4114
model_name='dabpermission',
4215
name='content_type',

0 commit comments

Comments
 (0)