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
This commit is contained in:
parent
07301a47e7
commit
66f95ea88e
@ -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]
|
||||
|
@ -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"
|
||||
|
5
main.py
5
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():
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user