From 0a6280276f97d5bc9dd646a84beebff54b29e660 Mon Sep 17 00:00:00 2001 From: SimplifiedPrivacy Date: Wed, 15 Jul 2026 19:34:24 -0400 Subject: [PATCH] Improved database management on entry --- gui/__main__.py | 59 +++++++++++++++-------- gui/__pycache__/__main__.cpython-312.pyc | Bin 5360 -> 0 bytes pyproject.toml | 2 +- 3 files changed, 41 insertions(+), 20 deletions(-) delete mode 100644 gui/__pycache__/__main__.cpython-312.pyc diff --git a/gui/__main__.py b/gui/__main__.py index 7aa2b11..6359d7c 100644 --- a/gui/__main__.py +++ b/gui/__main__.py @@ -3,6 +3,9 @@ from core.models.manage.session_management import init_session, get_session, clo from core.models.manage.version_check import check_database_compatibility, insert_new_version, get_custom_message 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 + # generic import os import sys @@ -37,6 +40,7 @@ def recovery_dialog(custom_error, db_version_you_have): # ============================================================================ # ASSETS FOLDER # ============================================================================ +logger.info("Welcome, checking assets..") if not assets_folder_setup(): from gui.v2.ui.popups.generic_error_popup import show_error custom_error = "Unable to Setup your Assets Folder. Please create an assets directory at ~/.local/share/hydra-veil/assets" @@ -45,17 +49,22 @@ if not assets_folder_setup(): # ============================================================================ # INITIALIZE DATABASE # ============================================================================ -# Does the database exist? -system_path = get_path() -database_path = system_path / "storage.db" -main_db_exists = does_it_exist(database_path) +logger.info("[DB MANAGEMENT] Starting DB init..") +try: + # Does the database exist? + system_path = get_path() + database_path = system_path / "storage.db" + main_db_exists = does_it_exist(database_path) -# Setup operations on the main DB which create it -init_session() # (engine, Session, _session all initialized from session_management) -session = get_session() + # Setup operations on the main DB which create it + init_session() # (engine, Session, _session all initialized from session_management) + session = get_session() -# does the version checker table exist? -version_table_exists = does_db_version_table_exist() + # does the version checker table exist? + version_table_exists = does_db_version_table_exist() +except: + logger.error("Critical Error with database initialization!") + sys.exit() # are they upgrading from a legacy version? # that would mean the table existed, but not the version table, @@ -89,17 +98,29 @@ logger.info(f"[DB MANAGEMENT] The result of the check is {is_compatable} and the # IF THE VERSIONS MATCH # ============================================================================ if is_compatable: - made_tables = create_ALL_tables() + try: + made_tables = create_ALL_tables() + # SCREEN FAILED TABLES + if not made_tables: + custom_error = "Critical Failure with starting the models of the database." + logger.error(f"[DB MANAGEMENT] {custom_error}") + close_session() + from gui.v2.ui.popups.Database_version import show_recovery_dialog + choice = show_recovery_dialog({"message": custom_error, "db_version": 0, "status": "cant_make"}) + logger.info(f"[DB MANAGEMENT] From the database error options, the user picked {choice}") + sys.exit() - # SCREEN FAILED TABLES - if not made_tables: - custom_error = "Critical Failure with starting the models of the database." - logger.error(f"[DB MANAGEMENT] {custom_error}") - close_session() - from gui.v2.ui.popups.Database_version import show_recovery_dialog - choice = show_recovery_dialog({"message": custom_error, "db_version": 0, "status": "cant_make"}) - logger.info(f"[DB MANAGEMENT] From the database error options, the user picked {choice}") - sys.exit() + except: + logger.info(f"[DB MANAGEMENT] create ALL tables failed. Running migrations...") + made_tables = migrate_sql() + logger.info(f"[DB MANAGEMENT] Results of migration is {made_tables.valid}") + + if not made_tables.valid: + close_session() + custom_error = "Could not Migrate the Database version, please delete the database. You will NOT lose profiles, this is the public data." + from gui.v2.ui.popups.Database_version import show_recovery_dialog + choice = show_recovery_dialog({"message": custom_error, "db_version": 0, "status": "cant_make"}) + sys.exit() # ASSUME TABLES CREATED logger.info("[DB MANAGEMENT] Tables successfully made or initialized if pre-existing") diff --git a/gui/__pycache__/__main__.cpython-312.pyc b/gui/__pycache__/__main__.cpython-312.pyc deleted file mode 100644 index 0e758e5b7f8e29906ba6c09322ea1fda515fdb48..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5360 zcma(VO>EoNnX+V=`n4>}@o(bi#E#>}meOoZ(4gz;B+gIcI$5naEz_2x#b=8ODXNc@ zRjE#^6ai|l9h}2}6=(-!w-&wR*we7X4g+==J*$Y!C0l`>dTZ7W1$x@|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