Skip to content

feat: Unified Migration System Design#1323

Open
quake wants to merge 20 commits intonervosnetwork:developfrom
quake:quake/rebase-on-develop
Open

feat: Unified Migration System Design#1323
quake wants to merge 20 commits intonervosnetwork:developfrom
quake:quake/rebase-on-develop

Conversation

@quake
Copy link
Copy Markdown
Member

@quake quake commented May 5, 2026

Impl of #1256

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements a unified, callback-driven database migration flow in crates/fiber-store (usable across node/CLI and WASM), and archives the legacy standalone fnn-migrate tool for pre-INIT_DB_VERSION upgrades.

Changes:

  • Refactors fiber-store migrations to run via auto_migrate() with confirm/progress callbacks, and wires this into native (fiber-bin) and WASM (fiber-wasm) startup.
  • Archives the old migrate/ tool as migrate_archive/ and removes it from the Makefile check target.
  • Updates migration-related tests and sample fixture version strings to align with the new migration epoch/versioning.

Reviewed changes

Copilot reviewed 21 out of 52 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
migrate_archive/src/util.rs Legacy helper utilities for archived migrator (bincode convert + prompt).
migrate_archive/src/tests/sample_tests.rs Archived tool tests for v0.7.0 sample round-trips and determinism.
migrate_archive/src/tests/mod.rs Archived tool test module wiring.
migrate_archive/src/tests/migration_tests.rs Archived tool tests validating v0.6.1→v0.7.0 migration behavior.
migrate_archive/src/migrations/sample.rs Archived placeholder migration object example.
migrate_archive/src/migrations/mod.rs Archived migration module registry list.
migrate_archive/src/migrations/mig_20260302_channel_replay_fields.rs Archived migration appending new replay-related trailing fields.
migrate_archive/src/migrations/mig_20260302_channel_open_record.rs Archived migration deleting ephemeral ChannelOpenRecord entries.
migrate_archive/src/migrations/mig_20260301_network_state_pubkey.rs Archived migration clearing legacy network actor state entries.
migrate_archive/src/migrations/mig_20260204_pubkey_channel_index.rs Archived migration rebuilding pubkey-based channel index.
migrate_archive/src/migrations/mig_20260203_trampoline.rs Archived migration for trampoline-related schema changes (channel/payment/attempt).
migrate_archive/src/migrations/mig_20260203_channel_index.rs Archived migration building channel→attempt index for non-final payments.
migrate_archive/src/migrations/mig_20251219.rs Archived migration v0.6.0→v0.6.1 channel state conversion.
migrate_archive/src/migrations/mig_20250724.rs Archived “breaking change” migration marker.
migrate_archive/src/migrations_backup/mig_20250617.rs Archived backup migration (historical reference).
migrate_archive/src/migrations_backup/mig_20250507.rs Archived backup invoice migration (historical reference).
migrate_archive/src/migrations_backup/mig_20250428.rs Archived backup channel/payment migrations (historical reference).
migrate_archive/src/migrations_backup/mig_20250407.rs Archived backup broadcast-message cleanup migration (historical reference).
migrate_archive/src/migrations_backup/mig_20250318.rs Archived backup v0.4.0→v0.4.1 channel migration (historical reference).
migrate_archive/src/migrations_backup/mig_20250308.rs Archived backup timestamp key consolidation migration (historical reference).
migrate_archive/src/migrations_backup/mig_20250307.rs Archived backup payment-session migration (historical reference).
migrate_archive/src/migrations_backup/mig_20250227.rs Archived backup watchtower schema migration (historical reference).
migrate_archive/src/migrations_backup/mig_20250123.rs Archived backup v0.3.1→v0.4.0 channel migration (historical reference).
migrate_archive/src/migrations_backup/mig_20250115.rs Archived backup v0.2.1→v0.3.0 channel migration (historical reference).
migrate_archive/src/migrations_backup/mig_20250114.rs Archived backup v0.2.0→v0.2.1 channel migration (historical reference).
migrate_archive/src/main.rs Archived standalone migrator binary entrypoint.
migrate_archive/src/lib.rs Archived migrator crate module exports.
migrate_archive/README.md Documents that migrate_archive/ is reference-only and how to upgrade old DBs.
migrate_archive/Cargo.toml Archived migrator crate manifest (not in workspace).
migrate_archive/build.rs Archived build script generating migration registration code.
Makefile Removes cd migrate && cargo check from the check target.
docs/plans/2026-04-09-unified-migration-system.md Implementation plan for the unified migration system.
crates/fiber-wasm/src/lib.rs Uses open_store_with_migration and adds WASM confirm/progress callbacks.
crates/fiber-types/src/sample/mod.rs Updates fixture path examples to v0.8.0.
crates/fiber-types/src/sample/broadcast.rs Updates sample broadcast message version string to 0.8.0.
crates/fiber-store/src/migrations/mod.rs Adds migrations module with build-time registration include.
crates/fiber-store/src/migration.rs Introduces callback-based auto-migration, new errors, and new INIT epoch.
crates/fiber-store/src/lib.rs Exposes the new migrations module.
crates/fiber-store/src/db_migrate.rs Simplifies DbMigrate to delegate to Migrations::auto_migrate().
crates/fiber-store/Cargo.toml Removes indicatif/console dependencies from fiber-store.
crates/fiber-store/build.rs Updates build script to scan src/migrations and generate registration/latest version.
crates/fiber-lib/src/tests/test_utils.rs Updates store opening call sites (formatting/compat with new API).
crates/fiber-lib/src/store/tests/store.rs Updates store opening call sites (formatting/compat with new API).
crates/fiber-lib/src/store/tests/migrate.rs Reworks migration tests for the new auto_migrate flow.
crates/fiber-lib/src/store/store_impl/mod.rs Adds open_store_with_migration and wires unified auto-migrate into store open.
crates/fiber-lib/src/store/mod.rs Re-exports open_store_with_migration and migration plan/progress types.
crates/fiber-lib/src/fiber/tests/gossip.rs Updates store opening call sites (formatting/compat with new API).
crates/fiber-lib/src/build.rs Removes build-time scanning of legacy migrate/ directory.
crates/fiber-lib/Cargo.toml Removes no-longer-needed deps (e.g. indicatif/ouroboros).
crates/fiber-bin/src/main.rs Wires CLI confirm/progress callbacks into store open at startup.
Cargo.lock Updates lockfile to reflect dependency graph changes (plus additional version shifts).

Comment thread crates/fiber-store/src/migration.rs
Comment thread crates/fiber-bin/src/main.rs
Comment thread crates/fiber-lib/src/store/tests/migrate.rs
Comment thread crates/fiber-lib/src/store/store_impl/mod.rs
@quake
Copy link
Copy Markdown
Member Author

quake commented May 5, 2026

@copilot apply changes based on the comments in this thread

quake added a commit to quake/fiber that referenced this pull request May 5, 2026
- Fix stderr flush compile error in fiber-bin cli_confirm
- Remove unused StorageBackend import in migration test
- Include db version and migration guidance in check_validate messages
Copy link
Copy Markdown
Contributor

@Zhangcy0x3 Zhangcy0x3 left a comment

Choose a reason for hiding this comment

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

I've left a couple of technical suggestions regarding WASM error handling and some minor API improvements for BTreeMap. Please take a look when you have time.

Comment thread crates/fiber-store/src/migration.rs
Comment thread crates/fiber-store/src/migration.rs Outdated
Comment thread migrate_archive/src/migrations_backup/mig_20250114.rs
Comment thread crates/fiber-store/src/migration.rs Outdated
quake added 17 commits May 7, 2026 12:21
Detailed plan covering 4 phases (12 tasks) for migrating from the
standalone migrate/ crate to a unified migration system in fiber-store
that works across all backends (RocksDB, SQLite, IndexedDB).
…stem

- Fix fiber-bin/fiber-wasm imports to use fnn::store re-exports instead
  of direct fiber_store::migration (fiber-bin doesn't depend on fiber-store)
- Add MigrationPlan/MigrationProgress re-exports in fiber-lib/src/store/mod.rs
- Remove obsolete migration scanning code from fiber-lib/src/build.rs
- Fix migration.rs auto_migrate() to use effective_latest_version() that
  considers dynamically registered migrations (fixes test failures)
- Fix test_run_migration open_db call to pass &Path reference
- Remove unused mut on DbMigrate variable in test
- Add open_store(path) that auto-confirms migration (for tests/simple setups)
- Rename old 3-param version to open_store_with_migration (for CLI/WASM)
- Fix all v0.7.x references to v0.8.x in migration messages, samples, docs
- Fix stderr flush compile error in fiber-bin cli_confirm
- Remove unused StorageBackend import in migration test
- Include db version and migration guidance in check_validate messages
quake added 3 commits May 7, 2026 12:23
- Use BTreeMap::range() instead of .iter().filter() for O(log n) lookup
- Replace .expect() with .ok() in get_db_version to avoid WASM trap
- Remove stale migrate/ references from release workflow
- Introduce MigrationStore object-safe trait backed by StorageBackend
  to keep Migration dyn-compatible while avoiding concrete Store type
@quake quake force-pushed the quake/rebase-on-develop branch from 5f9ebc2 to c9e0250 Compare May 7, 2026 04:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants