From 2e29e605a1d0ad67d0025d68aa8bf00e439528e6 Mon Sep 17 00:00:00 2001 From: yukang Date: Tue, 20 Feb 2024 11:34:01 +0800 Subject: [PATCH] fix subcommand migrate issues for background migrations --- ckb-bin/src/subcommand/migrate.rs | 8 +++++++- util/migrate/src/tests.rs | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ckb-bin/src/subcommand/migrate.rs b/ckb-bin/src/subcommand/migrate.rs index e20aeea068..43cca15693 100644 --- a/ckb-bin/src/subcommand/migrate.rs +++ b/ckb-bin/src/subcommand/migrate.rs @@ -15,7 +15,9 @@ pub fn migrate(args: MigrateArgs) -> Result<(), ExitCode> { })?; if let Some(db) = read_only_db { - let db_status = migrate.check(&db, args.include_background); + // if there are only pending background migrations, they will run automatically + // so here we check with `include_background` as true + let db_status = migrate.check(&db, true); if matches!(db_status, Ordering::Greater) { eprintln!( "The database was created by a higher version CKB executable binary \n\ @@ -25,8 +27,12 @@ pub fn migrate(args: MigrateArgs) -> Result<(), ExitCode> { return Err(ExitCode::Failure); } + // `include_background` is default to false + let db_status = migrate.check(&db, args.include_background); if args.check { if matches!(db_status, Ordering::Less) { + // special for bash usage, return 0 means need run migration + // if ckb migrate --check; then ckb migrate --force; fi return Ok(()); } else { return Err(ExitCode::Cli); diff --git a/util/migrate/src/tests.rs b/util/migrate/src/tests.rs index 2bb5c084a0..f8335c6fc0 100644 --- a/util/migrate/src/tests.rs +++ b/util/migrate/src/tests.rs @@ -161,5 +161,5 @@ fn test_mock_migration() { let rdb = mg2.open_read_only_db().unwrap().unwrap(); - assert_eq!(mg2.check(&rdb, false), std::cmp::Ordering::Equal) + assert_eq!(mg2.check(&rdb, true), std::cmp::Ordering::Equal) }