forked from tpd94/CDRM-Project
Refactor database checks to enhance path handling, add module docstrings for clarity, and streamline database creation logic
This commit is contained in:
parent
c82d23aabc
commit
d6cf10ccaf
@ -1,44 +1,52 @@
|
|||||||
|
"""Module to check for the database."""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
from custom_functions.database.cache_to_db_mariadb import (
|
||||||
|
create_database as create_mariadb_database,
|
||||||
|
)
|
||||||
|
from custom_functions.database.cache_to_db_sqlite import (
|
||||||
|
create_database as create_sqlite_database,
|
||||||
|
)
|
||||||
|
from custom_functions.database.user_db import create_user_database
|
||||||
|
|
||||||
|
|
||||||
def check_for_sqlite_database():
|
def check_for_sqlite_database():
|
||||||
with open(f"{os.getcwd()}/configs/config.yaml", "r") as file:
|
"""Check for the SQLite database."""
|
||||||
|
with open(
|
||||||
|
os.path.join(os.getcwd(), "configs", "config.yaml"), "r", encoding="utf-8"
|
||||||
|
) as file:
|
||||||
config = yaml.safe_load(file)
|
config = yaml.safe_load(file)
|
||||||
if os.path.exists(f"{os.getcwd()}/databases/key_cache.db"):
|
if os.path.exists(os.path.join(os.getcwd(), "databases", "key_cache.db")):
|
||||||
return
|
return
|
||||||
else:
|
if config["database_type"].lower() == "sqlite":
|
||||||
if config["database_type"].lower() != "mariadb":
|
create_sqlite_database()
|
||||||
from custom_functions.database.cache_to_db_sqlite import create_database
|
return
|
||||||
|
return
|
||||||
create_database()
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def check_for_user_database():
|
def check_for_user_database():
|
||||||
if os.path.exists(f"{os.getcwd()}/databases/users.db"):
|
"""Check for the user database."""
|
||||||
|
if os.path.exists(os.path.join(os.getcwd(), "databases", "users.db")):
|
||||||
return
|
return
|
||||||
else:
|
create_user_database()
|
||||||
from custom_functions.database.user_db import create_user_database
|
|
||||||
|
|
||||||
create_user_database()
|
|
||||||
|
|
||||||
|
|
||||||
def check_for_mariadb_database():
|
def check_for_mariadb_database():
|
||||||
with open(f"{os.getcwd()}/configs/config.yaml", "r") as file:
|
"""Check for the MariaDB database."""
|
||||||
|
with open(
|
||||||
|
os.path.join(os.getcwd(), "configs", "config.yaml"), "r", encoding="utf-8"
|
||||||
|
) as file:
|
||||||
config = yaml.safe_load(file)
|
config = yaml.safe_load(file)
|
||||||
if config["database_type"].lower() == "mariadb":
|
if config["database_type"].lower() == "mariadb":
|
||||||
from custom_functions.database.cache_to_db_mariadb import create_database
|
create_mariadb_database()
|
||||||
|
|
||||||
create_database()
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
return
|
return
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
def check_for_sql_database():
|
def check_for_sql_database():
|
||||||
|
"""Check for the SQL database."""
|
||||||
check_for_sqlite_database()
|
check_for_sqlite_database()
|
||||||
check_for_mariadb_database()
|
check_for_mariadb_database()
|
||||||
check_for_user_database()
|
check_for_user_database()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user