diff --git a/factsdb/database.py b/factsdb/database.py index 97aba5f..4d9a6f6 100644 --- a/factsdb/database.py +++ b/factsdb/database.py @@ -21,7 +21,20 @@ class DatabaseManager: self._init_database() except Exception as e: print(f"Warning: Database initialization failed: {e}") - # Continue with minimal functionality or raise the error + # Create the directory if it doesn't exist and the path has a directory component + import os + try: + # Check if path has a directory component + if os.path.dirname(self.config.path): + os.makedirs(os.path.dirname(self.config.path), exist_ok=True) + print(f"Created directory for database: {os.path.dirname(self.config.path)}") + else: + # If no directory, ensure current directory is writable + os.makedirs('.', exist_ok=True) + print("Verified current directory is writable") + except Exception as dir_error: + print(f"Warning: Could not create database directory: {dir_error}") + # Re-raise the original error raise def _init_database(self):