-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#4267] Move migrations to the correct app
- Loading branch information
1 parent
bb43b72
commit 3e39192
Showing
6 changed files
with
163 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...nforms/registrations/contrib/objects_api/migrations/0019_add_default_objects_api_group.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Generated by Django 4.2.11 on 2024-07-02 15:18 | ||
|
||
from django.db import migrations | ||
|
||
from django.db.migrations.state import StateApps | ||
from django.db.backends.base.schema import BaseDatabaseSchemaEditor | ||
|
||
|
||
def add_default_objects_api_group( | ||
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor | ||
) -> None: | ||
FormRegistrationBackend = apps.get_model("forms", "FormRegistrationBackend") | ||
ObjectsAPIGroupConfig = apps.get_model( | ||
"registrations_objects_api", "ObjectsAPIGroupConfig" | ||
) | ||
|
||
objects_api_group_config = ObjectsAPIGroupConfig.objects.order_by("pk").first() | ||
if objects_api_group_config is None: | ||
# Because this migration runs after registrations_objects_api/0017_move_singleton_data, | ||
# Having no Objects API Group means we had no solo config in the first place, thus | ||
# it is safe to assume no Objects API registration backend was set up. | ||
return | ||
|
||
for registration_backend in FormRegistrationBackend.objects.filter( | ||
backend="objects_api" | ||
): | ||
registration_backend.options.setdefault( | ||
"objects_api_group", objects_api_group_config.pk | ||
) | ||
registration_backend.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
( | ||
"registrations_objects_api", | ||
"0018_remove_objectsapiconfig_catalogi_service_and_more", | ||
), | ||
( | ||
"forms", | ||
"0100_add_default_objects_api_group", | ||
), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
add_default_objects_api_group, | ||
migrations.RunPython.noop, | ||
), | ||
] |
41 changes: 41 additions & 0 deletions
41
src/openforms/registrations/contrib/objects_api/migrations/0020_objecttype_url_to_uuid.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Generated by Django 4.2.11 on 2024-07-02 15:21 | ||
|
||
from django.db import migrations | ||
|
||
from django.db.migrations.state import StateApps | ||
from django.db.backends.base.schema import BaseDatabaseSchemaEditor | ||
|
||
|
||
def objecttype_url_to_uuid( | ||
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor | ||
) -> None: | ||
"""Change the objects API registration options to reference the objecttype UUID instead of the URL.""" | ||
|
||
FormRegistrationBackend = apps.get_model("forms", "FormRegistrationBackend") | ||
|
||
for registration_backend in FormRegistrationBackend.objects.filter( | ||
backend="objects_api" | ||
): | ||
|
||
objecttype_url = registration_backend.options.get("objecttype") | ||
if objecttype_url is not None and "/" in objecttype_url: | ||
# If it is `None`, we are dealing with broken confs. and upgrade checks where bypassed. | ||
registration_backend.options["objecttype"] = objecttype_url.rsplit("/", 1)[ | ||
1 | ||
] | ||
registration_backend.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("registrations_objects_api", "0019_add_default_objects_api_group"), | ||
("forms", "0100_add_default_objects_api_group"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
objecttype_url_to_uuid, | ||
migrations.RunPython.noop, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters