Fix database configuration paths for development environment

- Updated database path in database.py to use project root path
- Updated alembic.ini to use correct database path
- Modified alembic env.py to directly use database URL from code

generated with BackendIM... (backend.im)
This commit is contained in:
Automated Action 2025-05-13 14:34:47 +00:00
parent afb29d695c
commit 1ce4b4d932
3 changed files with 16 additions and 11 deletions

View File

@ -35,7 +35,7 @@ script_location = alembic
# are written from script.py.mako # are written from script.py.mako
# output_encoding = utf-8 # output_encoding = utf-8
sqlalchemy.url = sqlite:////app/storage/db/db.sqlite sqlalchemy.url = sqlite:////projects/simpletodoapp-njekzu/app/storage/db/db.sqlite
[post_write_hooks] [post_write_hooks]
# post_write_hooks defines scripts or Python functions that are run # post_write_hooks defines scripts or Python functions that are run

View File

@ -19,6 +19,10 @@ from app.database.database import Base
# access to the values within the .ini file in use. # access to the values within the .ini file in use.
config = context.config config = context.config
# Set the database URL directly from our database module
from app.database.database import SQLALCHEMY_DATABASE_URL
config.set_main_option("sqlalchemy.url", SQLALCHEMY_DATABASE_URL)
# Interpret the config file for Python logging. # Interpret the config file for Python logging.
# This line sets up loggers basically. # This line sets up loggers basically.
fileConfig(config.config_file_name) fileConfig(config.config_file_name)

View File

@ -4,11 +4,12 @@ from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker from sqlalchemy.orm import sessionmaker
# Create database directory if it doesn't exist # Create database directory if it doesn't exist
DB_DIR = Path("/app") / "storage" / "db" PROJECT_ROOT = Path("/projects/simpletodoapp-njekzu")
# DB_DIR.mkdir(parents=True, exist_ok=True) DB_DIR = PROJECT_ROOT / "app" / "storage" / "db"
DB_DIR.mkdir(parents=True, exist_ok=True)
# Database URL # Database URL
# SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite" SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite"
# Create engine # Create engine
engine = create_engine( engine = create_engine(
@ -17,15 +18,15 @@ engine = create_engine(
) )
# Create session # Create session
# SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
# Create base class # Create base class
Base = declarative_base() Base = declarative_base()
# Dependency # Dependency
# def get_db(): def get_db():
# db = SessionLocal() db = SessionLocal()
# try: try:
# yield db yield db
# finally: finally:
# db.close() db.close()