Schema clashes when using Postgresql as database #2979

Closed
opened 2025-11-11 15:18:51 -06:00 by GiteaMirror · 0 comments
Owner

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 user whereas select * from "user" and select * from public.user gets 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_base in (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?

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](https://docs.openwebui.com/getting-started/advanced-topics/env-configuration/#database_url)). 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 https://github.com/open-webui/open-webui/blob/29a271959556743e6deb4d55a5a982983335d7ab/backend/open_webui/apps/webui/routers/auths.py#L316). In Postgresql the name "user" is [a reserved keyword](https://www.postgresql.org/docs/current/sql-keywords-appendix.html), 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 user` whereas `select * from "user"` and `select * from public.user` gets 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_base` in (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](https://docs.sqlalchemy.org/en/14/orm/declarative_tables.html#explicit-schema-name-with-declarative-table) ## PR? I am willing to make a PR, if this would be a good solution to fixing this issue?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#2979