Skip to content

Fix: migrate legacy model id configs - #15495

Merged
wangq8 merged 1 commit into
infiniflow:mainfrom
buua436:b057
Jun 2, 2026
Merged

wangq8 merged 1 commit into
infiniflow:mainfrom
buua436:b057

Conversation

@buua436

@buua436 buua436 commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

migrate legacy model id configs

Type of change

  • Bug Fix (non-breaking change which fixes an issue)

@coderabbitai

coderabbitai Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds a new MySQL migration stage that normalizes legacy model identifiers from model@provider format to model@default@provider across multiple database columns, integrated into the Docker startup sequence. The implementation includes database column validation, recursive JSON normalization, and dual-mode (dry-run and execute) database updates.

Changes

Model ID Config Migration

Layer / File(s) Summary
Database infrastructure for migration
tools/scripts/mysql_migration.py
Adds json import and MigrationDatabase.column_exists helper method to safely check for column existence before scanning and updating tables.
Model ID normalization logic
tools/scripts/mysql_migration.py
ModelIdConfigStage implements detection and normalization of legacy model IDs across string and JSON columns, with recursive JSON walking, parameterized updates, and dry-run sample logging.
Stage registration and CLI documentation
tools/scripts/mysql_migration.py
Registers ModelIdConfigStage in MIGRATION_STAGES dictionary and adds CLI usage example for running the new model_id_config migration stage.
Startup initialization integration
docker/entrypoint.sh
Adds invocation of model_id_config migration stage to Docker entrypoint during model provider table initialization, after existing tenant model migrations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • infiniflow/ragflow#13976: Both PRs modify tools/scripts/mysql_migration.py's stage system—Feat: migrate script #13976 adds the tenant_model_instance/tenant_model migration stages (and registers them in MIGRATION_STAGES), while this PR extends that framework with a new model_id_config stage and wires it into the startup migration sequence after the tenant_model_instance/tenant_model stages.

Suggested labels

size:XL

Poem

🐰 hops excitedly
Legacy IDs now normalized bright,
From model@provider to the proper sight,
model@default@provider takes its place,
The database migration runs at startup's pace! ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.69% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description is incomplete. While it mentions the problem being solved, it provides only a one-line explanation without sufficient detail about what legacy configs are being migrated or why this migration is necessary. Expand the description to explain what 'legacy model id configs' means, the format change from 'model@provider' to 'model@default@provider', and the impact of this migration on the system.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix: migrate legacy model id configs' accurately summarizes the main change: adding a migration stage to normalize legacy model identifier formats.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@buua436
buua436 requested a review from Lynn-Inf June 2, 2026 03:36
@buua436 buua436 added the ci Continue Integration label Jun 2, 2026
@buua436
buua436 marked this pull request as ready for review June 2, 2026 03:36
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Jun 2, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
docker/entrypoint.sh (1)

275-280: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Don't hide a cross-table config rewrite behind --init-model-provider-tables.

Line 280 makes this flag mutate tenant, document, search, user_canvas*, pipeline_operation_log, and other non-provider tables as well. That changes the operational contract of the flag and can surprise operators who only intended the tenant_model_* backfill. I'd gate model_id_config behind its own explicit init path, or rename/update the entrypoint contract in the same change.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docker/entrypoint.sh` around lines 275 - 280, The current
INIT_MODEL_PROVIDER_TABLES branch runs migrations for tenant_model_provider,
tenant_model_instance, tenant_model, and also model_id_config which mutates
non-provider tables; change the entrypoint logic so model_id_config is not
hidden behind INIT_MODEL_PROVIDER_TABLES: add a new explicit env flag (e.g.,
INIT_MODEL_ID_CONFIG_TABLES) or rename the existing flag to reflect the broader
behavior, and gate the "$PY tools/scripts/mysql_migration.py --stages
model_id_config --config conf/service_conf.yaml --execute" call behind that new
flag (or adjust naming/contract) while leaving tenant_model_* migrations under
INIT_MODEL_PROVIDER_TABLES; update any related docs/comments to match the new
flag name.
🧹 Nitpick comments (1)
tools/scripts/mysql_migration.py (1)

912-975: 🏗️ Heavy lift

Avoid the second full-table pass before updates.

check() walks every configured table via count_changes(), and execute() immediately repeats the same scans/parsing again. With large tables like pipeline_operation_log and evaluation_runs, that doubles the I/O and JSON work for this init path. Cache the pending updates from check() or let execute() stream the migration in a single pass.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tools/scripts/mysql_migration.py` around lines 912 - 975, The check() method
currently calls count_changes() and forces a full scan, and execute() then
re-scans via iter_string_changes() and iter_json_changes(), doubling I/O; modify
check() to cache the pending change rows (e.g., store a list on self like
self._pending_changes containing tuples for both string and json updates
returned by count_changes() or by a new helper that yields rows), have
count_changes() either return those lists or produce them via a single iterator,
and update execute() to consume self._pending_changes (respecting
create_table_only and dry_run and using db.execute_sql as before) instead of
re-iterating tables; ensure names referenced: check(), execute(),
count_changes(), iter_string_changes(), iter_json_changes(),
self._pending_changes, create_table_only, dry_run, and db.execute_sql.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@docker/entrypoint.sh`:
- Around line 275-280: The current INIT_MODEL_PROVIDER_TABLES branch runs
migrations for tenant_model_provider, tenant_model_instance, tenant_model, and
also model_id_config which mutates non-provider tables; change the entrypoint
logic so model_id_config is not hidden behind INIT_MODEL_PROVIDER_TABLES: add a
new explicit env flag (e.g., INIT_MODEL_ID_CONFIG_TABLES) or rename the existing
flag to reflect the broader behavior, and gate the "$PY
tools/scripts/mysql_migration.py --stages model_id_config --config
conf/service_conf.yaml --execute" call behind that new flag (or adjust
naming/contract) while leaving tenant_model_* migrations under
INIT_MODEL_PROVIDER_TABLES; update any related docs/comments to match the new
flag name.

---

Nitpick comments:
In `@tools/scripts/mysql_migration.py`:
- Around line 912-975: The check() method currently calls count_changes() and
forces a full scan, and execute() then re-scans via iter_string_changes() and
iter_json_changes(), doubling I/O; modify check() to cache the pending change
rows (e.g., store a list on self like self._pending_changes containing tuples
for both string and json updates returned by count_changes() or by a new helper
that yields rows), have count_changes() either return those lists or produce
them via a single iterator, and update execute() to consume
self._pending_changes (respecting create_table_only and dry_run and using
db.execute_sql as before) instead of re-iterating tables; ensure names
referenced: check(), execute(), count_changes(), iter_string_changes(),
iter_json_changes(), self._pending_changes, create_table_only, dry_run, and
db.execute_sql.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 03dd9fa1-9cd0-43e0-ae9e-d24c6f76d5b8

📥 Commits

Reviewing files that changed from the base of the PR and between 0f6f7b3 and 50e6eac.

📒 Files selected for processing (2)
  • docker/entrypoint.sh
  • tools/scripts/mysql_migration.py

@codecov

codecov Bot commented Jun 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (0f6f7b3) to head (50e6eac).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #15495   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wangq8
wangq8 merged commit 2e02bf7 into infiniflow:main Jun 2, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants