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:
parent
afb29d695c
commit
1ce4b4d932
@ -35,7 +35,7 @@ script_location = alembic
|
||||
# are written from script.py.mako
|
||||
# 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 defines scripts or Python functions that are run
|
||||
|
@ -19,6 +19,10 @@ from app.database.database import Base
|
||||
# access to the values within the .ini file in use.
|
||||
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.
|
||||
# This line sets up loggers basically.
|
||||
fileConfig(config.config_file_name)
|
||||
|
@ -4,11 +4,12 @@ from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
# Create database directory if it doesn't exist
|
||||
DB_DIR = Path("/app") / "storage" / "db"
|
||||
# DB_DIR.mkdir(parents=True, exist_ok=True)
|
||||
PROJECT_ROOT = Path("/projects/simpletodoapp-njekzu")
|
||||
DB_DIR = PROJECT_ROOT / "app" / "storage" / "db"
|
||||
DB_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Database URL
|
||||
# SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite"
|
||||
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite"
|
||||
|
||||
# Create engine
|
||||
engine = create_engine(
|
||||
@ -17,15 +18,15 @@ engine = create_engine(
|
||||
)
|
||||
|
||||
# Create session
|
||||
# SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
|
||||
# Create base class
|
||||
Base = declarative_base()
|
||||
|
||||
# Dependency
|
||||
# def get_db():
|
||||
# db = SessionLocal()
|
||||
# try:
|
||||
# yield db
|
||||
# finally:
|
||||
# db.close()
|
||||
def get_db():
|
||||
db = SessionLocal()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
Loading…
x
Reference in New Issue
Block a user