Skip to content

Commit

Permalink
Hack around app label rename
Browse files Browse the repository at this point in the history
Probably the shadiest/trickest part of this upgrade - we have to keep
existing migration history in mind to avoid running them twice (as
those would crash out), but we must assume this SQL will also run
when the new dependencies are set up and that would incorrectly mark
the external package migrations as belonging to the legacy app.

Therefore, we strictly limit the migrations that may be renamed to the
ones that are known - the timestamps added by django definitely help
here.

The digid-eherkenning.oidc migrations also start with a squashed
migration, so there is no collision on the 0001_initial migration 🎉
  • Loading branch information
sergei-maertens committed Jul 5, 2024
1 parent b0e95e6 commit 748d8b8
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/digid_eherkenning_oidc_generics/apps.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,36 @@
from contextlib import suppress

from django.apps import AppConfig
from django.db import OperationalError, ProgrammingError, connection
from django.utils.translation import gettext_lazy as _


class DigiDeHerkenningOIDCAppConfig(AppConfig):
name = "digid_eherkenning_oidc_generics"
verbose_name = _("DigiD & eHerkenning via OpenID Connect")
label = "digid_eherkenning_oidc_generics_legacy"

def ready(self):
# Hook into the app registry to update the django_migrations table
# *before* we run migrations.
with suppress(OperationalError, ProgrammingError):
rename_app_label()


def rename_app_label():
with connection.cursor() as cursor:
# uses explicit query names so that we don't accidentally rwrite the
# new digid_eherkenning.oidc migrations
query = """
UPDATE django_migrations
SET app = 'digid_eherkenning_oidc_generics_legacy'
WHERE app = 'digid_eherkenning_oidc_generics'
AND (
name = '0001_initial'
OR name = '0002_auto_20240109_1055'
OR name = '0003_alter_openidconnectdigidconfig_oidc_exempt_urls_and_more'
OR name = '0004_alter_openidconnectdigidconfig_table_and_more'
OR name = '0001_legacy'
)
"""
cursor.execute(query)

0 comments on commit 748d8b8

Please sign in to comment.