|
|
@@ -10,12 +10,12 @@ from app.config import get_settings
|
|
|
|
|
|
settings = get_settings()
|
|
|
|
|
|
-# 确保数据库目录存在
|
|
|
-db_path = settings.database_url.replace("sqlite+aiosqlite:///", "")
|
|
|
-if db_path.startswith("sqlite+aiosqlite:///"):
|
|
|
- db_path = db_path.replace("sqlite+aiosqlite:///", "")
|
|
|
-if db_path and not db_path.startswith("memory"):
|
|
|
- Path(db_path).parent.mkdir(parents=True, exist_ok=True)
|
|
|
+# 确保数据库目录存在(从 URL 中解析路径)
|
|
|
+db_path = settings.database_url.removeprefix("sqlite+aiosqlite://")
|
|
|
+if db_path and not db_path.startswith(":memory"):
|
|
|
+ # 确保是绝对路径
|
|
|
+ db_path_obj = Path(db_path) if db_path.startswith("/") else Path("/") / db_path
|
|
|
+ db_path_obj.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
Base = declarative_base()
|
|
|
|