database creation fixes
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing

This commit is contained in:
2025-09-05 14:35:27 +09:00
parent 4ea540021a
commit 908aff8b3d

5
db.py
View File

@@ -10,10 +10,9 @@ DATABASE_URL = os.getenv("DATABASE_URL", "sqlite+aiosqlite:///bot.db")
if DATABASE_URL.startswith("sqlite+aiosqlite:///"):
db_path = DATABASE_URL.replace("sqlite+aiosqlite:///", "")
abs_db_path = os.path.abspath(db_path)
# Проверяем, что путь содержит директорию
db_dir = os.path.dirname(abs_db_path)
# Если путь содержит директорию, создаём её
if db_dir and db_dir != os.path.abspath("") and not os.path.exists(db_dir):
# Создаём директорию только если она не равна текущей ('.') и не пустая
if db_dir and db_dir != os.path.abspath("") and db_dir != '.' and not os.path.exists(db_dir):
os.makedirs(db_dir, exist_ok=True)
# Если по этому пути уже есть папка, удаляем её и создаём файл
if os.path.isdir(abs_db_path):