-
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.
[#2526] Allow for 0..n ZGW API groups to be configured
This is a first step towards allowing multiple ZGW backends throughout the platform. To maintain backwards compatibility with the current datamodel, we proxy the current service config fields to the new ZGWApiGroupConfig model as we work our way towards making all ZGW client invocations multi-backend aware.
- Loading branch information
1 parent
54f2d72
commit caca0df
Showing
6 changed files
with
361 additions
and
43 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
91 changes: 91 additions & 0 deletions
91
src/open_inwoner/openzaak/migrations/0049_add_multiple_zgw_backends_config.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,91 @@ | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("zgw_consumers", "0019_alter_service_uuid"), | ||
("openzaak", "0047_delete_statustranslation"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="ZGWApiGroupConfig", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
( | ||
"name", | ||
models.CharField( | ||
help_text="A recognisable name for this set of ZGW APIs.", | ||
max_length=255, | ||
verbose_name="name", | ||
), | ||
), | ||
( | ||
"drc_service", | ||
models.ForeignKey( | ||
limit_choices_to={"api_type": "drc"}, | ||
null=True, | ||
on_delete=django.db.models.deletion.PROTECT, | ||
related_name="zgwset_drc_config", | ||
to="zgw_consumers.service", | ||
verbose_name="Documenten API", | ||
), | ||
), | ||
( | ||
"form_service", | ||
models.OneToOneField( | ||
limit_choices_to={"api_type": "orc"}, | ||
null=True, | ||
on_delete=django.db.models.deletion.PROTECT, | ||
related_name="zgwset_orc_form_config", | ||
to="zgw_consumers.service", | ||
verbose_name="Form API", | ||
), | ||
), | ||
( | ||
"open_zaak_config", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.PROTECT, | ||
related_name="api_groups", | ||
to="openzaak.openzaakconfig", | ||
), | ||
), | ||
( | ||
"zrc_service", | ||
models.ForeignKey( | ||
limit_choices_to={"api_type": "zrc"}, | ||
null=True, | ||
on_delete=django.db.models.deletion.PROTECT, | ||
related_name="zgwset_zrc_config", | ||
to="zgw_consumers.service", | ||
verbose_name="Zaken API", | ||
), | ||
), | ||
( | ||
"ztc_service", | ||
models.ForeignKey( | ||
limit_choices_to={"api_type": "ztc"}, | ||
null=True, | ||
on_delete=django.db.models.deletion.PROTECT, | ||
related_name="zgwset_ztc_config", | ||
to="zgw_consumers.service", | ||
verbose_name="Catalogi API", | ||
), | ||
), | ||
], | ||
options={ | ||
"verbose_name": "ZGW API set", | ||
"verbose_name_plural": "ZGW API sets", | ||
}, | ||
), | ||
] |
55 changes: 55 additions & 0 deletions
55
src/open_inwoner/openzaak/migrations/0050_migrate_zgw_root_fields_to_multi_backend.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,55 @@ | ||
import logging | ||
from django.db import migrations | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def migrate_zgw_service_config_to_default_group_config(apps, schema_editor): | ||
ZGWApiGroupConfig = apps.get_model("openzaak", "ZGWApiGroupConfig") | ||
OpenZaakConfig = apps.get_model("openzaak", "OpenZaakConfig") | ||
|
||
for config in OpenZaakConfig.objects.all(): | ||
# OpenZaakConfig.objects.select_for_update().get(pk=config.pk) # Lock | ||
ZGWApiGroupConfig.objects.create( | ||
name="Migrated default config", | ||
zrc_service=config.zaak_service, | ||
drc_service=config.document_service, | ||
ztc_service=config.catalogi_service, | ||
form_service=config.form_service, | ||
open_zaak_config=config, | ||
) | ||
|
||
|
||
def reverse_migrate_zgw_service_config_to_default_group_config(apps, schema_editor): | ||
OpenZaakConfig = apps.get_model("openzaak", "OpenZaakConfig") | ||
|
||
for config in OpenZaakConfig.objects.all(): | ||
if config.api_groups.count() == 0: | ||
continue | ||
|
||
if config.api_groups.count() > 1: | ||
logger.warning("Multiple API groups to choose from, picking first") | ||
|
||
group_config = config.api_groups.first() | ||
config.zaak_service = group_config.zrc_service | ||
config.document_service = group_config.drc_service | ||
config.catalogi_service = group_config.ztc_service | ||
config.form_service = group_config.form_service | ||
config.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("zgw_consumers", "0019_alter_service_uuid"), | ||
("openzaak", "0049_add_multiple_zgw_backends_config"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
migrate_zgw_service_config_to_default_group_config, | ||
reverse_code=reverse_migrate_zgw_service_config_to_default_group_config, | ||
atomic=True, | ||
), | ||
] |
34 changes: 34 additions & 0 deletions
34
src/open_inwoner/openzaak/migrations/0051_drop_root_zgw_fields.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,34 @@ | ||
# Generated by Django 4.2.11 on 2024-06-04 10:02 | ||
|
||
import logging | ||
from django.db import migrations | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("zgw_consumers", "0019_alter_service_uuid"), | ||
("openzaak", "0050_migrate_zgw_root_fields_to_multi_backend"), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name="openzaakconfig", | ||
name="catalogi_service", | ||
), | ||
migrations.RemoveField( | ||
model_name="openzaakconfig", | ||
name="document_service", | ||
), | ||
migrations.RemoveField( | ||
model_name="openzaakconfig", | ||
name="form_service", | ||
), | ||
migrations.RemoveField( | ||
model_name="openzaakconfig", | ||
name="zaak_service", | ||
), | ||
] |
Oops, something went wrong.