Fix Pydantic model error in config.py and update DB configuration
This commit is contained in:
parent
eb8caf0254
commit
d145e0d3f6
@ -2,6 +2,9 @@ from typing import List
|
|||||||
from pydantic_settings import BaseSettings
|
from pydantic_settings import BaseSettings
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
# Create DB directory outside the model
|
||||||
|
DB_DIR = Path("/app") / "storage" / "db"
|
||||||
|
DB_DIR.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
class Settings(BaseSettings):
|
class Settings(BaseSettings):
|
||||||
API_V1_STR: str = "/api/v1"
|
API_V1_STR: str = "/api/v1"
|
||||||
@ -9,13 +12,12 @@ class Settings(BaseSettings):
|
|||||||
ALLOWED_ORIGINS: List[str] = ["*"]
|
ALLOWED_ORIGINS: List[str] = ["*"]
|
||||||
|
|
||||||
# Database settings
|
# Database settings
|
||||||
DB_DIR = Path("/app") / "storage" / "db"
|
|
||||||
DB_DIR.mkdir(parents=True, exist_ok=True)
|
|
||||||
DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
|
DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
|
||||||
|
|
||||||
class Config:
|
model_config = {
|
||||||
env_file = ".env"
|
"env_file": ".env",
|
||||||
case_sensitive = True
|
"case_sensitive": True
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
settings = Settings()
|
settings = Settings()
|
@ -1,13 +1,9 @@
|
|||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
from pathlib import Path
|
from app.core.config import settings
|
||||||
|
|
||||||
|
# Use the SQLALCHEMY_DATABASE_URL from settings
|
||||||
# Create db directory if it doesn't exist
|
SQLALCHEMY_DATABASE_URL = settings.DATABASE_URL
|
||||||
DB_DIR = Path("/app") / "storage" / "db"
|
|
||||||
DB_DIR.mkdir(parents=True, exist_ok=True)
|
|
||||||
|
|
||||||
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite"
|
|
||||||
|
|
||||||
engine = create_engine(
|
engine = create_engine(
|
||||||
SQLALCHEMY_DATABASE_URL,
|
SQLALCHEMY_DATABASE_URL,
|
||||||
|
6
test_config.py
Normal file
6
test_config.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
from app.core.config import settings
|
||||||
|
|
||||||
|
print("Settings loaded successfully")
|
||||||
|
print(f"API_V1_STR: {settings.API_V1_STR}")
|
||||||
|
print(f"DATABASE_URL: {settings.DATABASE_URL}")
|
Loading…
x
Reference in New Issue
Block a user