-
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.
Merge pull request #3554 from open-formulieren/chore/squash-variables…
…-migrations Squash variables migrations
- Loading branch information
Showing
5 changed files
with
141 additions
and
196 deletions.
There are no files selected for viewing
135 changes: 135 additions & 0 deletions
135
src/openforms/variables/migrations/0001_initial_to_openforms_v230.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,135 @@ | ||
# Generated by Django 3.2.21 on 2023-10-24 14:35 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
import openforms.variables.validators | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
replaces = [ | ||
("variables", "0001_add_service_fetch_configuration"), | ||
("variables", "0002_servicefetchconfiguration_name"), | ||
("variables", "0003_servicefetchconfiguration__query_params"), | ||
("variables", "0004_migrate_query_params"), | ||
("variables", "0005_remove_servicefetchconfiguration_query_params"), | ||
( | ||
"variables", | ||
"0006_rename__query_params_servicefetchconfiguration_query_params", | ||
), | ||
("variables", "0007_alter_servicefetchconfiguration_headers"), | ||
("variables", "0008_alter_servicefetchconfiguration_query_params"), | ||
("variables", "0009_servicefetchconfiguration_name"), | ||
("variables", "0010_alter_servicefetchconfiguration_name"), | ||
("variables", "0011_migrate_interpolation_format"), | ||
] | ||
|
||
dependencies = [ | ||
("zgw_consumers", "0016_auto_20220818_1412"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="ServiceFetchConfiguration", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
( | ||
"path", | ||
models.CharField( | ||
blank=True, | ||
default="", | ||
help_text="path relative to the Service API root", | ||
max_length=250, | ||
verbose_name="path", | ||
), | ||
), | ||
( | ||
"method", | ||
models.CharField( | ||
choices=[("GET", "GET"), ("POST", "POST")], | ||
default="GET", | ||
help_text="POST is allowed, but should not be used to mutate data", | ||
max_length=4, | ||
verbose_name="HTTP method", | ||
), | ||
), | ||
( | ||
"headers", | ||
models.JSONField( | ||
blank=True, | ||
default=dict, | ||
help_text="Additions and overrides for the HTTP request headers as defined in the Service.", | ||
validators=[openforms.variables.validators.HeaderValidator()], | ||
verbose_name="HTTP request headers", | ||
), | ||
), | ||
( | ||
"body", | ||
models.JSONField( | ||
blank=True, | ||
help_text='Request body for POST requests (only "application/json" is supported)', | ||
null=True, | ||
verbose_name="HTTP request body", | ||
), | ||
), | ||
( | ||
"data_mapping_type", | ||
models.CharField( | ||
blank=True, | ||
choices=[("JsonLogic", "JsonLogic"), ("jq", "jq")], | ||
default="", | ||
max_length=10, | ||
verbose_name="mapping expression language", | ||
), | ||
), | ||
( | ||
"mapping_expression", | ||
models.JSONField( | ||
blank=True, | ||
help_text="For jq, pass a string containing the filter expression", | ||
null=True, | ||
verbose_name="mapping expression", | ||
), | ||
), | ||
( | ||
"service", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.PROTECT, | ||
to="zgw_consumers.service", | ||
verbose_name="service", | ||
), | ||
), | ||
( | ||
"name", | ||
models.CharField( | ||
help_text="human readable name for the configuration", | ||
max_length=250, | ||
), | ||
), | ||
( | ||
"query_params", | ||
models.JSONField( | ||
blank=True, | ||
default=dict, | ||
validators=[ | ||
openforms.variables.validators.QueryParameterValidator() | ||
], | ||
verbose_name="HTTP query string", | ||
), | ||
), | ||
], | ||
options={ | ||
"verbose_name": "service fetch configuration", | ||
"verbose_name_plural": "service fetch configurations", | ||
}, | ||
), | ||
] |
33 changes: 2 additions & 31 deletions
33
src/openforms/variables/migrations/0004_migrate_query_params.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 |
---|---|---|
@@ -1,42 +1,13 @@ | ||
# Generated by Django 3.2.18 on 2023-03-13 15:38 | ||
|
||
from urllib.parse import parse_qs, urlencode | ||
|
||
from django.db import migrations | ||
|
||
|
||
def migrate_query_params_to_jsonfield(apps, _): | ||
ServiceFetchConfiguration = apps.get_model("variables", "ServiceFetchConfiguration") | ||
|
||
for config in ServiceFetchConfiguration.objects.all(): | ||
if config.query_params: | ||
config._query_params = parse_qs( | ||
config.query_params[1:] | ||
if config.query_params.startswith("?") | ||
else config.query_params | ||
) | ||
else: | ||
config._query_params = {} | ||
config.save() | ||
|
||
|
||
def migrate_query_params_to_textfield(apps, _): | ||
ServiceFetchConfiguration = apps.get_model("variables", "ServiceFetchConfiguration") | ||
|
||
for config in ServiceFetchConfiguration.objects.all(): | ||
if config._query_params: | ||
config.query_params = f"?{urlencode(config._query_params, doseq=True)}" | ||
config.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("variables", "0003_servicefetchconfiguration__query_params"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
migrate_query_params_to_jsonfield, migrate_query_params_to_textfield | ||
) | ||
] | ||
# data migration removed, as these have been executed on Open Forms 2.3.0+ | ||
operations = [] |
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
39 changes: 2 additions & 37 deletions
39
src/openforms/variables/migrations/0011_migrate_interpolation_format.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 |
---|---|---|
@@ -1,48 +1,13 @@ | ||
# Generated by Django 3.2.18 on 2023-03-28 12:35 | ||
|
||
import re | ||
|
||
from django.db import migrations | ||
|
||
MATCH_SINGLE_BRACKETS = r"{([A-z0-9_\.]*)}" | ||
REPL_SINGLE_BRACKETS = r"{{\1}}" | ||
|
||
|
||
def apply_regex_nested(data, pattern, repl): | ||
if isinstance(data, dict): | ||
for key, value in data.items(): | ||
data[key] = apply_regex_nested(value, pattern, repl) | ||
elif isinstance(data, list): | ||
data = [apply_regex_nested(value, pattern, repl) for value in data] | ||
elif isinstance(data, str): | ||
return re.sub(pattern, repl, data) | ||
return data | ||
|
||
|
||
def forwards(apps, _): | ||
ServiceFetchConfiguration = apps.get_model("variables", "ServiceFetchConfiguration") | ||
|
||
for config in ServiceFetchConfiguration.objects.all(): | ||
if config.body: | ||
config.body = apply_regex_nested( | ||
config.body, MATCH_SINGLE_BRACKETS, REPL_SINGLE_BRACKETS | ||
) | ||
if config.headers: | ||
config.headers = apply_regex_nested( | ||
config.headers, MATCH_SINGLE_BRACKETS, REPL_SINGLE_BRACKETS | ||
) | ||
if config.query_params: | ||
config.query_params = apply_regex_nested( | ||
config.query_params, MATCH_SINGLE_BRACKETS, REPL_SINGLE_BRACKETS | ||
) | ||
|
||
config.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("variables", "0010_alter_servicefetchconfiguration_name"), | ||
] | ||
|
||
operations = [migrations.RunPython(forwards, migrations.RunPython.noop)] | ||
# data migration removed, as these have been executed on Open Forms 2.3.0+ | ||
operations = [] |
This file was deleted.
Oops, something went wrong.