Skip to content

Fix: Create db directory before connecting to SQLite database#6

Open
by22Jy wants to merge 1 commit intoGamesCrafters:mainfrom
by22Jy:main
Open

Fix: Create db directory before connecting to SQLite database#6
by22Jy wants to merge 1 commit intoGamesCrafters:mainfrom
by22Jy:main

Conversation

@by22Jy
Copy link

@by22Jy by22Jy commented Feb 18, 2026

Summary

Fixes issue where SqliteDB fails to initialize when the db/ directory does not exist.

Problem

After cloning the repository and running setup, attempting to solve a game throws:

sqlite3.OperationalError: unable to open database file

This occurs because the /database/db/ directory is not created during project setup.

Solution

  • Added os.makedirs(os.path.dirname(self.path), exist_ok=True) before connecting to the database
  • Only creates the directory when not in read-only mode (ro=False)
  • This ensures the directory exists before SQLite attempts to create the database file

Changes

  • Modified database/src/database/sqlite_database.py
  • Added directory creation in __init__ method (lines 21-23)

Testing

  • Tested with a fresh clone of the repository
  • Directory is created automatically when needed
  • No errors when connecting to database for the first time

Related Issue

Fixes #5


🤖 First-time contributor! Happy to help improve this project.

- Fixes #5
- Added os.makedirs() to create db/ directory if it doesn't exist
- Only creates directory when not in read-only mode (ro=False)
- Prevents sqlite3.OperationalError when database file doesn't exist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant