fix: use AppData path for SQLite DB on Windows, absolute path on Linux
The default sqlite:////app/data/cloud.db path only works inside Docker. On Windows, Controlled Folder Access blocks writes to arbitrary paths. Now mirrors the same pattern as local_backend/config.py: - Windows: %LOCALAPPDATA%/xenia_cloud/cloud.db (always writable) - Linux/Docker: next to main.py (overridden by DATABASE_URL in .env) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,12 +1,20 @@
|
|||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from pydantic_settings import BaseSettings
|
from pydantic_settings import BaseSettings
|
||||||
|
|
||||||
_HERE = Path(__file__).parent
|
_HERE = Path(__file__).parent
|
||||||
|
|
||||||
|
if os.name == "nt":
|
||||||
|
_DB_DIR = Path(os.environ.get("LOCALAPPDATA", Path.home() / "AppData" / "Local")) / "xenia_cloud"
|
||||||
|
_DB_DIR.mkdir(parents=True, exist_ok=True)
|
||||||
|
_DEFAULT_DB = _DB_DIR / "cloud.db"
|
||||||
|
else:
|
||||||
|
_DEFAULT_DB = _HERE / "cloud.db"
|
||||||
|
|
||||||
|
|
||||||
class Settings(BaseSettings):
|
class Settings(BaseSettings):
|
||||||
SECRET_KEY: str = "change-me-generate-a-long-random-string"
|
SECRET_KEY: str = "change-me-generate-a-long-random-string"
|
||||||
DATABASE_URL: str = "sqlite:////app/data/cloud.db"
|
DATABASE_URL: str = f"sqlite:///{_DEFAULT_DB.as_posix()}"
|
||||||
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60
|
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60
|
||||||
ADMIN_USERNAME: str = "sysadmin"
|
ADMIN_USERNAME: str = "sysadmin"
|
||||||
ADMIN_PASSWORD: str = "changeme"
|
ADMIN_PASSWORD: str = "changeme"
|
||||||
|
|||||||
Reference in New Issue
Block a user