[PR #24197] fix: add idempotency to PostgreSQL migrations to prevent DuplicateTable/UniqueViolation errors #50545

Open
opened 2026-04-30 03:19:23 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/24197
Author: @juanpabloequihua
Created: 4/28/2026
Status: 🔄 Open

Base: devHead: fix-postgres-migrations


📝 Commits (1)

  • cf77c47 fix: add idempotency to postgres migrations to prevent duplicate key/table errors

📊 Changes

6 files changed (+212 additions, -118 deletions)

View changed files

📝 backend/open_webui/migrations/versions/56359461a091_add_calendar_tables.py (+81 -49)
📝 backend/open_webui/migrations/versions/a3dd5bedd151_add_tasks_and_summary_to_chat.py (+16 -3)
📝 backend/open_webui/migrations/versions/b7c8d9e0f1a2_add_last_read_at_to_chat.py (+8 -3)
📝 backend/open_webui/migrations/versions/c1d2e3f4a5b6_add_shared_chat_table.py (+51 -33)
📝 backend/open_webui/migrations/versions/d4e5f6a7b8c9_add_automation_tables.py (+49 -29)
📝 backend/open_webui/migrations/versions/e1f2a3b4c5d6_add_is_pinned_to_note.py (+7 -1)

📄 Description

Description
Adds existence checks (idempotency) for tables, columns, indexes, and grant records across 6 migration files. This prevents migration failures (specifically psycopg2.errors.UniqueViolation and psycopg2.errors.DuplicateTable) on PostgreSQL deployments. This is especially critical for large databases (100GB+) or environments where a migration might partially execute and then fail on a subsequent restart.

Changelog Entry

Fixed

  • Added existence checks to migrations a3dd5bedd151, d4e5f6a7b8c9, b7c8d9e0f1a2, e1f2a3b4c5d6, c1d2e3f4a5b6, and 56359461a091.
  • Resolved UniqueViolation in access_grant table migration by checking for existing records before insertion.
  • Resolved DuplicateTable and DuplicateColumn errors by using has_table and information_schema checks.

Additional Information

Before submitting, make sure you've checked the following:

  • Target branch: Verify that the pull request targets the dev branch. PRs targeting main will be immediately closed.
  • Description: (Provided above)
  • Changelog: (Provided above)
  • Documentation: Add docs in Open WebUI Docs Repository. Document user-facing behavior, environment variables, public APIs/interfaces, or deployment steps.
  • Dependencies: No new dependencies
  • Agentic AI Code: Confirm this Pull Request is not written by any AI Agent or has at least gone through additional human review AND manual testing. If any AI Agent is the co-author of this PR, it may lead to immediate closure of the PR.
  • Code review: Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
  • Design & Architecture: Prefer smart defaults over adding new settings; use local state for ephemeral UI logic. Open a Discussion for major architectural or UX changes.
  • Git Hygiene: Keep PRs atomic (one logical change). Clean up commits and rebase on dev to ensure no unrelated commits (e.g. from main) are included. Push updates to the existing PR branch instead of closing and reopening.
  • Title Prefix: To clearly categorize this pull request, prefix the pull request title using one of the following:
    • BREAKING CHANGE: Significant changes that may affect compatibility
    • build: Changes that affect the build system or external dependencies
    • ci: Changes to our continuous integration processes or workflows
    • chore: Refactor, cleanup, or other non-functional code changes
    • docs: Documentation update or addition
    • feat: Introduces a new feature or enhancement to the codebase
    • fix: Bug fix or error correction
    • i18n: Internationalization or localization changes
    • perf: Performance improvement
    • refactor: Code restructuring for better maintainability, readability, or scalability
    • style: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc.)
    • test: Adding missing tests or correcting existing tests
    • WIP: Work in progress, a temporary label for incomplete or ongoing work

Contributor License Agreement

Note

Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/24197 **Author:** [@juanpabloequihua](https://github.com/juanpabloequihua) **Created:** 4/28/2026 **Status:** 🔄 Open **Base:** `dev` ← **Head:** `fix-postgres-migrations` --- ### 📝 Commits (1) - [`cf77c47`](https://github.com/open-webui/open-webui/commit/cf77c47a03e2b84a4b8d0f50c7aa75998d39fe2b) fix: add idempotency to postgres migrations to prevent duplicate key/table errors ### 📊 Changes **6 files changed** (+212 additions, -118 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/migrations/versions/56359461a091_add_calendar_tables.py` (+81 -49) 📝 `backend/open_webui/migrations/versions/a3dd5bedd151_add_tasks_and_summary_to_chat.py` (+16 -3) 📝 `backend/open_webui/migrations/versions/b7c8d9e0f1a2_add_last_read_at_to_chat.py` (+8 -3) 📝 `backend/open_webui/migrations/versions/c1d2e3f4a5b6_add_shared_chat_table.py` (+51 -33) 📝 `backend/open_webui/migrations/versions/d4e5f6a7b8c9_add_automation_tables.py` (+49 -29) 📝 `backend/open_webui/migrations/versions/e1f2a3b4c5d6_add_is_pinned_to_note.py` (+7 -1) </details> ### 📄 Description **Description** Adds existence checks (idempotency) for tables, columns, indexes, and grant records across 6 migration files. This prevents migration failures (specifically `psycopg2.errors.UniqueViolation` and `psycopg2.errors.DuplicateTable`) on PostgreSQL deployments. This is especially critical for large databases (100GB+) or environments where a migration might partially execute and then fail on a subsequent restart. **Changelog Entry** ### Fixed - Added existence checks to migrations `a3dd5bedd151`, `d4e5f6a7b8c9`, `b7c8d9e0f1a2`, `e1f2a3b4c5d6`, `c1d2e3f4a5b6`, and `56359461a091`. - Resolved `UniqueViolation` in `access_grant` table migration by checking for existing records before insertion. - Resolved `DuplicateTable` and `DuplicateColumn` errors by using `has_table` and information_schema checks. **Additional Information** - Relates to Issue #24129 - Manually tested on a production-scale PostgreSQL database (100GB+) where the original migrations were failing. **Before submitting, make sure you've checked the following:** - [X] **Target branch:** Verify that the pull request targets the `dev` branch. **PRs targeting `main` will be immediately closed.** - [X] **Description:** (Provided above) - [X] **Changelog:** (Provided above) - [ ] **Documentation:** Add docs in [Open WebUI Docs Repository](https://github.com/open-webui/docs). Document user-facing behavior, environment variables, public APIs/interfaces, or deployment steps. - [X] **Dependencies:** No new dependencies - [X] **Agentic AI Code:** Confirm this Pull Request is **not written by any AI Agent** or has at least **gone through additional human review AND manual testing**. If any AI Agent is the co-author of this PR, it may lead to immediate closure of the PR. - [X] **Code review:** Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards? - [X] **Design & Architecture:** Prefer smart defaults over adding new settings; use local state for ephemeral UI logic. Open a Discussion for major architectural or UX changes. - [X] **Git Hygiene:** Keep PRs atomic (one logical change). Clean up commits and rebase on `dev` to ensure no unrelated commits (e.g. from `main`) are included. Push updates to the existing PR branch instead of closing and reopening. - [X] **Title Prefix:** To clearly categorize this pull request, prefix the pull request title using one of the following: - **BREAKING CHANGE**: Significant changes that may affect compatibility - **build**: Changes that affect the build system or external dependencies - **ci**: Changes to our continuous integration processes or workflows - **chore**: Refactor, cleanup, or other non-functional code changes - **docs**: Documentation update or addition - **feat**: Introduces a new feature or enhancement to the codebase - **fix**: Bug fix or error correction - **i18n**: Internationalization or localization changes - **perf**: Performance improvement - **refactor**: Code restructuring for better maintainability, readability, or scalability - **style**: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc.) - **test**: Adding missing tests or correcting existing tests - **WIP**: Work in progress, a temporary label for incomplete or ongoing work ### Contributor License Agreement <!-- 🚨 DO NOT DELETE THE TEXT BELOW 🚨 Keep the "Contributor License Agreement" confirmation text intact. Deleting it will trigger the CLA-Bot to INVALIDATE your PR. Your PR will NOT be reviewed or merged until you check the box below confirming that you have read and agree to the terms of the CLA. --> - [X] By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. > [!NOTE] > Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-30 03:19:23 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#50545