From 9fe62fc80d2a9025ffd91fd7410e6497144a1bb3 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Fri, 6 Sep 2024 05:30:16 +0200 Subject: [PATCH] refac --- .../open_webui/migrations/scripts/revision.py | 19 +++++++++ .../migrations/versions/7e5b5dc7342b_init.py | 42 +++++-------------- 2 files changed, 30 insertions(+), 31 deletions(-) create mode 100644 backend/open_webui/migrations/scripts/revision.py diff --git a/backend/open_webui/migrations/scripts/revision.py b/backend/open_webui/migrations/scripts/revision.py new file mode 100644 index 000000000..32ebc9e35 --- /dev/null +++ b/backend/open_webui/migrations/scripts/revision.py @@ -0,0 +1,19 @@ +from alembic import command +from alembic.config import Config + +from open_webui.env import OPEN_WEBUI_DIR + +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)) + + +def revision(message: str) -> None: + command.revision(alembic_cfg, message=message, autogenerate=False) + + +if __name__ == "__main__": + input_message = input("Enter the revision message: ") + revision(input_message) diff --git a/backend/open_webui/migrations/versions/7e5b5dc7342b_init.py b/backend/open_webui/migrations/versions/7e5b5dc7342b_init.py index 62d0f8588..607a7b2c9 100644 --- a/backend/open_webui/migrations/versions/7e5b5dc7342b_init.py +++ b/backend/open_webui/migrations/versions/7e5b5dc7342b_init.py @@ -11,8 +11,8 @@ from typing import Sequence, Union import sqlalchemy as sa from alembic import op - import open_webui.apps.webui.internal.db +from open_webui.apps.webui.internal.db import JSONField from open_webui.migrations.util import get_existing_tables # revision identifiers, used by Alembic. @@ -82,9 +82,7 @@ def upgrade() -> None: sa.Column("id", sa.String(), nullable=False), sa.Column("user_id", sa.String(), nullable=True), sa.Column("filename", sa.Text(), nullable=True), - sa.Column( - "meta", open_webui.apps.webui.internal.db.JSONField(), nullable=True - ), + sa.Column("meta", JSONField(), nullable=True), sa.Column("created_at", sa.BigInteger(), nullable=True), sa.PrimaryKeyConstraint("id"), ) @@ -97,12 +95,8 @@ def upgrade() -> None: sa.Column("name", sa.Text(), nullable=True), sa.Column("type", sa.Text(), nullable=True), sa.Column("content", sa.Text(), nullable=True), - sa.Column( - "meta", open_webui.apps.webui.internal.db.JSONField(), nullable=True - ), - sa.Column( - "valves", open_webui.apps.webui.internal.db.JSONField(), nullable=True - ), + sa.Column("meta", JSONField(), nullable=True), + sa.Column("valves", JSONField(), nullable=True), sa.Column("is_active", sa.Boolean(), nullable=True), sa.Column("is_global", sa.Boolean(), nullable=True), sa.Column("updated_at", sa.BigInteger(), nullable=True), @@ -128,12 +122,8 @@ def upgrade() -> None: sa.Column("user_id", sa.Text(), nullable=True), sa.Column("base_model_id", sa.Text(), nullable=True), sa.Column("name", sa.Text(), nullable=True), - sa.Column( - "params", open_webui.apps.webui.internal.db.JSONField(), nullable=True - ), - sa.Column( - "meta", open_webui.apps.webui.internal.db.JSONField(), nullable=True - ), + sa.Column("params", JSONField(), nullable=True), + sa.Column("meta", JSONField(), nullable=True), sa.Column("updated_at", sa.BigInteger(), nullable=True), sa.Column("created_at", sa.BigInteger(), nullable=True), sa.PrimaryKeyConstraint("id"), @@ -167,15 +157,9 @@ def upgrade() -> None: sa.Column("user_id", sa.String(), nullable=True), sa.Column("name", sa.Text(), nullable=True), sa.Column("content", sa.Text(), nullable=True), - sa.Column( - "specs", open_webui.apps.webui.internal.db.JSONField(), nullable=True - ), - sa.Column( - "meta", open_webui.apps.webui.internal.db.JSONField(), nullable=True - ), - sa.Column( - "valves", open_webui.apps.webui.internal.db.JSONField(), nullable=True - ), + sa.Column("specs", JSONField(), nullable=True), + sa.Column("meta", JSONField(), nullable=True), + sa.Column("valves", JSONField(), nullable=True), sa.Column("updated_at", sa.BigInteger(), nullable=True), sa.Column("created_at", sa.BigInteger(), nullable=True), sa.PrimaryKeyConstraint("id"), @@ -193,12 +177,8 @@ def upgrade() -> None: sa.Column("updated_at", sa.BigInteger(), nullable=True), sa.Column("created_at", sa.BigInteger(), nullable=True), sa.Column("api_key", sa.String(), nullable=True), - sa.Column( - "settings", open_webui.apps.webui.internal.db.JSONField(), nullable=True - ), - sa.Column( - "info", open_webui.apps.webui.internal.db.JSONField(), nullable=True - ), + sa.Column("settings", JSONField(), nullable=True), + sa.Column("info", JSONField(), nullable=True), sa.Column("oauth_sub", sa.Text(), nullable=True), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("api_key"),