From 66f95ea88ec7a15d126c9a7eec99f22fe70736cd Mon Sep 17 00:00:00 2001 From: Automated Action Date: Sun, 18 May 2025 19:15:35 +0000 Subject: [PATCH] Fix database path for standalone environment - Modified database connection to use project-relative paths - Updated Alembic configuration to dynamically use the SQLAlchemy URL - Added a root endpoint for easy testing - Fixed imports in migration environment --- alembic.ini | 3 ++- app/db/database.py | 4 +++- main.py | 5 +++++ migrations/env.py | 5 ++++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/alembic.ini b/alembic.ini index 1d8c6ca..d0b5e48 100644 --- a/alembic.ini +++ b/alembic.ini @@ -36,7 +36,8 @@ script_location = migrations # output_encoding = utf-8 # SQLite URL example -sqlalchemy.url = sqlite:////app/storage/db/db.sqlite +# This will be overridden programmatically in env.py +sqlalchemy.url = driver://user:pass@localhost/dbname # Logging configuration [loggers] diff --git a/app/db/database.py b/app/db/database.py index 1fae7b1..2fb6328 100644 --- a/app/db/database.py +++ b/app/db/database.py @@ -4,7 +4,9 @@ from sqlalchemy import create_engine, MetaData from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker, Session -DB_DIR = Path("/app") / "storage" / "db" +# Get the project root directory +PROJECT_ROOT = Path(__file__).parent.parent.parent.absolute() +DB_DIR = PROJECT_ROOT / "app" / "storage" / "db" DB_DIR.mkdir(parents=True, exist_ok=True) SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite" diff --git a/main.py b/main.py index f3b9c72..010e3e2 100644 --- a/main.py +++ b/main.py @@ -33,6 +33,11 @@ if settings.BACKEND_CORS_ORIGINS: # Include our router app.include_router(api_router, prefix=settings.API_V1_STR) +# Root endpoint for quick testing +@app.get("/") +async def root(): + return {"message": "Welcome to the Generic REST API Service. Visit /docs for documentation."} + # Custom documentation endpoints @app.get("/docs", include_in_schema=False) async def custom_swagger_ui_html(): diff --git a/migrations/env.py b/migrations/env.py index 5cb9e99..9992202 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -4,12 +4,15 @@ from sqlalchemy import engine_from_config from sqlalchemy import pool from alembic import context -from app.db.database import Base +from app.db.database import Base, SQLALCHEMY_DATABASE_URL # this is the Alembic Config object, which provides # access to the values within the .ini file in use. config = context.config +# Override the sqlalchemy.url from alembic.ini with our dynamically created URL +config.set_main_option("sqlalchemy.url", SQLALCHEMY_DATABASE_URL) + # Interpret the config file for Python logging. # This line sets up loggers basically. if config.config_file_name is not None: