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 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():
 | 
			
		||||
    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)
 | 
			
		||||
    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
 | 
			
		||||
    else:
 | 
			
		||||
        if config["database_type"].lower() != "mariadb":
 | 
			
		||||
            from custom_functions.database.cache_to_db_sqlite import create_database
 | 
			
		||||
 | 
			
		||||
            create_database()
 | 
			
		||||
            return
 | 
			
		||||
        else:
 | 
			
		||||
            return
 | 
			
		||||
    if config["database_type"].lower() == "sqlite":
 | 
			
		||||
        create_sqlite_database()
 | 
			
		||||
        return
 | 
			
		||||
    return
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
    else:
 | 
			
		||||
        from custom_functions.database.user_db import create_user_database
 | 
			
		||||
 | 
			
		||||
        create_user_database()
 | 
			
		||||
    create_user_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)
 | 
			
		||||
    if config["database_type"].lower() == "mariadb":
 | 
			
		||||
        from custom_functions.database.cache_to_db_mariadb import create_database
 | 
			
		||||
 | 
			
		||||
        create_database()
 | 
			
		||||
        return
 | 
			
		||||
    else:
 | 
			
		||||
        create_mariadb_database()
 | 
			
		||||
        return
 | 
			
		||||
    return
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def check_for_sql_database():
 | 
			
		||||
    """Check for the SQL database."""
 | 
			
		||||
    check_for_sqlite_database()
 | 
			
		||||
    check_for_mariadb_database()
 | 
			
		||||
    check_for_user_database()
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user