[PR #32226] fix: add MySQL/TiDB compatibility for credit pool and trial app migrations #33615

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

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

State: closed
Merged: No


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

Two migration files use PostgreSQL-specific SQL that breaks flask db upgrade on MySQL / TiDB:

  • 7df29de0f6beuuid_generate_v4() server_default on tenant_credit_pools.id
  • f9f6d18a37f9uuid_generate_v4() on account_trial_app_records.id, exporle_banners.id, trial_apps.id, plus ::character varying type casts on exporle_banners.status and exporle_banners.language

Instead of adding dialect branching, this PR makes both migrations and their corresponding models fully database-agnostic:

Migrations — Remove uuid_generate_v4() server_default from id columns and replace ::character varying casts with plain string defaults. Remove unused from sqlalchemy.dialects import postgresql import.

Models — Replace server_default=text("uuid_generate_v4()") with default=lambda: str(uuidv7()) on the id column of all 4 affected models (TenantCreditPool, TrialApp, AccountTrialAppRecord, ExporleBanner), consistent with the DefaultFieldsMixin pattern. Also replace ::character varying casts in ExporleBanner with plain string defaults.

UUID generation now happens at the application level, which is database-agnostic, reduces database roundtrips, and aligns with the project's direction of using UUIDv7 for primary keys.

Affected tables

Table Model Change
tenant_credit_pools TenantCreditPool id: db hook → app-level UUIDv7
account_trial_app_records AccountTrialAppRecord id: db hook → app-level UUIDv7
exporle_banners ExporleBanner id: db hook → app-level UUIDv7; status/language: remove PG type casts
trial_apps TrialApp id: db hook → app-level UUIDv7

Screenshots

N/A — backend-only migration fix, no UI changes.

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/32226 **State:** closed **Merged:** No --- > [!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 Two migration files use PostgreSQL-specific SQL that breaks `flask db upgrade` on MySQL / TiDB: - `7df29de0f6be` — `uuid_generate_v4()` server_default on `tenant_credit_pools.id` - `f9f6d18a37f9` — `uuid_generate_v4()` on `account_trial_app_records.id`, `exporle_banners.id`, `trial_apps.id`, plus `::character varying` type casts on `exporle_banners.status` and `exporle_banners.language` Instead of adding dialect branching, this PR makes both migrations and their corresponding models fully database-agnostic: **Migrations** — Remove `uuid_generate_v4()` server_default from `id` columns and replace `::character varying` casts with plain string defaults. Remove unused `from sqlalchemy.dialects import postgresql` import. **Models** — Replace `server_default=text("uuid_generate_v4()")` with `default=lambda: str(uuidv7())` on the `id` column of all 4 affected models (`TenantCreditPool`, `TrialApp`, `AccountTrialAppRecord`, `ExporleBanner`), consistent with the `DefaultFieldsMixin` pattern. Also replace `::character varying` casts in `ExporleBanner` with plain string defaults. UUID generation now happens at the application level, which is database-agnostic, reduces database roundtrips, and aligns with the project's direction of using UUIDv7 for primary keys. ### Affected tables | Table | Model | Change | |---|---|---| | `tenant_credit_pools` | `TenantCreditPool` | `id`: db hook → app-level UUIDv7 | | `account_trial_app_records` | `AccountTrialAppRecord` | `id`: db hook → app-level UUIDv7 | | `exporle_banners` | `ExporleBanner` | `id`: db hook → app-level UUIDv7; `status`/`language`: remove PG type casts | | `trial_apps` | `TrialApp` | `id`: db hook → app-level UUIDv7 | ## Screenshots N/A — backend-only migration fix, no UI changes. ## 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:36 -05:00
yindo closed this issue 2026-02-21 20:53:36 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#33615