forked from Support/sp-hydra-veil-gui
Improved database management on entry
This commit is contained in:
parent
25489bf203
commit
0a6280276f
3 changed files with 41 additions and 20 deletions
|
|
@ -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")
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in a new issue