Procházet zdrojové kódy

修复重构容器数据丢失的情况

lxylxy123321 před 1 týdnem
rodič
revize
da8fb05b58
1 změnil soubory, kde provedl 6 přidání a 6 odebrání
  1. 6 6
      backend/app/core/db.py

+ 6 - 6
backend/app/core/db.py

@@ -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()