[PR #32269] fix: make e-1.12.1 enterprise migrations database-agnostic for MySQL/TiDB #33642

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

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

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

Fixes #32196

This PR backports a MySQL/TiDB compatibility fix to release/e-1.12.1 for enterprise migrations that currently rely on PostgreSQL-only defaults.

Root cause

Two migrations define PostgreSQL-specific defaults that fail on MySQL/TiDB:

  • uuid_generate_v4() as server_default for id columns
  • ::character varying casts in string defaults

This causes migration failures during flask db upgrade on MySQL/TiDB.

What changed

1) Migration updates

  • api/migrations/versions/2025_12_25_1039-7df29de0f6be_add_credit_pool.py

    • Removed server_default=sa.text('uuid_generate_v4()') from tenant_credit_pools.id
    • Removed unused PostgreSQL dialect import
  • api/migrations/versions/2026_01_17_1110-f9f6d18a37f9_add_table_explore_banner_and_trial.py

    • Removed server_default=sa.text('uuid_generate_v4()') from:
      • account_trial_app_records.id
      • exporle_banners.id
      • trial_apps.id
    • Replaced PostgreSQL cast defaults:
      • 'enabled'::character varying -> 'enabled'
      • 'en-US'::character varying -> 'en-US'
    • Removed unused PostgreSQL dialect import

2) Model updates (keep ORM behavior consistent)

  • api/models/model.py
    • Updated ID generation for:
      • TrialApp
      • AccountTrialAppRecord
      • ExporleBanner
      • TenantCreditPool
    • Replaced DB-level server_default=sa.text("uuid_generate_v4()") with application-level UUID generation:
      • default=lambda: str(uuid4())
    • Updated ExporleBanner defaults to plain strings (no PostgreSQL cast text)

Why this approach

  • Keeps migration scripts database-agnostic (no dialect branch duplication).
  • Preserves existing UUID format consistency (UUIDv4) for historical data.
  • Ensures inserts still work after removing DB-level UUID defaults by generating IDs in application code.

Affected tables

  • tenant_credit_pools
  • account_trial_app_records
  • exporle_banners
  • trial_apps

Screenshots

N/A — backend migration/model fix only.

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 make lint and make type-check (backend) and cd web && npx lint-staged (frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/32269 **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 Fixes #32196 This PR backports a MySQL/TiDB compatibility fix to `release/e-1.12.1` for enterprise migrations that currently rely on PostgreSQL-only defaults. ### Root cause Two migrations define PostgreSQL-specific defaults that fail on MySQL/TiDB: - `uuid_generate_v4()` as `server_default` for `id` columns - `::character varying` casts in string defaults This causes migration failures during `flask db upgrade` on MySQL/TiDB. ### What changed #### 1) Migration updates - `api/migrations/versions/2025_12_25_1039-7df29de0f6be_add_credit_pool.py` - Removed `server_default=sa.text('uuid_generate_v4()')` from `tenant_credit_pools.id` - Removed unused PostgreSQL dialect import - `api/migrations/versions/2026_01_17_1110-f9f6d18a37f9_add_table_explore_banner_and_trial.py` - Removed `server_default=sa.text('uuid_generate_v4()')` from: - `account_trial_app_records.id` - `exporle_banners.id` - `trial_apps.id` - Replaced PostgreSQL cast defaults: - `'enabled'::character varying` -> `'enabled'` - `'en-US'::character varying` -> `'en-US'` - Removed unused PostgreSQL dialect import #### 2) Model updates (keep ORM behavior consistent) - `api/models/model.py` - Updated ID generation for: - `TrialApp` - `AccountTrialAppRecord` - `ExporleBanner` - `TenantCreditPool` - Replaced DB-level `server_default=sa.text("uuid_generate_v4()")` with application-level UUID generation: - `default=lambda: str(uuid4())` - Updated `ExporleBanner` defaults to plain strings (no PostgreSQL cast text) ### Why this approach - Keeps migration scripts database-agnostic (no dialect branch duplication). - Preserves existing UUID format consistency (UUIDv4) for historical data. - Ensures inserts still work after removing DB-level UUID defaults by generating IDs in application code. ### Affected tables - `tenant_credit_pools` - `account_trial_app_records` - `exporle_banners` - `trial_apps` ## Screenshots N/A — backend migration/model fix only. ## Checklist - [ ] 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 `make lint` and `make type-check` (backend) and `cd web && npx lint-staged` (frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:53:39 -05:00
yindo closed this issue 2026-02-21 20:53:39 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#33642