forked from Support/sp-hydra-veil-gui
Improved Migration detection and launch on app start
This commit is contained in:
parent
3c67e72d2d
commit
184728a948
1 changed files with 28 additions and 27 deletions
|
|
@ -10,7 +10,7 @@ from core.controllers.SyncController import new_sync
|
|||
from core.controllers.ConfigurationController import ConfigurationController
|
||||
from essentials.observers.ConnectionObserver import ConnectionObserver
|
||||
from core.observers.ClientObserver import ClientObserver
|
||||
from gui.v2.actions.database_health import GuiStorageDatabaseError, validate_storage_database, has_required_sync_data
|
||||
# from gui.v2.actions.database_health import GuiStorageDatabaseError, validate_storage_database, has_required_sync_data
|
||||
|
||||
# generic
|
||||
import os
|
||||
|
|
@ -128,8 +128,6 @@ main_db_exists = False
|
|||
logger.info("[DB MANAGEMENT] Starting DB init..")
|
||||
try:
|
||||
main_db_exists = does_it_exist(database_path)
|
||||
if main_db_exists:
|
||||
validate_storage_database(database_path)
|
||||
|
||||
# Setup operations on the main DB which create it
|
||||
init_session() # (engine, Session, _session all initialized from session_management)
|
||||
|
|
@ -137,10 +135,6 @@ try:
|
|||
|
||||
# does the version checker table exist?
|
||||
version_table_exists = does_db_version_table_exist()
|
||||
except GuiStorageDatabaseError as error:
|
||||
logger.error(f"[DB MANAGEMENT] Critical storage database error during initialization: {error}")
|
||||
close_session()
|
||||
recovery_dialog(str(error), "Unreadable")
|
||||
except Exception as error:
|
||||
logger.error(f"[DB MANAGEMENT] Critical Error with database initialization: {error}")
|
||||
close_session()
|
||||
|
|
@ -210,7 +204,17 @@ logger.info(f"[DB MANAGEMENT] The result of the check is {is_compatable} and the
|
|||
# ============================================================================
|
||||
# IF the versions do NOT match
|
||||
# ============================================================================
|
||||
migrated = False
|
||||
if not is_compatable:
|
||||
|
||||
# MIGRATE?
|
||||
if reason == "upgrade":
|
||||
migration = migrate_sql()
|
||||
if migration.valid:
|
||||
migrated = True
|
||||
|
||||
# MIGRATE FAILED OR NOT POSSIBLE
|
||||
if not migrated:
|
||||
logger.error(f"[DB MANAGEMENT] The App is expecting a different DB version than the real database. The reason is {reason}")
|
||||
db_version_you_have = compatability_dict.get("old_db_version", "Error getting the Version")
|
||||
|
||||
|
|
@ -256,13 +260,13 @@ did_it_insert = insert_new_version(session, Constants.DB_VERSION_THIS_APP_WANTS)
|
|||
if not did_it_insert:
|
||||
logger.error(f"[DB MANAGEMENT] Critical Failure with updating/inserting the new DB version into the database.")
|
||||
|
||||
try:
|
||||
sync_data_missing = not has_required_sync_data(database_path)
|
||||
except GuiStorageDatabaseError as error:
|
||||
logger.error(f"[DB MANAGEMENT] Critical storage database error during synced data check: {error}")
|
||||
close_session()
|
||||
recovery_dialog(str(error), "Unreadable")
|
||||
sync_data_missing = True
|
||||
# try:
|
||||
# sync_data_missing = not has_required_sync_data(database_path)
|
||||
# except GuiStorageDatabaseError as error:
|
||||
# logger.error(f"[DB MANAGEMENT] Critical storage database error during synced data check: {error}")
|
||||
# close_session()
|
||||
# recovery_dialog(str(error), "Unreadable")
|
||||
# sync_data_missing = True
|
||||
|
||||
# Load GUI either way:
|
||||
from gui.main_ui import start_ui
|
||||
|
|
@ -272,10 +276,7 @@ if migration_happened:
|
|||
force_sync = True
|
||||
clear_sync_cache()
|
||||
else:
|
||||
force_sync = sync_data_missing
|
||||
|
||||
if sync_data_missing:
|
||||
logger.info("[DB MANAGEMENT] Required synced data is missing. GUI will prompt for sync.")
|
||||
force_sync = False
|
||||
|
||||
# if we deleted their DB, we want to force sync,
|
||||
if lock_file.exists():
|
||||
|
|
|
|||
Loading…
Reference in a new issue