mirror of
https://github.com/open-webui/open-webui.git
synced 2026-07-16 14:39:31 -05:00
Schema clashes when using Postgresql as database #2979
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?
Originally created by @MadsLang on GitHub (Dec 10, 2024).
TLDR
No explicit schema definition clashes with reserved keywords, when migrating database to postgresql. Would it be a good solution to add schema definition together with the DATABASE_URL environment variable?
Description of the problem
I am trying to host my database for OpenWebUI as a postgresql database in Cloud SQL in Google Cloud Platform. I am deploying the Docker container for OpenWebUI and specifying the database connection string in the DATABASE_URL environment variable (as specified at the documentation).
The connection seems to be working fine, but when trying to log into the UI, I am getting the error: "The email or password provided is incorrect. Please check for typos and try logging in again.". I am also using trusted header to authenticate (which have been working fine before when I was using native sqlite as database).
The problem seems to be that when authenticating the user, the backend is querying the table "user" in the database (using the ORM defined by Users.get_user_by_email - see
29a2719595/backend/open_webui/apps/webui/routers/auths.py (L316)).In Postgresql the name "user" is a reserved keyword, which means that this query is getting the sql-users in my deployment of postgres - rather than the user table defined by OpenWebUI. I have checked this by just querying my postgresql-database directly:
select * from userwhereasselect * from "user"andselect * from public.usergets the correct table of users.Possible solution
I suspect that simply being able to specify a schema for postgresql would suffice. I think that optimally, it would just be another environment variable that you could add. The value could then be added when creating the sqlalchemy connection. For example adding it to
declarative_basein (https://github.com/open-webui/open-webui/blob/main/backend/open_webui/apps/webui/internal/db.py#L102)See also defining explicit schema with the MetaData class
PR?
I am willing to make a PR, if this would be a good solution to fixing this issue?