feat(sqlalchemy): use subprocess to do migrations

This commit is contained in:
Jonathan Rohde 2024-06-24 09:50:14 +02:00
parent bee835cb65
commit 070d9083d5
2 changed files with 6 additions and 8 deletions

View File

@ -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]

View File

@ -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