Skip to content

Commit

Permalink
fix subcommand migrate issues for background migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Feb 20, 2024
1 parent 4d76925 commit 2e29e60
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion ckb-bin/src/subcommand/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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\
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion util/migrate/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 2e29e60

Please sign in to comment.