mirror of
https://github.com/open-webui/open-webui.git
synced 2026-03-22 22:21:27 -05:00
[PR #1791] [MERGED] feat: add support for using postgres for the backend DB #7578
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/1791
Author: @cheahjs
Created: 4/27/2024
Status: ✅ Merged
Merged: 4/27/2024
Merged by: @tjbck
Base:
dev← Head:feat/external-db-support📝 Commits (2)
e91a49cfeat: add support for using postgres for the backend DB47a33acfeat: show error toast if trying to download db on external db📊 Changes
19 files changed (+350 additions, -24 deletions)
View changed files
📝
backend/apps/litellm/main.py(+12 -1)📝
backend/apps/web/internal/db.py(+5 -4)📝
backend/apps/web/internal/migrations/001_initial_schema.py(+105 -0)📝
backend/apps/web/internal/migrations/005_add_updated_at.py(+53 -0)➕
backend/apps/web/internal/migrations/006_migrate_timestamps_and_charfields.py(+130 -0)📝
backend/apps/web/models/auths.py(+1 -1)📝
backend/apps/web/models/chats.py(+3 -3)📝
backend/apps/web/models/documents.py(+3 -3)📝
backend/apps/web/models/modelfiles.py(+1 -1)📝
backend/apps/web/models/prompts.py(+2 -2)📝
backend/apps/web/models/tags.py(+1 -1)📝
backend/apps/web/models/users.py(+2 -2)📝
backend/apps/web/routers/auths.py(+2 -0)📝
backend/apps/web/routers/utils.py(+8 -2)📝
backend/config.py(+7 -0)📝
backend/constants.py(+2 -0)📝
backend/requirements.txt(+2 -0)📝
src/lib/apis/utils/index.ts(+7 -3)📝
src/lib/components/admin/Settings/Database.svelte(+4 -1)📄 Description
Pull Request Checklist
Description
Addresses the application DB portion of https://github.com/open-webui/open-webui/issues/1397
Adds a new env var
DATABASE_URLthat can be used to point to a SQLite database, Postgres database, or MySQL database. I have only tested with SQLite and Postgres. The URL schema can be found at https://docs.peewee-orm.com/en/latest/peewee/playhouse.html#connectAs part of this work, a few schema migrations were done.
DateFieldandDateTimeFieldwere migrated toBigIntegerFielddateordatetimefields.date/datetimetointeger, as this requires casting and custom logic per database/CharFields were migrated toTextFields.CharFieldhas a default max length of 255, but SQLite doesn't enforce this length limit.This does not migrate an existing SQLite DB onto a remote DB.
To test locally with Postgres,
docker run --name webui-postgres -e POSTGRES_PASSWORD=mysecretpassword -p:5433:5432 --rm postgresDATABASE_URL=postgres://postgres:mysecretpassword@localhost:5433/postgres GLOBAL_LOG_LEVEL=DEBUG ./dev.shChangelog Entry
Added
DATABASE_URLenvironment variable.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.