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 0e758e5..0000000 Binary files a/gui/__pycache__/__main__.cpython-312.pyc and /dev/null differ diff --git a/pyproject.toml b/pyproject.toml index 6dbce05..b35b956 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ classifiers = [ "Operating System :: POSIX :: Linux", ] dependencies = [ - "sp-hydra-veil-core == 2.3.9", + "sp-hydra-veil-core == 2.4.0", "pyperclip ~= 1.9.0", "pyqt6 ~= 6.7.1", "qrcode[pil] ~= 8.2"