diff --git a/backend/open_webui/config.py b/backend/open_webui/config.py index c5ac40babd..9851aa37ba 100644 --- a/backend/open_webui/config.py +++ b/backend/open_webui/config.py @@ -19,6 +19,7 @@ from authlib.integrations.starlette_client import OAuth from open_webui.env import ( DATA_DIR, DATABASE_URL, + ENABLE_DB_MIGRATIONS, ENV, REDIS_URL, REDIS_KEY_PREFIX, @@ -67,7 +68,8 @@ def run_migrations(): log.exception(f"Error running migrations: {e}") -run_migrations() +if ENABLE_DB_MIGRATIONS: + run_migrations() class Config(Base): diff --git a/backend/open_webui/env.py b/backend/open_webui/env.py index 1e977906c4..a5184aa4d5 100644 --- a/backend/open_webui/env.py +++ b/backend/open_webui/env.py @@ -117,6 +117,8 @@ VERSION = PACKAGE_DATA["version"] DEPLOYMENT_ID = os.environ.get("DEPLOYMENT_ID", "") INSTANCE_ID = os.environ.get("INSTANCE_ID", str(uuid4())) +ENABLE_DB_MIGRATIONS = os.environ.get("ENABLE_DB_MIGRATIONS", "True").lower() == "true" + # Function to parse each section def parse_section(section): diff --git a/backend/open_webui/internal/db.py b/backend/open_webui/internal/db.py index a5eecd6605..95571c2435 100644 --- a/backend/open_webui/internal/db.py +++ b/backend/open_webui/internal/db.py @@ -14,6 +14,7 @@ from open_webui.env import ( DATABASE_POOL_SIZE, DATABASE_POOL_TIMEOUT, DATABASE_ENABLE_SQLITE_WAL, + ENABLE_DB_MIGRATIONS, ) from peewee_migrate import Router from sqlalchemy import Dialect, create_engine, MetaData, event, types @@ -75,7 +76,8 @@ def handle_peewee_migration(DATABASE_URL): assert db.is_closed(), "Database connection is still open." -handle_peewee_migration(DATABASE_URL) +if ENABLE_DB_MIGRATIONS: + handle_peewee_migration(DATABASE_URL) SQLALCHEMY_DATABASE_URL = DATABASE_URL