Skip to content

Commit

Permalink
[#2617] Fix migrations for digid-eherkenning-generics
Browse files Browse the repository at this point in the history
    - Various models for digid-eherkenning-generics have the wrong
      database tables associated due to renaming of the app label
      before the migrations.
  • Loading branch information
pi-sigma committed Oct 3, 2024
1 parent 7d70386 commit 24f33c9
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by Django 4.2.11 on 2024-07-07 13:44

from django.db import migrations, models
from django.db import migrations


class Migration(migrations.Migration):
Expand All @@ -9,23 +9,15 @@ class Migration(migrations.Migration):
("digid_eherkenning_oidc_generics_legacy", "0001_legacy"),
]

operations = [
migrations.AddField(
model_name="openidconnectdigidconfig",
name="oidc_token_use_basic_auth",
field=models.BooleanField(
default=False,
help_text="If enabled, the client ID and secret are sent in the HTTP Basic auth header when obtaining the access token. Otherwise, they are sent in the request body.",
verbose_name="Use Basic auth for token endpoint",
),
),
migrations.AddField(
model_name="openidconnecteherkenningconfig",
name="oidc_token_use_basic_auth",
field=models.BooleanField(
default=False,
help_text="If enabled, the client ID and secret are sent in the HTTP Basic auth header when obtaining the access token. Otherwise, they are sent in the request body.",
verbose_name="Use Basic auth for token endpoint",
),
),
]
# models have the wrong db_table associated
query1 = """
ALTER TABLE "digid_eherkenning_oidc_generics_legacy_openidconnectdigidconfig" ADD COLUMN "oidc_token_use_basic_auth" boolean DEFAULT false NOT NULL;
ALTER TABLE "digid_eherkenning_oidc_generics_legacy_openidconnectdigidconfig" ALTER COLUMN "oidc_token_use_basic_auth" DROP DEFAULT;
"""

query2 = """
ALTER TABLE "digid_eherkenning_oidc_generics_legacy_openidconnecteherkenningconfig" ADD COLUMN "oidc_token_use_basic_auth" boolean DEFAULT false NOT NULL;
ALTER TABLE "digid_eherkenning_oidc_generics_legacy_openidconnecteherkenningconfig" ALTER COLUMN "oidc_token_use_basic_auth" DROP DEFAULT;
"""

operations = [migrations.RunSQL(query1), migrations.RunSQL(query2)]
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,22 @@ class Migration(migrations.Migration):
verbose_name="URLs exempt from session renewal",
),
),
migrations.AddField(
model_name="openidconnectdigidconfig",
name="oidc_token_use_basic_auth",
field=models.BooleanField(
default=False,
help_text="If enabled, the client ID and secret are sent in the HTTP Basic auth header when obtaining the access token. Otherwise, they are sent in the request body.",
verbose_name="Use Basic auth for token endpoint",
),
),
migrations.AddField(
model_name="openidconnecteherkenningconfig",
name="oidc_token_use_basic_auth",
field=models.BooleanField(
default=False,
help_text="If enabled, the client ID and secret are sent in the HTTP Basic auth header when obtaining the access token. Otherwise, they are sent in the request body.",
verbose_name="Use Basic auth for token endpoint",
),
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,17 @@ class Migration(migrations.Migration):
table="digid_eherkenning_oidc_generics_legacy_openidconnecteherkenningconfig",
),
]

# models have the wrong db_table associated
query1 = """
ALTER TABLE "digid_eherkenning_oidc_generics_openidconnectdigidconfig"
RENAME TO "digid_eherkenning_oidc_generics_legacy_openidconnectdigidconfig";
"""

query2 = """
ALTER TABLE "digid_eherkenning_oidc_generics_openidconnecteherkenningconfig"
RENAME TO "digid_eherkenning_oidc_generics_legacy_openidconnecteherkenningconfig";
"""

operations = [migrations.RunSQL(query1), migrations.RunSQL(query2)]
operations = []
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ class Migration(migrations.Migration):
),
]

operations = [
migrations.AlterModelTable(
name="openidconnectdigidconfig",
table="digid_eherkenning_oidc_generics_openidconnectdigidconfig",
),
migrations.AlterModelTable(
name="openidconnecteherkenningconfig",
table="digid_eherkenning_oidc_generics_openidconnecteherkenningconfig",
),
]
# models have the wrong db_table associated
query1 = """
ALTER TABLE "digid_eherkenning_oidc_generics_openidconnectdigidconfig"
RENAME TO "digid_eherkenning_oidc_generics_legacy_openidconnectdigidconfig";
"""

query2 = """
ALTER TABLE "digid_eherkenning_oidc_generics_openidconnecteherkenningconfig"
RENAME TO "digid_eherkenning_oidc_generics_legacy_openidconnecteherkenningconfig";
"""

operations = [migrations.RunSQL(query1), migrations.RunSQL(query2)]
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ class Migration(migrations.Migration):
),
]

operations = [
migrations.DeleteModel(
name="OpenIDConnectDigiDConfig",
),
migrations.DeleteModel(
name="OpenIDConnectEHerkenningConfig",
),
]
# models have the wrong db_table associated
query1 = """
DROP TABLE "digid_eherkenning_oidc_generics_legacy_openidconnectdigidconfig" CASCADE;
"""

query2 = """
DROP TABLE "digid_eherkenning_oidc_generics_legacy_openidconnecteherkenningconfig" CASCADE;
"""

operations = [migrations.RunSQL(query1), migrations.RunSQL(query2)]
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ def forwards(apps, _):
"OpenIDConnectEHerkenningConfig",
)

# models have the wrong db_table associated
OpenIDConnectDigiDConfig.objects.model._meta.db_table = (
"digid_eherkenning_oidc_generics_legacy_openidconnectdigidconfig"
)
OpenIDConnectEHerkenningConfig.objects.model._meta.db_table = (
"digid_eherkenning_oidc_generics_legacy_openidconnecteherkenningconfig"
)

# new models
DigiDConfig = apps.get_model(
"digid_eherkenning_oidc_generics",
Expand All @@ -54,13 +62,13 @@ def forwards(apps, _):
digid_create_kwargs = {
field_name: getattr(legacy_digid, field_name)
for field_name in SHARED_FIELDS
} | {"bsn_claim": legacy_digid.identifier_claim_name}
} | {"bsn_claim": [legacy_digid.identifier_claim_name]}
DigiDConfig.objects.create(**digid_create_kwargs)

if legacy_eh := OpenIDConnectEHerkenningConfig.objects.first():
eh_create_kwargs = {
field_name: getattr(legacy_eh, field_name) for field_name in SHARED_FIELDS
} | {"legal_subject_claim": legacy_eh.identifier_claim_name}
} | {"legal_subject_claim": [legacy_eh.identifier_claim_name]}
EHerkenningConfig.objects.create(**eh_create_kwargs)


Expand Down

0 comments on commit 24f33c9

Please sign in to comment.