-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1266 from maykinmedia/tasks/2569-persist-service-…
…on-zgw-configs Persist the source service when syncing CatalogusConfig
- Loading branch information
Showing
6 changed files
with
169 additions
and
2 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
69 changes: 69 additions & 0 deletions
69
src/open_inwoner/openzaak/migrations/0052_add_catalogusconfig_service.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,69 @@ | ||
# Generated by Django 4.2.11 on 2024-06-19 12:35 | ||
|
||
import django.db.models.deletion | ||
from django.core.exceptions import MultipleObjectsReturned | ||
from django.db import DataError, migrations, models | ||
|
||
|
||
def migrate_catalogus_config_service_field_from_default(apps, schema_editor): | ||
CatalogusConfig = apps.get_model("openzaak", "CatalogusConfig") | ||
ZGWApiGroupConfig = apps.get_model("openzaak", "ZGWApiGroupConfig") | ||
|
||
if not CatalogusConfig.objects.all().exists(): | ||
return | ||
|
||
try: | ||
config = ZGWApiGroupConfig.objects.all().get() | ||
except MultipleObjectsReturned: | ||
raise DataError( | ||
"Attempted to set CatalogusConfig.service using ZGWApiGroupConfig, but there" | ||
" are multiple instances configured. Please (temporarily) ensure you have only" | ||
" a single ZGWApiGroupConfig configured, then run this migration again." | ||
) | ||
|
||
for catalogus_config in CatalogusConfig.objects.all(): | ||
catalogus_config.service = config.ztc_service | ||
catalogus_config.save() | ||
|
||
|
||
def reverse_migrate_catalogus_config_service_field_from_default(apps, schema_editor): | ||
CatalogusConfig = apps.get_model("openzaak", "CatalogusConfig") | ||
CatalogusConfig.objects.all().update(service=None) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("zgw_consumers", "0019_alter_service_uuid"), | ||
("openzaak", "0051_drop_root_zgw_fields"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="catalogusconfig", | ||
name="service", | ||
field=models.ForeignKey( | ||
limit_choices_to={"api_type": "ztc"}, | ||
null=True, | ||
on_delete=django.db.models.deletion.PROTECT, | ||
related_name="catalogus_configs", | ||
to="zgw_consumers.service", | ||
verbose_name="Form API", | ||
), | ||
), | ||
migrations.RunPython( | ||
migrate_catalogus_config_service_field_from_default, | ||
reverse_code=reverse_migrate_catalogus_config_service_field_from_default, | ||
), | ||
migrations.AlterField( | ||
model_name="catalogusconfig", | ||
name="service", | ||
field=models.ForeignKey( | ||
limit_choices_to={"api_type": "ztc"}, | ||
on_delete=django.db.models.deletion.PROTECT, | ||
related_name="catalogus_configs", | ||
to="zgw_consumers.service", | ||
verbose_name="Catalogus API", | ||
), | ||
), | ||
] |
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
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