Fix Pydantic model error by adding ClassVar annotation to DB_DIR and moving directory creation outside class definition
This commit is contained in:
parent
4857a0347c
commit
aa94a02360
@ -1,7 +1,8 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import ClassVar
|
||||
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class Settings(BaseModel):
|
||||
@ -13,9 +14,10 @@ class Settings(BaseModel):
|
||||
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 7 # 7 days
|
||||
|
||||
# Database
|
||||
DB_DIR = Path("/app/storage/db")
|
||||
DB_DIR.mkdir(parents=True, exist_ok=True)
|
||||
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
|
||||
DB_DIR: ClassVar[Path] = Path("/app/storage/db")
|
||||
SQLALCHEMY_DATABASE_URL: str = Field(
|
||||
default_factory=lambda: f"sqlite:///{Settings.DB_DIR}/db.sqlite"
|
||||
)
|
||||
|
||||
# CORS
|
||||
CORS_ORIGINS: list[str] = ["*"]
|
||||
@ -26,4 +28,7 @@ class Settings(BaseModel):
|
||||
}
|
||||
|
||||
|
||||
# Create the database directory
|
||||
Settings.DB_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
settings = Settings()
|
||||
|
Loading…
x
Reference in New Issue
Block a user