From d4cfb783ef62c8ddda98b18f6974a5cfaebb40cc Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 9 Mar 2025 21:04:54 +0700 Subject: [PATCH] fix ta_config appsettings migration --- .../config/management/commands/ta_startup.py | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/backend/config/management/commands/ta_startup.py b/backend/config/management/commands/ta_startup.py index ec6d2ffc..3dc55e83 100644 --- a/backend/config/management/commands/ta_startup.py +++ b/backend/config/management/commands/ta_startup.py @@ -168,7 +168,7 @@ class Command(BaseCommand): ) return - if not config: + if not config or config == {"status": False}: self.stdout.write( self.style.SUCCESS(" no config values to migrate") ) @@ -181,7 +181,7 @@ class Command(BaseCommand): self.stdout.write( self.style.SUCCESS(" ✓ migrated appconfig to ES") ) - RedisArchivist().del_message("config") + RedisArchivist().del_message("config", save=True) return message = " 🗙 failed to migrate app config" @@ -262,8 +262,8 @@ class Command(BaseCommand): def _init_app_config(self) -> None: """init default app config to ES""" self.stdout.write("[10] Check AppConfig") - try: - _ = AppConfig().config + _, status_code = ElasticWrap("ta_config/_doc/appsettings").get() + if status_code in [200, 201]: self.stdout.write( self.style.SUCCESS(" skip completed appsettings init") ) @@ -273,15 +273,16 @@ class Command(BaseCommand): self.style.SUCCESS(f" added new default: {new_default}") ) - except ValueError: - handler = AppConfig.__new__(AppConfig) - _, status_code = handler.sync_defaults() - self.stdout.write( - self.style.SUCCESS(" ✓ Created default appsettings.") - ) - self.stdout.write( - self.style.SUCCESS(f" Status code: {status_code}") - ) + return + + handler = AppConfig.__new__(AppConfig) + _, status_code = handler.sync_defaults() + self.stdout.write( + self.style.SUCCESS(" ✓ Created default appsettings.") + ) + self.stdout.write( + self.style.SUCCESS(f" Status code: {status_code}") + ) def _mig_channel_tags(self) -> None: """update from v0.4.13 to v0.5.0, migrate incorrect data types"""