diff --git a/backend/alembic.ini b/backend/alembic.ini index 72f2b762b..4eff85f0c 100644 --- a/backend/alembic.ini +++ b/backend/alembic.ini @@ -58,7 +58,7 @@ version_path_separator = os # Use os.pathsep. Default configuration used for ne # are written from script.py.mako # output_encoding = utf-8 -sqlalchemy.url = REPLACE_WITH_DATABASE_URL +# sqlalchemy.url = REPLACE_WITH_DATABASE_URL [post_write_hooks] diff --git a/backend/main.py b/backend/main.py index 6e44045f2..8892d9bc7 100644 --- a/backend/main.py +++ b/backend/main.py @@ -173,13 +173,11 @@ https://github.com/open-webui/open-webui def run_migrations(): - from alembic.config import Config - from alembic import command - - alembic_cfg = Config(f"{BACKEND_DIR}/alembic.ini") - alembic_cfg.set_main_option("sqlalchemy.url", DATABASE_URL) - alembic_cfg.set_main_option("script_location", f"{BACKEND_DIR}/migrations") - command.upgrade(alembic_cfg, "head") + env = os.environ.copy() + env["DATABASE_URL"] = DATABASE_URL + migration_task = subprocess.run(["alembic", f"-c{BACKEND_DIR}/alembic.ini", "upgrade", "head"], env=env) + if migration_task.returncode > 0: + raise ValueError("Error running migrations") @asynccontextmanager