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."""
|
"""Application configuration settings."""
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import ClassVar
|
||||||
|
|
||||||
from pydantic_settings import BaseSettings
|
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):
|
class Settings(BaseSettings):
|
||||||
"""Application settings."""
|
"""Application settings."""
|
||||||
@ -12,14 +17,13 @@ class Settings(BaseSettings):
|
|||||||
API_V1_STR: str = "/api/v1"
|
API_V1_STR: str = "/api/v1"
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
DB_DIR = Path("/app") / "storage" / "db"
|
DB_DIR: ClassVar[Path] = DB_DIR
|
||||||
DB_DIR.mkdir(parents=True, exist_ok=True)
|
|
||||||
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
|
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
|
||||||
|
|
||||||
class Config:
|
model_config = {
|
||||||
"""Config class for Settings."""
|
"case_sensitive": True,
|
||||||
case_sensitive = True
|
"env_file": ".env",
|
||||||
env_file = ".env"
|
}
|
||||||
|
|
||||||
|
|
||||||
settings = Settings()
|
settings = Settings()
|
Loading…
x
Reference in New Issue
Block a user