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.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.services.helpers.manage_assets import assets_folder_setup
|
||||||
from core.Constants import Constants
|
from core.Constants import Constants
|
||||||
|
from core.models.DatabaseOperation import DatabaseOperation, DBErrorType
|
||||||
|
from core.models.manage.migrations import migrate_sql
|
||||||
|
|
||||||
# generic
|
# generic
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
@ -37,6 +40,7 @@ def recovery_dialog(custom_error, db_version_you_have):
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# ASSETS FOLDER
|
# ASSETS FOLDER
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
logger.info("Welcome, checking assets..")
|
||||||
if not assets_folder_setup():
|
if not assets_folder_setup():
|
||||||
from gui.v2.ui.popups.generic_error_popup import show_error
|
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"
|
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
|
# INITIALIZE DATABASE
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# Does the database exist?
|
logger.info("[DB MANAGEMENT] Starting DB init..")
|
||||||
system_path = get_path()
|
try:
|
||||||
database_path = system_path / "storage.db"
|
# Does the database exist?
|
||||||
main_db_exists = does_it_exist(database_path)
|
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
|
# 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)
|
||||||
session = get_session()
|
session = get_session()
|
||||||
|
|
||||||
# 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:
|
||||||
|
logger.error("Critical Error with database initialization!")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
# are they upgrading from a legacy version?
|
# are they upgrading from a legacy version?
|
||||||
# that would mean the table existed, but not the version table,
|
# that would mean the table existed, but not the version table,
|
||||||
|
|
@ -89,8 +98,8 @@ logger.info(f"[DB MANAGEMENT] The result of the check is {is_compatable} and the
|
||||||
# IF THE VERSIONS MATCH
|
# IF THE VERSIONS MATCH
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
if is_compatable:
|
if is_compatable:
|
||||||
|
try:
|
||||||
made_tables = create_ALL_tables()
|
made_tables = create_ALL_tables()
|
||||||
|
|
||||||
# SCREEN FAILED TABLES
|
# SCREEN FAILED TABLES
|
||||||
if not made_tables:
|
if not made_tables:
|
||||||
custom_error = "Critical Failure with starting the models of the database."
|
custom_error = "Critical Failure with starting the models of the database."
|
||||||
|
|
@ -101,6 +110,18 @@ if is_compatable:
|
||||||
logger.info(f"[DB MANAGEMENT] From the database error options, the user picked {choice}")
|
logger.info(f"[DB MANAGEMENT] From the database error options, the user picked {choice}")
|
||||||
sys.exit()
|
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
|
# ASSUME TABLES CREATED
|
||||||
logger.info("[DB MANAGEMENT] Tables successfully made or initialized if pre-existing")
|
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",
|
"Operating System :: POSIX :: Linux",
|
||||||
]
|
]
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"sp-hydra-veil-core == 2.3.9",
|
"sp-hydra-veil-core == 2.4.0",
|
||||||
"pyperclip ~= 1.9.0",
|
"pyperclip ~= 1.9.0",
|
||||||
"pyqt6 ~= 6.7.1",
|
"pyqt6 ~= 6.7.1",
|
||||||
"qrcode[pil] ~= 8.2"
|
"qrcode[pil] ~= 8.2"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue