fix: sequential migrations#3
Conversation
|
Warning Review limit reached
Next review available in: 45 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughMigration execution in vectorctl-migration was refactored from concurrent/batched processing (try_join_all with single insert_many/delete_many) to sequential per-migration processing, with the ledger updated immediately after each migration succeeds. New unit tests validate ordering and partial persistence on failure. ChangesSequential Migration Ledger Updates
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant apply_up
participant Migration
participant Ledger
Caller->>apply_up: run migrations in order
loop each migration
apply_up->>Migration: up()
Migration-->>apply_up: success or error
alt success
apply_up->>Ledger: insert ledger record
else error
apply_up-->>Caller: stop, return error
end
end
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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: 1
🧹 Nitpick comments (1)
vectorctl-migration/src/migrator.rs (1)
366-450: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert migration execution order directly.
These tests currently observe ledger writes, not
up/downinvocation order. Add a shared call log toMockMigrationand assert the exact calls, including that migrations after the failure are never invoked.Also applies to: 453-475
🤖 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 `@vectorctl-migration/src/migrator.rs` around lines 366 - 450, These tests are only checking ledger state, not the actual `up`/`down` invocation order. Add a shared call log to `MockMigration` (or a similar test-local tracker) and record each `MigrationTrait::up`/`down` call in order, then update `apply_up_records_sequentially_in_order` and `apply_up_stops_and_persists_prefix_on_failure` to assert the exact call sequence and that migrations after the failing one are never invoked. Keep the changes localized around `MockMigration`, `apply_up`, and the existing test helpers like `test_ctx`.
🤖 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 `@vectorctl-migration/src/migrator.rs`:
- Around line 262-269: Move the success print in the rollback path of the
migrator so it happens only after `ledger.delete_many` completes successfully,
and apply the same ordering to the corresponding apply path that uses
`insert_many`. In `migrator.rs`, keep the message construction in the
rollback/apply logic but defer the `println!` of “Rolled back”/“Applied” until
after the durable ledger write succeeds, so failures in `delete_many` or
`insert_many` do not emit a success status prematurely.
---
Nitpick comments:
In `@vectorctl-migration/src/migrator.rs`:
- Around line 366-450: These tests are only checking ledger state, not the
actual `up`/`down` invocation order. Add a shared call log to `MockMigration`
(or a similar test-local tracker) and record each `MigrationTrait::up`/`down`
call in order, then update `apply_up_records_sequentially_in_order` and
`apply_up_stops_and_persists_prefix_on_failure` to assert the exact call
sequence and that migrations after the failing one are never invoked. Keep the
changes localized around `MockMigration`, `apply_up`, and the existing test
helpers like `test_ctx`.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: d75debd1-3574-4a9c-b75a-c63e935297fa
📒 Files selected for processing (1)
vectorctl-migration/src/migrator.rs
ba7f790 to
3169072
Compare
|
@jpopesculian I'll review it when I get home from my lunch |
|
no rush! |
Make
run_up/run_downconverge on partial failureProblem
run_upapplied all pending migrations concurrently (futures::future::try_join_all) and wrote the applied-ledger once at the end, only if every migration succeeded. This caused two failure modes:execyields migrations in DAG order (dependencies first), buttry_join_alldrove them concurrently — a migration reading a collection an earlier one creates could see it missing.1..kalready ran server-side but were never recorded (insert_manywas never reached). On the next run they were stillPendingand ran again; any non-idempotent step (e.g. a barecreate_collection) then errored forever. Downstream,aqora-platformrunsMigrator::upon every boot, so a wedged ledger panicked the server on startup.Fix
Apply migrations sequentially in the order
forward_path/backward_pathalready yields, and write each migration to the ledger immediately after it succeeds. A mid-run failure now leaves durable partial progress, so the next run resumes at the failed migration instead of replaying — even for non-idempotent migrations. Reuses the existinginsert_many/delete_many(one-elementVec); no trait or backend changes.run_up/run_downkeep their signatures (soexecis untouched) and delegate to new private, ledger-genericapply_up/apply_downhelpers.run_downgets the symmetric treatment;Direction::Refreshworks unchanged.Tests
Adds a
#[cfg(test)] mod testsinmigrator.rswith a mock ledger + mock migrations injected through the helpers' generic seam (driven byfutures::executor::block_on, no new dependency). Covers: sequential ordered recording, prefix-persisted-and-stop onupfailure, same ondownfailure, and the missing-id error path. The failure-case tests pin the regression — they would fail against the old batched-write code.Summary by CodeRabbit
Bug Fixes
Tests