[PR #28188] feat:mysql adaptation for metadb #31980

Closed
opened 2026-02-21 20:50:31 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/28188

State: closed
Merged: Yes


Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

This pull request introduces multi-database support (PostgreSQL, MySQL, and OceanBase), improves database configuration flexibility, and refactors several SQL query implementations for better compatibility and maintainability. It also updates environment and workflow files to support these changes, and refactors metadata filtering logic for datasets.

Database support and configuration:

  • Added support for selecting the database type (DB_TYPE) in DatabaseConfig and .env.example, enabling PostgreSQL, MySQL, and OceanBase as backend options. The SQLAlchemy URI scheme and engine options now adjust dynamically based on the selected database type. [1] [2] [3] [4]
  • Updated documentation and example environment files to clarify database configuration and added/removal of OceanBase vector settings. [1] [2] [3]

CI/CD and workflow changes:

  • Modified GitHub Actions workflows to distinguish between PostgreSQL and MySQL services, and added a dedicated MySQL migration test job. [1] [2] [3] [4]

SQL query refactoring for compatibility:

  • Refactored SQL queries in api/controllers/console/app/statistic.py to use a new helper function convert_datetime_to_date, replacing Postgres-specific date/time functions with a more portable approach for multi-database support. [1] [2] [3] [4] [5] [6] [7] [8]

Dataset metadata filtering improvements:

  • Simplified and standardized metadata filter construction in api/core/rag/retrieval/dataset_retrieval.py, replacing raw SQL fragments and casting with SQLAlchemy JSON field methods for better type safety and compatibility. [1] [2]

Minor codebase updates:

Screenshots

Before After
pg pg,mysql and mysql compatible db

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/28188 **State:** closed **Merged:** Yes --- > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 1. Ensure there is an associated issue and you have been assigned to it > 1. Use the correct syntax to link this PR: `Fixes #<issue number>`. ## Summary This pull request introduces multi-database support (PostgreSQL, MySQL, and OceanBase), improves database configuration flexibility, and refactors several SQL query implementations for better compatibility and maintainability. It also updates environment and workflow files to support these changes, and refactors metadata filtering logic for datasets. **Database support and configuration:** * Added support for selecting the database type (`DB_TYPE`) in `DatabaseConfig` and `.env.example`, enabling PostgreSQL, MySQL, and OceanBase as backend options. The SQLAlchemy URI scheme and engine options now adjust dynamically based on the selected database type. [[1]](diffhunk://#diff-0aeb1a877a7ce604c8cca16fff2336c5d8297b313ac42832af471f210592fc5bR108-R113) [[2]](diffhunk://#diff-0aeb1a877a7ce604c8cca16fff2336c5d8297b313ac42832af471f210592fc5bL143-R152) [[3]](diffhunk://#diff-0aeb1a877a7ce604c8cca16fff2336c5d8297b313ac42832af471f210592fc5bL207-L214) [[4]](diffhunk://#diff-2fdd31c8eaeb05db626d15ffa6f31b34be3044212e22d6831e976afbab90cc86L75-R83) * Updated documentation and example environment files to clarify database configuration and added/removal of OceanBase vector settings. [[1]](diffhunk://#diff-c7b1c23e00a1fd0378f6ea41a7dfe1c9e043d766f738dba26860c783b82e8c6aL18-R19) [[2]](diffhunk://#diff-2fdd31c8eaeb05db626d15ffa6f31b34be3044212e22d6831e976afbab90cc86R180-R190) [[3]](diffhunk://#diff-2fdd31c8eaeb05db626d15ffa6f31b34be3044212e22d6831e976afbab90cc86L342-L350) **CI/CD and workflow changes:** * Modified GitHub Actions workflows to distinguish between PostgreSQL and MySQL services, and added a dedicated MySQL migration test job. [[1]](diffhunk://#diff-255c167193ef734f4f0c2dd66841dd24884a70ad9be5d0c37bb706dd8351ae0aL11-R11) [[2]](diffhunk://#diff-255c167193ef734f4f0c2dd66841dd24884a70ad9be5d0c37bb706dd8351ae0aL48-R48) [[3]](diffhunk://#diff-255c167193ef734f4f0c2dd66841dd24884a70ad9be5d0c37bb706dd8351ae0aR60-R116) [[4]](diffhunk://#diff-8c3f82f0b002430c7b079361d8dbc0662a32467f16bc9d20b5796745488abdf8L65-R65) **SQL query refactoring for compatibility:** * Refactored SQL queries in `api/controllers/console/app/statistic.py` to use a new helper function `convert_datetime_to_date`, replacing Postgres-specific date/time functions with a more portable approach for multi-database support. [[1]](diffhunk://#diff-0247e713e9840d8fe033587ded2b71440168600d3f1d9b9ae7e9589da06296f5L47-R49) [[2]](diffhunk://#diff-0247e713e9840d8fe033587ded2b71440168600d3f1d9b9ae7e9589da06296f5R110-R142) [[3]](diffhunk://#diff-0247e713e9840d8fe033587ded2b71440168600d3f1d9b9ae7e9589da06296f5L164-R169) [[4]](diffhunk://#diff-0247e713e9840d8fe033587ded2b71440168600d3f1d9b9ae7e9589da06296f5L220-R226) [[5]](diffhunk://#diff-0247e713e9840d8fe033587ded2b71440168600d3f1d9b9ae7e9589da06296f5L279-R286) [[6]](diffhunk://#diff-0247e713e9840d8fe033587ded2b71440168600d3f1d9b9ae7e9589da06296f5L354-R362) [[7]](diffhunk://#diff-0247e713e9840d8fe033587ded2b71440168600d3f1d9b9ae7e9589da06296f5L419-R428) [[8]](diffhunk://#diff-0247e713e9840d8fe033587ded2b71440168600d3f1d9b9ae7e9589da06296f5L474-R484) **Dataset metadata filtering improvements:** * Simplified and standardized metadata filter construction in `api/core/rag/retrieval/dataset_retrieval.py`, replacing raw SQL fragments and casting with SQLAlchemy JSON field methods for better type safety and compatibility. [[1]](diffhunk://#diff-7f86aebf4552189e1397e4091112ae9a5325340de0d7c4d4b172ca99b7309690L10-R10) [[2]](diffhunk://#diff-7f86aebf4552189e1397e4091112ae9a5325340de0d7c4d4b172ca99b7309690L1026-R1073) **Minor codebase updates:** * Added missing import for `dify_config` in `api/core/tools/tool_manager.py`. All in all,this job can be divided into three parts:schema,migration versions and a little sql. Discussion in https://github.com/langgenius/dify/discussions/26878. Fix #https://github.com/langgenius/dify/issues/26422. close https://github.com/langgenius/dify/pull/27983 ## Screenshots | Before | After | |--------|-------| | pg | pg,mysql and mysql compatible db | ## Checklist - [x] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:50:31 -05:00
yindo closed this issue 2026-02-21 20:50:31 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#31980