Fix database path configuration for container environment
This commit is contained in:
parent
3b82051f44
commit
5c580db609
@ -36,8 +36,9 @@ script_location = migrations
|
||||
# output_encoding = utf-8
|
||||
|
||||
# SQLite URL example
|
||||
# For container environment, use the proper path
|
||||
sqlalchemy.url = sqlite:////projects/bloggingplatformapi-lncxqv/storage/db/db.sqlite
|
||||
# This URL is just a placeholder and will be overridden by env.py
|
||||
# using the same path calculation logic as in app/db/session.py
|
||||
sqlalchemy.url = driver://user:pass@localhost/dbname
|
||||
|
||||
[post_write_hooks]
|
||||
# post_write_hooks defines scripts or Python functions that are run
|
||||
|
@ -1,13 +1,25 @@
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from pathlib import Path
|
||||
import os
|
||||
|
||||
|
||||
# Get the project root directory
|
||||
PROJECT_ROOT = Path("/projects/bloggingplatformapi-lncxqv")
|
||||
# Check if we're running in the container environment at /app/repo
|
||||
IN_CONTAINER = os.path.exists('/app/repo')
|
||||
|
||||
# Set the database directory path based on the environment
|
||||
if IN_CONTAINER:
|
||||
# Container path
|
||||
DB_DIR = Path("/app/repo/storage/db")
|
||||
else:
|
||||
# Local development path - using either the project directory or fallback to /app
|
||||
PROJECT_ROOT = Path("/projects/bloggingplatformapi-lncxqv")
|
||||
if PROJECT_ROOT.exists():
|
||||
DB_DIR = PROJECT_ROOT / "storage" / "db"
|
||||
else:
|
||||
DB_DIR = Path("/app/storage/db")
|
||||
|
||||
# Create the directory for the database if it doesn't exist
|
||||
DB_DIR = PROJECT_ROOT / "storage" / "db"
|
||||
DB_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite"
|
||||
|
@ -30,6 +30,30 @@ except ImportError:
|
||||
# access to the values within the .ini file in use.
|
||||
config = context.config
|
||||
|
||||
# Set up the database URL dynamically based on environment
|
||||
# Check if we're running in the container environment at /app/repo
|
||||
IN_CONTAINER = os.path.exists('/app/repo')
|
||||
|
||||
# Set the database directory path based on the environment
|
||||
if IN_CONTAINER:
|
||||
# Container path
|
||||
DB_DIR = Path("/app/repo/storage/db")
|
||||
else:
|
||||
# Local development path - using either the project directory or fallback to /app
|
||||
PROJECT_ROOT = Path("/projects/bloggingplatformapi-lncxqv")
|
||||
if PROJECT_ROOT.exists():
|
||||
DB_DIR = PROJECT_ROOT / "storage" / "db"
|
||||
else:
|
||||
DB_DIR = Path("/app/storage/db")
|
||||
|
||||
# Create the directory for the database if it doesn't exist
|
||||
DB_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite"
|
||||
|
||||
# Override the URL in the config with our dynamic URL
|
||||
config.set_main_option("sqlalchemy.url", SQLALCHEMY_DATABASE_URL)
|
||||
|
||||
# Interpret the config file for Python logging.
|
||||
# This line sets up loggers basically.
|
||||
fileConfig(config.config_file_name)
|
||||
|
Loading…
x
Reference in New Issue
Block a user