|
3 | 3 | from django.db import migrations |
4 | 4 |
|
5 | 5 |
|
6 | | -def create_types_and_permissions(apps, schema_editor): |
| 6 | +def create_types_if_needed(apps, schema_editor): |
7 | 7 | """Before we can migrate to the new DABContentType, entries in that table must be created. |
8 | 8 |
|
9 | 9 | This method runs what is ordinarily the post_migrate logic, but in the migration case here. |
| 10 | + Only needed in the upgrade case, otherwise better to run at true post-migrate. |
10 | 11 | """ |
11 | | - from ansible_base.rbac.management import create_dab_permissions |
| 12 | + permission_cls = apps.get_model('dab_rbac', 'DABPermission') |
| 13 | + rd_cls = permission_cls = apps.get_model('dab_rbac', 'RoleDefinition') |
| 14 | + if permission_cls.objects.exists() or rd_cls.objects.exists(): |
| 15 | + from ansible_base.rbac.management.create_types import create_DAB_contenttypes |
12 | 16 |
|
13 | | - create_dab_permissions(apps.get_app_config('dab_rbac'), apps=apps) |
| 17 | + create_DAB_contenttypes(apps=apps) |
14 | 18 |
|
15 | 19 |
|
16 | 20 | def migrate_content_type(apps, schema_editor): |
@@ -48,6 +52,6 @@ class Migration(migrations.Migration): |
48 | 52 | ] |
49 | 53 |
|
50 | 54 | operations = [ |
51 | | - migrations.RunPython(create_types_and_permissions, migrations.RunPython.noop), |
| 55 | + migrations.RunPython(create_types_if_needed, migrations.RunPython.noop), |
52 | 56 | migrations.RunPython(migrate_content_type, migrations.RunPython.noop), |
53 | 57 | ] |
0 commit comments