Some checks failed
Create and publish Docker images with specific build args / build-main-image (linux/amd64, ubuntu-latest) (push) Has been cancelled
Create and publish Docker images with specific build args / build-main-image (linux/arm64, ubuntu-24.04-arm) (push) Has been cancelled
Create and publish Docker images with specific build args / build-cuda-image (linux/amd64, ubuntu-latest) (push) Has been cancelled
Create and publish Docker images with specific build args / build-cuda-image (linux/arm64, ubuntu-24.04-arm) (push) Has been cancelled
Create and publish Docker images with specific build args / build-cuda126-image (linux/amd64, ubuntu-latest) (push) Has been cancelled
Create and publish Docker images with specific build args / build-cuda126-image (linux/arm64, ubuntu-24.04-arm) (push) Has been cancelled
Create and publish Docker images with specific build args / build-ollama-image (linux/amd64, ubuntu-latest) (push) Has been cancelled
Create and publish Docker images with specific build args / build-ollama-image (linux/arm64, ubuntu-24.04-arm) (push) Has been cancelled
Create and publish Docker images with specific build args / build-slim-image (linux/amd64, ubuntu-latest) (push) Has been cancelled
Create and publish Docker images with specific build args / build-slim-image (linux/arm64, ubuntu-24.04-arm) (push) Has been cancelled
Create and publish Docker images with specific build args / merge-main-images (push) Has been cancelled
Create and publish Docker images with specific build args / merge-cuda-images (push) Has been cancelled
Create and publish Docker images with specific build args / merge-cuda126-images (push) Has been cancelled
Create and publish Docker images with specific build args / merge-ollama-images (push) Has been cancelled
Create and publish Docker images with specific build args / merge-slim-images (push) Has been cancelled
Python CI / Format Backend (3.11.x) (push) Has been cancelled
Python CI / Format Backend (3.12.x) (push) Has been cancelled
Frontend Build / Format & Build Frontend (push) Has been cancelled
Frontend Build / Frontend Unit Tests (push) Has been cancelled
Close inactive issues / close-issues (push) Has been cancelled
78 lines
2.5 KiB
Python
78 lines
2.5 KiB
Python
from open_webui.env import OPEN_WEBUI_DIR, log
|
|
from open_webui.internal.db import Session
|
|
from sqlalchemy import text
|
|
|
|
|
|
# Function to run the alembic migrations
|
|
def run_migrations():
|
|
log.info("Running migrations")
|
|
try:
|
|
from alembic import command
|
|
from alembic.config import Config
|
|
|
|
alembic_cfg = Config(OPEN_WEBUI_DIR / "alembic.ini")
|
|
|
|
# Set the script location dynamically
|
|
migrations_path = OPEN_WEBUI_DIR / "migrations"
|
|
alembic_cfg.set_main_option("script_location", str(migrations_path))
|
|
|
|
command.upgrade(alembic_cfg, "head")
|
|
except Exception as e:
|
|
log.exception(f"Error running migrations: {e}")
|
|
|
|
|
|
def run_extra_migrations():
|
|
"""
|
|
Only create table or index is allowed here.
|
|
"""
|
|
custom_migrations = [
|
|
{"base": "3781e22d8b01", "upgrade_to": "1403e6d80d1d"},
|
|
{"base": "d31026856c01", "upgrade_to": "97c08d196e3d"},
|
|
]
|
|
log.info("Running extra migrations")
|
|
# do migrations
|
|
try:
|
|
# load version from db
|
|
current_version = Session.execute(
|
|
text("SELECT version_num FROM alembic_version")
|
|
).scalar_one()
|
|
|
|
# init alembic
|
|
from alembic import command
|
|
from alembic.config import Config
|
|
|
|
alembic_cfg = Config(OPEN_WEBUI_DIR / "alembic.ini")
|
|
migrations_path = OPEN_WEBUI_DIR / "migrations"
|
|
alembic_cfg.set_main_option("script_location", str(migrations_path))
|
|
|
|
# do migrations
|
|
for migration in custom_migrations:
|
|
try:
|
|
command.stamp(alembic_cfg, migration["base"])
|
|
command.upgrade(alembic_cfg, migration["upgrade_to"])
|
|
except Exception as err:
|
|
err = str(err)
|
|
if err.index("already exists") != -1 or err.index("duplicate") != -1:
|
|
log.info(
|
|
"skip migrate %s to %s: already exists",
|
|
migration["base"],
|
|
migration["upgrade_to"],
|
|
)
|
|
continue
|
|
log.warning(
|
|
"failed to migrate %s to %s: %s",
|
|
migration["base"],
|
|
migration["upgrade_to"],
|
|
err,
|
|
)
|
|
|
|
# stamp to current version
|
|
command.stamp(alembic_cfg, current_version)
|
|
except Exception as e:
|
|
log.exception("Error running extra migrations: %s", e)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
run_migrations()
|
|
run_extra_migrations()
|