Fix Pydantic error by moving DB_DIR outside of Settings class
- Moved DB_DIR Path definition outside Settings class to fix Pydantic 2.x annotation error - Updated path to use project-specific path rather than /app - Added start.py script to validate app loading generated with BackendIM... (backend.im)
This commit is contained in:
parent
5a8adf1d9c
commit
9586f0c506
@ -1,16 +1,19 @@
|
|||||||
from pydantic_settings import BaseSettings
|
from pydantic_settings import BaseSettings
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional
|
from typing import Optional, ClassVar
|
||||||
|
|
||||||
|
|
||||||
|
# Create DB directory outside of the Settings class
|
||||||
|
DB_DIR = Path("/projects/taskmanagerapi-8e2xek/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"
|
||||||
PROJECT_NAME: str = "Task Manager API"
|
PROJECT_NAME: str = "Task Manager API"
|
||||||
|
|
||||||
# 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"
|
||||||
|
|
||||||
|
|
||||||
settings = Settings()
|
settings = Settings()
|
@ -1,14 +1,8 @@
|
|||||||
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
|
||||||
import os
|
|
||||||
|
|
||||||
# Use relative path for development environment
|
SQLALCHEMY_DATABASE_URL = settings.DATABASE_URL
|
||||||
BASE_DIR = Path(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
|
||||||
DB_DIR = BASE_DIR / "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,
|
||||||
|
14
start.py
Normal file
14
start.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
# Add the project root to the Python path
|
||||||
|
BASE_DIR = Path(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
sys.path.insert(0, str(BASE_DIR))
|
||||||
|
|
||||||
|
# Import the app from main.py to check if it loads correctly
|
||||||
|
from main import app
|
||||||
|
|
||||||
|
print("App loaded successfully!")
|
||||||
|
print(f"App name: {app.title}")
|
||||||
|
print("If you can see this message, the error has been fixed.")
|
Loading…
x
Reference in New Issue
Block a user