Repository navigation
feat: add Peewee ORM support for OceanBase as primary database (#12769) - #12926
Merged
yuzhichang merged 1 commit intoJan 31, 2026
Merged
Conversation
- Add RetryingPooledOceanBaseDatabase class (inherits from PooledMySQLDatabase) - OceanBase is MySQL compatible, so we use MySQL protocol - Add OCEANBASE to PooledDatabase enum - Add OCEANBASE to DatabaseLock enum (uses MysqlDatabaseLock) - Add OCEANBASE to TextFieldType enum (uses LONGTEXT) - Add comprehensive unit tests - Enable via DB_TYPE=oceanbase environment variable Related to oceanbase/seekdb#123 Closes infiniflow#12769
Contributor
|
Hi @NTLx quick question here, since we already have the dedicated test folder structure, so curious why we create a separate tests/unit folder again in this pr? cc: @yuzhichang |
1 task done
KevinHuSh
pushed a commit
that referenced
this pull request
Feb 2, 2026
### What problem does this PR solve? Fixed the regression issue that unable to start the server as below details, which was related to this pr #12926 looks like. ``` Error Trace Traceback (most recent call last): File "/mnt/c/Workspace/ragflow/api/ragflow_server.py", line 33, in <module> from api.apps import app File "/mnt/c/Workspace/ragflow/api/apps/__init__.py", line 26, in <module> Traceback (most recent call last): File "/mnt/c/Workspace/ragflow/rag/svr/task_executor.py", line 34, in <module> from api.db.db_models import close_connection, APIToken File "/mnt/c/Workspace/ragflow/api/db/db_models.py", line 49, in <module> from api.db.services.knowledgebase_service import KnowledgebaseService File "/mnt/c/Workspace/ragflow/api/db/services/__init__.py", line 19, in <module> class TextFieldType(Enum): File "/mnt/c/Workspace/ragflow/api/db/db_models.py", line 53, in TextFieldType from .user_service import UserService as UserService File "/mnt/c/Workspace/ragflow/api/db/services/user_service.py", line 24, in <module> POSTGRES = "TEXT" ^^^^^^^^ File "/usr/lib/python3.12/enum.py", line 443, in __setitem__ raise TypeError('%r already defined as %r' % (key, self[key])) TypeError: 'POSTGRES' already defined as 'TEXT' from api.db.db_models import DB, UserTenant File "/mnt/c/Workspace/ragflow/api/db/db_models.py", line 49, in <module> class TextFieldType(Enum): File "/mnt/c/Workspace/ragflow/api/db/db_models.py", line 53, in TextFieldType POSTGRES = "TEXT" ^^^^^^^^ File "/usr/lib/python3.12/enum.py", line 443, in __setitem__ raise TypeError('%r already defined as %r' % (key, self[key])) TypeError: 'POSTGRES' already defined as 'TEXT' ``` ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
1 task done
KevinHuSh
pushed a commit
that referenced
this pull request
Feb 3, 2026
…ck (#12969) ### What problem does this PR solve? This mistake was made by PR #12926 This PR makes the OceanBase peewee unit test discoverable by the default unit test runner/CI (by moving it under test/), so it’s included in the unified unit test suite. It also fixes `test_database_lock_enum_values` to correctly handle Enum alias members (DatabaseLock uses the same value for MYSQL and OCEANBASE). ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) - [ ] New Feature (non-breaking change which adds functionality) - [ ] Documentation Update - [ ] Refactoring - [ ] Performance Improvement - [ ] Other (please describe): ### Screenshots The original `test_oceanbase_peewee.py` was placed under tests/, which isn’t included in the default unit test runner’s testpaths, so it wasn’t picked up by the unit test suite. So we need to move it to correct path. <img width="670" height="540" alt="image" src="https://github.com/user-attachments/assets/69d39346-450f-46dc-8965-29c3d7b32bc9" /> When using old version in `test_oceanbase_peewee.py`: ``` def test_database_lock_enum_values(self): """Test DatabaseLock enum has all expected values.""" expected = {'MYSQL', 'OCEANBASE', 'POSTGRES'} actual = {e.name for e in DatabaseLock} assert expected.issubset(actual), f"Missing: {expected - actual}" ``` The old check iterated Enum members, so alias values were skipped and only `MYSQL/POSTGRES` were seen, making OCEANBASE appear missing. <img width="1998" height="931" alt="65e2837f23b7b298980a410c7d5c2f09" src="https://github.com/user-attachments/assets/d8e98c5a-2cfa-4182-ae35-a3ef03554a27" /> and new version uses `DatabaseLock.__members__` and passes: <img width="2024" height="1170" alt="1aa8c6facb28d24149270fe1bc4a9dd9" src="https://github.com/user-attachments/assets/d8688936-ccac-4a39-a389-23dc6f0fe276" />
4 tasks
tmimmanuel
pushed a commit
to tmimmanuel/ragflow
that referenced
this pull request
May 14, 2026
…2933) ### What problem does this PR solve? Fixed the regression issue that unable to start the server as below details, which was related to this pr infiniflow#12926 looks like. ``` Error Trace Traceback (most recent call last): File "/mnt/c/Workspace/ragflow/api/ragflow_server.py", line 33, in <module> from api.apps import app File "/mnt/c/Workspace/ragflow/api/apps/__init__.py", line 26, in <module> Traceback (most recent call last): File "/mnt/c/Workspace/ragflow/rag/svr/task_executor.py", line 34, in <module> from api.db.db_models import close_connection, APIToken File "/mnt/c/Workspace/ragflow/api/db/db_models.py", line 49, in <module> from api.db.services.knowledgebase_service import KnowledgebaseService File "/mnt/c/Workspace/ragflow/api/db/services/__init__.py", line 19, in <module> class TextFieldType(Enum): File "/mnt/c/Workspace/ragflow/api/db/db_models.py", line 53, in TextFieldType from .user_service import UserService as UserService File "/mnt/c/Workspace/ragflow/api/db/services/user_service.py", line 24, in <module> POSTGRES = "TEXT" ^^^^^^^^ File "/usr/lib/python3.12/enum.py", line 443, in __setitem__ raise TypeError('%r already defined as %r' % (key, self[key])) TypeError: 'POSTGRES' already defined as 'TEXT' from api.db.db_models import DB, UserTenant File "/mnt/c/Workspace/ragflow/api/db/db_models.py", line 49, in <module> class TextFieldType(Enum): File "/mnt/c/Workspace/ragflow/api/db/db_models.py", line 53, in TextFieldType POSTGRES = "TEXT" ^^^^^^^^ File "/usr/lib/python3.12/enum.py", line 443, in __setitem__ raise TypeError('%r already defined as %r' % (key, self[key])) TypeError: 'POSTGRES' already defined as 'TEXT' ``` ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
geversite
pushed a commit
to geversite/ragflow
that referenced
this pull request
Jul 3, 2026
### What problem does this PR solve? Fixed the regression issue that unable to start the server as below details, which was related to this pr infiniflow/ragflow#12926 looks like. ``` Error Trace Traceback (most recent call last): File "/mnt/c/Workspace/ragflow/api/ragflow_server.py", line 33, in <module> from api.apps import app File "/mnt/c/Workspace/ragflow/api/apps/__init__.py", line 26, in <module> Traceback (most recent call last): File "/mnt/c/Workspace/ragflow/rag/svr/task_executor.py", line 34, in <module> from api.db.db_models import close_connection, APIToken File "/mnt/c/Workspace/ragflow/api/db/db_models.py", line 49, in <module> from api.db.services.knowledgebase_service import KnowledgebaseService File "/mnt/c/Workspace/ragflow/api/db/services/__init__.py", line 19, in <module> class TextFieldType(Enum): File "/mnt/c/Workspace/ragflow/api/db/db_models.py", line 53, in TextFieldType from .user_service import UserService as UserService File "/mnt/c/Workspace/ragflow/api/db/services/user_service.py", line 24, in <module> POSTGRES = "TEXT" ^^^^^^^^ File "/usr/lib/python3.12/enum.py", line 443, in __setitem__ raise TypeError('%r already defined as %r' % (key, self[key])) TypeError: 'POSTGRES' already defined as 'TEXT' from api.db.db_models import DB, UserTenant File "/mnt/c/Workspace/ragflow/api/db/db_models.py", line 49, in <module> class TextFieldType(Enum): File "/mnt/c/Workspace/ragflow/api/db/db_models.py", line 53, in TextFieldType POSTGRES = "TEXT" ^^^^^^^^ File "/usr/lib/python3.12/enum.py", line 443, in __setitem__ raise TypeError('%r already defined as %r' % (key, self[key])) TypeError: 'POSTGRES' already defined as 'TEXT' ``` ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
This PR adds Peewee ORM support for OceanBase as the primary database in RAGFlow, as requested in issue #12769.
Changes
Core Implementation
RetryingPooledOceanBaseDatabase Class
PooledMySQLDatabase(OceanBase is MySQL-compatible)PooledDatabase Enum
OCEANBASE = RetryingPooledOceanBaseDatabaseDatabaseLock Enum
OCEANBASE = MysqlDatabaseLockTextFieldType Enum
OCEANBASE = "LONGTEXT"DatabaseMigrator Enum
OCEANBASE = MySQLMigratorUsage
Technical Details
api/db/db_models.pyTesting
tests/unit/test_oceanbase_peewee.pyAcceptance Criteria
✅ Can switch to OceanBase database via
DB_TYPE=oceanbaseenvironment variable✅ All database operations work normally in OceanBase environment
✅ OceanBase uses MySQL compatibility mode (no additional dependencies)
Background
This is part of the RAGFlow + OceanBase Hackathon to allow users to choose OceanBase as RAGFlow's primary database, leveraging OceanBase's high availability and scalability.
Related Issues
Closes #12769