diff --git a/alembic.ini b/alembic.ini index 612fb12..cb9626f 100644 --- a/alembic.ini +++ b/alembic.ini @@ -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 diff --git a/alembic/env.py b/alembic/env.py index 092ebfb..f3ab0e6 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -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) diff --git a/app/database/database.py b/app/database/database.py index d443a99..798b92f 100644 --- a/app/database/database.py +++ b/app/database/database.py @@ -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() \ No newline at end of file +def get_db(): + db = SessionLocal() + try: + yield db + finally: + db.close() \ No newline at end of file