From 220d739fef9913f099a2e0d08934efa88991ec45 Mon Sep 17 00:00:00 2001 From: Jens L Date: Sat, 28 Oct 2023 17:56:04 +0200 Subject: [PATCH] lifecycle: rework otp_merge migration (#7359) Signed-off-by: Jens Langhammer --- lifecycle/system_migrations/otp_merge.py | 31 +++++++++--------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/lifecycle/system_migrations/otp_merge.py b/lifecycle/system_migrations/otp_merge.py index 6e6a1970c..a71ebbd82 100644 --- a/lifecycle/system_migrations/otp_merge.py +++ b/lifecycle/system_migrations/otp_merge.py @@ -3,13 +3,17 @@ from lifecycle.migrate import BaseMigration SQL_STATEMENT = """ BEGIN TRANSACTION; -DELETE FROM django_migrations WHERE app = 'otp_static'; -DELETE FROM django_migrations WHERE app = 'otp_totp'; +-- Update migrations (static) +UPDATE django_migrations SET app = 'authentik_stages_authenticator_static', name = '0008_initial' WHERE app = 'otp_static' AND name = '0001_initial'; +UPDATE django_migrations SET app = 'authentik_stages_authenticator_static', name = '0009_throttling' WHERE app = 'otp_static' AND name = '0002_throttling'; -- Rename tables (static) ALTER TABLE otp_static_staticdevice RENAME TO authentik_stages_authenticator_static_staticdevice; ALTER TABLE otp_static_statictoken RENAME TO authentik_stages_authenticator_static_statictoken; ALTER SEQUENCE otp_static_statictoken_id_seq RENAME TO authentik_stages_authenticator_static_statictoken_id_seq; ALTER SEQUENCE otp_static_staticdevice_id_seq RENAME TO authentik_stages_authenticator_static_staticdevice_id_seq; +-- Update migrations (totp) +UPDATE django_migrations SET app = 'authentik_stages_authenticator_totp', name = '0008_initial' WHERE app = 'otp_totp' AND name = '0001_initial'; +UPDATE django_migrations SET app = 'authentik_stages_authenticator_totp', name = '0009_auto_20190420_0723' WHERE app = 'otp_totp' AND name = '0002_auto_20190420_0723'; -- Rename tables (totp) ALTER TABLE otp_totp_totpdevice RENAME TO authentik_stages_authenticator_totp_totpdevice; ALTER SEQUENCE otp_totp_totpdevice_id_seq RENAME TO authentik_stages_authenticator_totp_totpdevice_id_seq; @@ -25,22 +29,9 @@ class Migration(BaseMigration): return bool(self.cur.rowcount) def run(self): - self.cur.execute(SQL_STATEMENT) - self.fake_migration( - ( - "authentik_stages_authenticator_static", - "0008_initial", - ), - ( - "authentik_stages_authenticator_static", - "0009_throttling", - ), - ( - "authentik_stages_authenticator_totp", - "0008_initial", - ), - ( - "authentik_stages_authenticator_totp", - "0009_auto_20190420_0723", - ), + self.cur.execute( + "SELECT * FROM django_migrations WHERE app = 'authentik_stages_authenticator_static' AND name = '0007_authenticatorstaticstage_token_length_and_more';" ) + if not bool(self.cur.rowcount): + raise Exception("Please upgrade to 2023.8 before upgrading to 2023.10") + self.cur.execute(SQL_STATEMENT)