diff --git a/gui/__main__.py b/gui/__main__.py index b73ff78..e11f344 100644 --- a/gui/__main__.py +++ b/gui/__main__.py @@ -5,6 +5,7 @@ from core.services.helpers.manage_assets import assets_folder_setup from core.Constants import Constants from core.models.DatabaseOperation import DatabaseOperation, DBErrorType from core.models.manage.migrations import migrate_sql +from core.models.manage.clear_sql_model import clear_sql_model # generic import os @@ -13,8 +14,27 @@ from pathlib import Path # ============================================================================ -# DISPLAY CHOICES AND RECOVERY UI +# UTIL FUNCTIONS AND RECOVERY UI # ============================================================================ +def clear_sync_cache(): + """ + Purpose: + Clear CachedSync + If that fails, prompt for a database wipe. + + Why: + If they migrated, they have new schemas, but old data. + The problem with that, is the newest CachedSync entry will fool the sync data functions into thinking they don't need to sync new data, + Even though they do need to sync with the new schema. + """ + from core.models.orm_models.CachedSync import CachedSync + result = clear_sql_model(CachedSync) + if result: + logger.info(f"[DB MANAGEMENT] After Migration cleared the CachedSync table: {result}.") + else: + custom_error = "There were issues with clearing the Sync Cache in your database. Please delete the old version and fetch the new public data (what locations, browsers, ect) This will NOT affect your profiles or browser sessions." + recovery_dialog(custom_error, "CachedSync Issue") + def failed_migration(db_version_you_have): close_session() # shut down db connection custom_error = "There were issues with migrating your database. We transitioned to a new Database format for new features! Please delete the old version and fetch the new public data (what locations, browsers, ect) This will NOT affect your profiles or browser sessions." @@ -75,7 +95,6 @@ except: logger.error("Critical Error with database initialization!") sys.exit() - # ============================================================================ # LEGACY DATABASE CHECKS # ============================================================================ @@ -91,6 +110,7 @@ if not version_table_exists and main_db_exists: if migration.valid: migration_happened = True force_sync = True + clear_sync_cache() else: # THEN DISPLAY CHOICES AND RECOVERY UI db_version_you_have = "Old System" @@ -154,6 +174,7 @@ if is_compatable: logger.info(f"[DB MANAGEMENT] Launcher is now passing it off to launch the main GUI window WITHOUT force sync..") if migration_happened: force_sync = True + clear_sync_cache() else: force_sync = False