[PR #3327] [MERGED] BREAKING CHANGE/sqlalchemy instead of peewee #8017

Closed
opened 2025-11-11 17:42:46 -06:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/3327
Author: @jonathan-rohde
Created: 6/20/2024
Status: Merged
Merged: 7/2/2024
Merged by: @tjbck

Base: dev-migrationHead: feat/sqlalchemy-instead-of-peewee


📝 Commits (10+)

  • df09d08 feat(sqlalchemy): Replace peewee with sqlalchemy
  • bee835c feat(sqlalchemy): remove session reference from router
  • 070d908 feat(sqlalchemy): use subprocess to do migrations
  • 320e658 feat(sqlalchemy): cleanup fixes
  • c134eab feat(sqlalchemy): format backend
  • eb01e8d feat(sqlalchemy): use scoped session
  • da403f3 feat(sqlalchemy): use session factory instead of context manager
  • a9b1487 feat(sqlalchemy): fix wrong column types
  • 8f939cf feat(sqlalchemy): some fixes
  • 2fb27ad feat(sqlalchemy): add missing file

📊 Changes

60 files changed (+2219 additions, -2109 deletions)

View changed files

📝 .github/workflows/integration-test.yml (+24 -2)
backend/alembic.ini (+114 -0)
📝 backend/apps/webui/internal/db.py (+32 -26)
backend/apps/webui/internal/migrations/001_initial_schema.py (+0 -254)
backend/apps/webui/internal/migrations/002_add_local_sharing.py (+0 -48)
backend/apps/webui/internal/migrations/003_add_auth_api_key.py (+0 -48)
backend/apps/webui/internal/migrations/004_add_archived.py (+0 -46)
backend/apps/webui/internal/migrations/005_add_updated_at.py (+0 -130)
backend/apps/webui/internal/migrations/006_migrate_timestamps_and_charfields.py (+0 -130)
backend/apps/webui/internal/migrations/007_add_user_last_active_at.py (+0 -79)
backend/apps/webui/internal/migrations/008_add_memory.py (+0 -53)
backend/apps/webui/internal/migrations/009_add_models.py (+0 -61)
backend/apps/webui/internal/migrations/010_migrate_modelfiles_to_models.py (+0 -130)
backend/apps/webui/internal/migrations/011_add_user_settings.py (+0 -48)
backend/apps/webui/internal/migrations/012_add_tools.py (+0 -61)
backend/apps/webui/internal/migrations/013_add_user_info.py (+0 -48)
backend/apps/webui/internal/migrations/014_add_files.py (+0 -55)
backend/apps/webui/internal/migrations/015_add_functions.py (+0 -61)
backend/apps/webui/internal/migrations/016_add_valves_and_is_active.py (+0 -50)
backend/apps/webui/internal/migrations/017_add_user_oauth_sub.py (+0 -49)

...and 40 more files

📄 Description

Pull Request Checklist

Note to first-time contributors: Please open a discussion post in Discussions and describe your changes before submitting a pull request.

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

  • Target branch: Please verify that the pull request targets the dev branch.
  • Description: Provide a concise description of the changes made in this pull request.
  • Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
  • Documentation: Have you updated relevant documentation Open WebUI Docs, or other documentation sources?
  • Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation?
  • Testing: Have you written and run sufficient tests for validating the changes?
  • 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?
  • Prefix: To cleary 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

Changelog Entry

Description

Replacing peewee with SQLAlchemy. The combination of FastAPI with Peewee is not supported and we should avoid using both libraries in parallel.
The change replaces the whole ORM model with SQLAlchemy and uses Alembic for schema migrations.
The initial database migration script is checking the database schema for table existence and skips table creation in case the table already exists.

Changed

  • Replace Peewee with SQLAlchemy
  • Replace peewee-migrate with alembic

Breaking Change

  • The fact that there might be columns added between installed versions is making the replacement of the migration a breaking change.

Additional Information


🔄 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/3327 **Author:** [@jonathan-rohde](https://github.com/jonathan-rohde) **Created:** 6/20/2024 **Status:** ✅ Merged **Merged:** 7/2/2024 **Merged by:** [@tjbck](https://github.com/tjbck) **Base:** `dev-migration` ← **Head:** `feat/sqlalchemy-instead-of-peewee` --- ### 📝 Commits (10+) - [`df09d08`](https://github.com/open-webui/open-webui/commit/df09d0830a1680a1028a5df0864d916d6b66d302) feat(sqlalchemy): Replace peewee with sqlalchemy - [`bee835c`](https://github.com/open-webui/open-webui/commit/bee835cb65a8b3feba6824d2e6c9378b95f6e990) feat(sqlalchemy): remove session reference from router - [`070d908`](https://github.com/open-webui/open-webui/commit/070d9083d5dd515c32bd7bf60aeecc56f5bc059c) feat(sqlalchemy): use subprocess to do migrations - [`320e658`](https://github.com/open-webui/open-webui/commit/320e658595918241c9bdab4f302017039d1ae694) feat(sqlalchemy): cleanup fixes - [`c134eab`](https://github.com/open-webui/open-webui/commit/c134eab27a929cbf678a60356a4c8f6c2e718201) feat(sqlalchemy): format backend - [`eb01e8d`](https://github.com/open-webui/open-webui/commit/eb01e8d2755a73f7c8db121d7b69b36bee1cae22) feat(sqlalchemy): use scoped session - [`da403f3`](https://github.com/open-webui/open-webui/commit/da403f3e3cf9ce700da2fdb477e0bdfc4794d37d) feat(sqlalchemy): use session factory instead of context manager - [`a9b1487`](https://github.com/open-webui/open-webui/commit/a9b148791d982b9635935a41ca6bdc3aa47165c3) feat(sqlalchemy): fix wrong column types - [`8f939cf`](https://github.com/open-webui/open-webui/commit/8f939cf55bc4a4de63c859f033cf5da5378e2d30) feat(sqlalchemy): some fixes - [`2fb27ad`](https://github.com/open-webui/open-webui/commit/2fb27adbf67c13d89ac652f3652f7a578a3bcb25) feat(sqlalchemy): add missing file ### 📊 Changes **60 files changed** (+2219 additions, -2109 deletions) <details> <summary>View changed files</summary> 📝 `.github/workflows/integration-test.yml` (+24 -2) ➕ `backend/alembic.ini` (+114 -0) 📝 `backend/apps/webui/internal/db.py` (+32 -26) ➖ `backend/apps/webui/internal/migrations/001_initial_schema.py` (+0 -254) ➖ `backend/apps/webui/internal/migrations/002_add_local_sharing.py` (+0 -48) ➖ `backend/apps/webui/internal/migrations/003_add_auth_api_key.py` (+0 -48) ➖ `backend/apps/webui/internal/migrations/004_add_archived.py` (+0 -46) ➖ `backend/apps/webui/internal/migrations/005_add_updated_at.py` (+0 -130) ➖ `backend/apps/webui/internal/migrations/006_migrate_timestamps_and_charfields.py` (+0 -130) ➖ `backend/apps/webui/internal/migrations/007_add_user_last_active_at.py` (+0 -79) ➖ `backend/apps/webui/internal/migrations/008_add_memory.py` (+0 -53) ➖ `backend/apps/webui/internal/migrations/009_add_models.py` (+0 -61) ➖ `backend/apps/webui/internal/migrations/010_migrate_modelfiles_to_models.py` (+0 -130) ➖ `backend/apps/webui/internal/migrations/011_add_user_settings.py` (+0 -48) ➖ `backend/apps/webui/internal/migrations/012_add_tools.py` (+0 -61) ➖ `backend/apps/webui/internal/migrations/013_add_user_info.py` (+0 -48) ➖ `backend/apps/webui/internal/migrations/014_add_files.py` (+0 -55) ➖ `backend/apps/webui/internal/migrations/015_add_functions.py` (+0 -61) ➖ `backend/apps/webui/internal/migrations/016_add_valves_and_is_active.py` (+0 -50) ➖ `backend/apps/webui/internal/migrations/017_add_user_oauth_sub.py` (+0 -49) _...and 40 more files_ </details> ### 📄 Description # Pull Request Checklist ### Note to first-time contributors: Please open a discussion post in [Discussions](https://github.com/open-webui/open-webui/discussions) and describe your changes before submitting a pull request. **Before submitting, make sure you've checked the following:** - [x] **Target branch:** Please verify that the pull request targets the `dev` branch. - [x] **Description:** Provide a concise description of the changes made in this pull request. - [x] **Changelog:** Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description. - [ ] **Documentation:** Have you updated relevant documentation [Open WebUI Docs](https://github.com/open-webui/docs), or other documentation sources? - [ ] **Dependencies:** Are there any new dependencies? Have you updated the dependency versions in the documentation? - [x] **Testing:** Have you written and run sufficient tests for validating the changes? - [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] **Prefix:** To cleary 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 # Changelog Entry ### Description Replacing peewee with SQLAlchemy. The combination of FastAPI with Peewee is not supported and we should avoid using both libraries in parallel. The change replaces the whole ORM model with SQLAlchemy and uses Alembic for schema migrations. The initial database migration script is checking the database schema for table existence and skips table creation in case the table already exists. ### Changed - Replace Peewee with SQLAlchemy - Replace peewee-migrate with alembic ### Breaking Change - The fact that there might be columns added between installed versions is making the replacement of the migration a breaking change. --- ### Additional Information - Related to issue #3228 --- <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 2025-11-11 17:42:46 -06: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#8017