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 core.controllers.ConfigurationController import ConfigurationController
|
||||||
from essentials.observers.ConnectionObserver import ConnectionObserver
|
from essentials.observers.ConnectionObserver import ConnectionObserver
|
||||||
from core.observers.ClientObserver import ClientObserver
|
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
|
# generic
|
||||||
import os
|
import os
|
||||||
|
|
@ -128,8 +128,6 @@ main_db_exists = False
|
||||||
logger.info("[DB MANAGEMENT] Starting DB init..")
|
logger.info("[DB MANAGEMENT] Starting DB init..")
|
||||||
try:
|
try:
|
||||||
main_db_exists = does_it_exist(database_path)
|
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
|
# Setup operations on the main DB which create it
|
||||||
init_session() # (engine, Session, _session all initialized from session_management)
|
init_session() # (engine, Session, _session all initialized from session_management)
|
||||||
|
|
@ -137,10 +135,6 @@ try:
|
||||||
|
|
||||||
# does the version checker table exist?
|
# does the version checker table exist?
|
||||||
version_table_exists = does_db_version_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:
|
except Exception as error:
|
||||||
logger.error(f"[DB MANAGEMENT] Critical Error with database initialization: {error}")
|
logger.error(f"[DB MANAGEMENT] Critical Error with database initialization: {error}")
|
||||||
close_session()
|
close_session()
|
||||||
|
|
@ -210,19 +204,29 @@ logger.info(f"[DB MANAGEMENT] The result of the check is {is_compatable} and the
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# IF the versions do NOT match
|
# IF the versions do NOT match
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
migrated = False
|
||||||
if not is_compatable:
|
if not is_compatable:
|
||||||
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")
|
|
||||||
|
|
||||||
# WHAT IS THE REASON?
|
# MIGRATE?
|
||||||
custom_error = get_custom_message(reason, compatability_dict)
|
if reason == "upgrade":
|
||||||
|
migration = migrate_sql()
|
||||||
|
if migration.valid:
|
||||||
|
migrated = True
|
||||||
|
|
||||||
# shut down db connection
|
# MIGRATE FAILED OR NOT POSSIBLE
|
||||||
close_session()
|
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")
|
||||||
|
|
||||||
# THEN DISPLAY CHOICES AND RECOVERY UI
|
# WHAT IS THE REASON?
|
||||||
recovery_dialog(custom_error, db_version_you_have)
|
custom_error = get_custom_message(reason, compatability_dict)
|
||||||
# goodbye. exits.
|
|
||||||
|
# shut down db connection
|
||||||
|
close_session()
|
||||||
|
|
||||||
|
# THEN DISPLAY CHOICES AND RECOVERY UI
|
||||||
|
recovery_dialog(custom_error, db_version_you_have)
|
||||||
|
# goodbye. exits.
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# THE VERSIONS MATCH IF THEY ARE STILL HERE
|
# THE VERSIONS MATCH IF THEY ARE STILL HERE
|
||||||
|
|
@ -256,13 +260,13 @@ did_it_insert = insert_new_version(session, Constants.DB_VERSION_THIS_APP_WANTS)
|
||||||
if not did_it_insert:
|
if not did_it_insert:
|
||||||
logger.error(f"[DB MANAGEMENT] Critical Failure with updating/inserting the new DB version into the database.")
|
logger.error(f"[DB MANAGEMENT] Critical Failure with updating/inserting the new DB version into the database.")
|
||||||
|
|
||||||
try:
|
# try:
|
||||||
sync_data_missing = not has_required_sync_data(database_path)
|
# sync_data_missing = not has_required_sync_data(database_path)
|
||||||
except GuiStorageDatabaseError as error:
|
# except GuiStorageDatabaseError as error:
|
||||||
logger.error(f"[DB MANAGEMENT] Critical storage database error during synced data check: {error}")
|
# logger.error(f"[DB MANAGEMENT] Critical storage database error during synced data check: {error}")
|
||||||
close_session()
|
# close_session()
|
||||||
recovery_dialog(str(error), "Unreadable")
|
# recovery_dialog(str(error), "Unreadable")
|
||||||
sync_data_missing = True
|
# sync_data_missing = True
|
||||||
|
|
||||||
# Load GUI either way:
|
# Load GUI either way:
|
||||||
from gui.main_ui import start_ui
|
from gui.main_ui import start_ui
|
||||||
|
|
@ -272,10 +276,7 @@ if migration_happened:
|
||||||
force_sync = True
|
force_sync = True
|
||||||
clear_sync_cache()
|
clear_sync_cache()
|
||||||
else:
|
else:
|
||||||
force_sync = sync_data_missing
|
force_sync = False
|
||||||
|
|
||||||
if sync_data_missing:
|
|
||||||
logger.info("[DB MANAGEMENT] Required synced data is missing. GUI will prompt for sync.")
|
|
||||||
|
|
||||||
# if we deleted their DB, we want to force sync,
|
# if we deleted their DB, we want to force sync,
|
||||||
if lock_file.exists():
|
if lock_file.exists():
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue