[PR #22717] [CLOSED] fix: add missing primary key constraints to legacy Peewee tables #114139

Closed
opened 2026-05-18 14:47:11 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/22717
Author: @ryan-pip
Created: 3/16/2026
Status: Closed

Base: devHead: fix/add-missing-primary-keys


📝 Commits (1)

  • 7f7cf8f fix: add missing primary key constraints to legacy Peewee tables

📊 Changes

1 file changed (+51 additions, -0 deletions)

View changed files

backend/open_webui/migrations/versions/c3d4e5f6a7b8_add_missing_primary_keys.py (+51 -0)

📄 Description

Closes / relates to: https://github.com/open-webui/open-webui/discussions/22716

Description

Tables originally created by the legacy Peewee migration system have only UNIQUE constraints on their id columns — not PRIMARY KEY constraints. When the project migrated to Alembic, the init migration skips tables that already exist, so the PKs were never added.

This PR adds a new Alembic migration (c3d4e5f6a7b8) that retroactively promotes the unique constraint to a primary key for all 7 affected tables.

Changelog

Fixed

  • 🗄️ Missing primary keys on legacy Peewee tables. Tables created by
    the legacy Peewee migration system (chat, chatidtag, file,
    function, memory, model, tool) were missing PRIMARY KEY
    constraints on their id columns. A new Alembic migration
    (c3d4e5f6a7b8) retroactively adds the primary key and drops the
    now-redundant unique constraint. The migration is idempotent and safe
    to run on databases that were already migrated through Alembic.

Checklist

  • I have read the Contributing Guidelines
  • I have opened a GitHub Discussion before submitting this PR: https://github.com/open-webui/open-webui/discussions/22716
  • The PR targets the dev branch, not main
  • The migration is idempotent — upgrade() checks the existing PK constraint before acting
  • downgrade() removes the PK cleanly
  • Tested against a Peewee-originated DB (alembic upgrade head → PKs present, unique constraints removed)
  • Verified no-op on a fresh Alembic-only DB
  • This PR contains code that was assisted or generated by an AI tool

📌 CLA

By submitting this pull request, I confirm that my contribution is made under the terms of the project's license and that I have the right to submit it.


🔄 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/22717 **Author:** [@ryan-pip](https://github.com/ryan-pip) **Created:** 3/16/2026 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `fix/add-missing-primary-keys` --- ### 📝 Commits (1) - [`7f7cf8f`](https://github.com/open-webui/open-webui/commit/7f7cf8fb29249e4ce41a1901c511ff652117d989) fix: add missing primary key constraints to legacy Peewee tables ### 📊 Changes **1 file changed** (+51 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `backend/open_webui/migrations/versions/c3d4e5f6a7b8_add_missing_primary_keys.py` (+51 -0) </details> ### 📄 Description Closes / relates to: https://github.com/open-webui/open-webui/discussions/22716 ## Description Tables originally created by the legacy Peewee migration system have only `UNIQUE` constraints on their `id` columns — not `PRIMARY KEY` constraints. When the project migrated to Alembic, the init migration skips tables that already exist, so the PKs were never added. This PR adds a new Alembic migration (`c3d4e5f6a7b8`) that retroactively promotes the unique constraint to a primary key for all 7 affected tables. ## Changelog ### Fixed - 🗄️ **Missing primary keys on legacy Peewee tables.** Tables created by the legacy Peewee migration system (`chat`, `chatidtag`, `file`, `function`, `memory`, `model`, `tool`) were missing `PRIMARY KEY` constraints on their `id` columns. A new Alembic migration (`c3d4e5f6a7b8`) retroactively adds the primary key and drops the now-redundant unique constraint. The migration is idempotent and safe to run on databases that were already migrated through Alembic. ## Checklist - [x] I have read the [Contributing Guidelines](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTING.md) - [x] I have opened a GitHub Discussion before submitting this PR: https://github.com/open-webui/open-webui/discussions/22716 - [x] The PR targets the `dev` branch, not `main` - [x] The migration is idempotent — `upgrade()` checks the existing PK constraint before acting - [x] `downgrade()` removes the PK cleanly - [x] Tested against a Peewee-originated DB (`alembic upgrade head` → PKs present, unique constraints removed) - [x] Verified no-op on a fresh Alembic-only DB - [x] This PR contains code that was assisted or generated by an AI tool ## 📌 CLA By submitting this pull request, I confirm that my contribution is made under the terms of the project's license and that I have the right to submit it. --- <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-05-18 14:47:11 -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#114139