Repository navigation
Go: add migrate database flag - #16719
Conversation
Signed-off-by: Jin Hai <[email protected]>
📝 WalkthroughWalkthroughA new ChangesOptional Database Migration Flag
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested labels: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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.
Inline comments:
In `@cmd/ragflow_server.go`:
- Around line 85-86: The startup flow for ragflow_server now depends on the
migrateDB flag, but the new --migrate path is not consistently surfaced or used.
Update the argument handling in ragflow_server’s main startup logic and
printHelp so --migrate is documented and available, then make sure every
entrypoint/script that launches bin/ragflow_server passes the flag so InitDB
still performs schema migration during upgrades.
In `@internal/dao/database.go`:
- Around line 163-176: The success log in database initialization is misleading
because it always says the schema was migrated even when the migrateDB branch is
skipped. Update the final status logging in database.go around the database
connection/migration flow so it reflects whether migrateDB was true or false,
using the existing database initialization path and the migrateDB flag to choose
between a migrated-success message and a connected-without-migration message.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4a8bb7fa-af63-4148-ac6d-cbfb0f576582
📒 Files selected for processing (2)
cmd/ragflow_server.gointernal/dao/database.go
| case "--migrate": | ||
| args.migrateDB = true |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify help text lists --migrate and find startup invocations of the server binary
rg -nP -C3 '\-\-migrate|func printHelp' cmd/ragflow_server.go
rg -nP -C2 'ragflow_main|ragflow_server' -g '!**/*.go' -g '*.{sh,yaml,yml,Dockerfile,dockerfile}' .Repository: infiniflow/ragflow
Length of output: 5433
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== cmd/ragflow_server.go around flag parsing, help, and startup =="
sed -n '1,220p' cmd/ragflow_server.go | cat -n | sed -n '1,220p'
echo
echo "== search for migrate handling and any auto-migration calls =="
rg -n "migrateDB|migrate|auto.?migrat|migration" cmd internal docker build.sh .
echo
echo "== startup invocations of bin/ragflow_server / ragflow_server with args =="
rg -n "bin/ragflow_server|ragflow_server" docker build.sh README.md .github . -g '!**/*.go'Repository: infiniflow/ragflow
Length of output: 50377
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== relevant DB init logic =="
sed -n '60,190p' internal/dao/database.go | cat -n
echo
echo "== help text and flag parsing around --migrate =="
sed -n '74,210p' cmd/ragflow_server.go | cat -n
echo
echo "== startup wrappers invoking bin/ragflow_server =="
rg -n -C2 "bin/ragflow_server|ragflow_server --(api|admin|ingestor|syncer)|--migrate" docker build.sh README.md .github .
echo
echo "== any direct uses of InitDB and migrateDB wiring =="
rg -n -C2 "InitDB\\(|migrateDB" cmd internalRepository: infiniflow/ragflow
Length of output: 20733
Add --migrate to every startup path
InitDB now skips schema migration unless this flag is passed, but printHelp doesn’t list it and the current launch scripts still invoke bin/ragflow_server without it. Existing deployments will silently stop migrating on upgrade unless every entrypoint is updated.
🤖 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 `@cmd/ragflow_server.go` around lines 85 - 86, The startup flow for
ragflow_server now depends on the migrateDB flag, but the new --migrate path is
not consistently surfaced or used. Update the argument handling in
ragflow_server’s main startup logic and printHelp so --migrate is documented and
available, then make sure every entrypoint/script that launches
bin/ragflow_server passes the flag so InitDB still performs schema migration
during upgrades.
| if migrateDB { | ||
| common.Info("Migrating database schema...") | ||
| for _, m := range dataModels { | ||
| if err = autoMigrateSafely(DB, m); err != nil { | ||
| return fmt.Errorf("failed to migrate model %T: %w", m, err) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Run manual migrations for complex schema changes | ||
| if err = RunMigrations(DB); err != nil { | ||
| return fmt.Errorf("failed to run manual migrations: %w", err) | ||
| // Run manual migrations for complex schema changes | ||
| if err = RunMigrations(DB); err != nil { | ||
| return fmt.Errorf("failed to run manual migrations: %w", err) | ||
| } | ||
| common.Info("Database schema migrated successfully") | ||
| } |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Misleading success log when migration is skipped.
With migration now gated behind if migrateDB, the unconditional log at Line 184 ("Database connected and migrated successfully") still claims a migration happened even when --migrate was not passed. This can mislead operators debugging whether the schema was actually migrated. Consider reflecting the skip.
💡 Suggested wording fix (Line 184)
- common.Info("Database connected and migrated successfully")
+ if migrateDB {
+ common.Info("Database connected and migrated successfully")
+ } else {
+ common.Info("Database connected (schema migration skipped; pass --migrate to run migrations)")
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if migrateDB { | |
| common.Info("Migrating database schema...") | |
| for _, m := range dataModels { | |
| if err = autoMigrateSafely(DB, m); err != nil { | |
| return fmt.Errorf("failed to migrate model %T: %w", m, err) | |
| } | |
| } | |
| } | |
| // Run manual migrations for complex schema changes | |
| if err = RunMigrations(DB); err != nil { | |
| return fmt.Errorf("failed to run manual migrations: %w", err) | |
| // Run manual migrations for complex schema changes | |
| if err = RunMigrations(DB); err != nil { | |
| return fmt.Errorf("failed to run manual migrations: %w", err) | |
| } | |
| common.Info("Database schema migrated successfully") | |
| } | |
| if migrateDB { | |
| common.Info("Database connected and migrated successfully") | |
| } else { | |
| common.Info("Database connected (schema migration skipped; pass --migrate to run migrations)") | |
| } |
🤖 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 `@internal/dao/database.go` around lines 163 - 176, The success log in database
initialization is misleading because it always says the schema was migrated even
when the migrateDB branch is skipped. Update the final status logging in
database.go around the database connection/migration flow so it reflects whether
migrateDB was true or false, using the existing database initialization path and
the migrateDB flag to choose between a migrated-success message and a
connected-without-migration message.
Summary
--migrate will trigger database migration