Fix Pydantic error in Settings class
- Add ClassVar type annotation to DB_DIR field - Move directory creation logic outside of Settings class - Update config class to use model_config dict format for Pydantic v2 - Fix database migration error related to non-annotated attribute
This commit is contained in:
parent
53bc4e0199
commit
bff5c53372
@ -1,8 +1,13 @@
|
||||
"""Application configuration settings."""
|
||||
from pathlib import Path
|
||||
from typing import ClassVar
|
||||
|
||||
from pydantic_settings import BaseSettings
|
||||
|
||||
# Create database directory
|
||||
DB_DIR = Path("/app") / "storage" / "db"
|
||||
DB_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
"""Application settings."""
|
||||
@ -12,14 +17,13 @@ class Settings(BaseSettings):
|
||||
API_V1_STR: str = "/api/v1"
|
||||
|
||||
# Database
|
||||
DB_DIR = Path("/app") / "storage" / "db"
|
||||
DB_DIR.mkdir(parents=True, exist_ok=True)
|
||||
DB_DIR: ClassVar[Path] = DB_DIR
|
||||
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
|
||||
|
||||
class Config:
|
||||
"""Config class for Settings."""
|
||||
case_sensitive = True
|
||||
env_file = ".env"
|
||||
model_config = {
|
||||
"case_sensitive": True,
|
||||
"env_file": ".env",
|
||||
}
|
||||
|
||||
|
||||
settings = Settings()
|
Loading…
x
Reference in New Issue
Block a user