-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df28490
commit 1f417c0
Showing
40 changed files
with
524 additions
and
415 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,64 @@ | ||
use ckb_app_config::{ExitCode, MigrateArgs}; | ||
use ckb_launcher::DatabaseMigration; | ||
use ckb_launcher::migrate::Migrate; | ||
|
||
use crate::helper::prompt; | ||
|
||
pub fn migrate(args: MigrateArgs) -> Result<(), ExitCode> { | ||
let migration = DatabaseMigration::new(&args.config.db.path); | ||
let migrate = Migrate::new(&args.config.db.path); | ||
|
||
if args.check { | ||
if migration.migration_check() { | ||
return Ok(()); | ||
} else { | ||
return Err(ExitCode::Cli); | ||
} | ||
} | ||
{ | ||
let read_only_db = migrate.open_read_only_db().map_err(|e| { | ||
eprintln!("migrate error {}", e); | ||
ExitCode::Failure | ||
})?; | ||
|
||
if !migration.migration_check() { | ||
return Ok(()); | ||
} | ||
if let Some(db) = read_only_db { | ||
if args.check { | ||
if migrate.check(&db) { | ||
return Ok(()); | ||
} else { | ||
return Err(ExitCode::Cli); | ||
} | ||
} | ||
|
||
if migration.require_expensive_migrations() && !args.force { | ||
if atty::is(atty::Stream::Stdin) && atty::is(atty::Stream::Stdout) { | ||
let input = prompt("\ | ||
\n\ | ||
Doing migration will take quite a long time before CKB could work again.\n\ | ||
Another choice is to delete all data, then synchronize them again.\n\ | ||
\n\ | ||
Once the migration started, the data will be no longer compatible with all older versions CKB,\n\ | ||
so we strongly recommended you to backup the old data before migrating.\n\ | ||
\nIf you want to migrate the data, please input YES, otherwise, the current process will exit.\n\ | ||
> ", | ||
); | ||
if input.trim().to_lowercase() != "yes" { | ||
eprintln!("The migration was declined since the user didn't confirm."); | ||
return Err(ExitCode::Failure); | ||
if !migrate.check(&db) { | ||
return Ok(()); | ||
} | ||
|
||
if migrate.require_expensive(&db) && !args.force { | ||
if atty::is(atty::Stream::Stdin) && atty::is(atty::Stream::Stdout) { | ||
let input = prompt("\ | ||
\n\ | ||
Doing migration will take quite a long time before CKB could work again.\n\ | ||
Another choice is to delete all data, then synchronize them again.\n\ | ||
\n\ | ||
Once the migration started, the data will be no longer compatible with all older versions CKB,\n\ | ||
so we strongly recommended you to backup the old data before migrating.\n\ | ||
\nIf you want to migrate the data, please input YES, otherwise, the current process will exit.\n\ | ||
> ", | ||
); | ||
if input.trim().to_lowercase() != "yes" { | ||
eprintln!("The migration was declined since the user didn't confirm."); | ||
return Err(ExitCode::Failure); | ||
} | ||
} else { | ||
eprintln!("Run error: use --force to migrate without interactive prompt"); | ||
return Err(ExitCode::Failure); | ||
} | ||
} | ||
} else { | ||
eprintln!("Run error: use --force to migrate without interactive prompt"); | ||
return Err(ExitCode::Failure); | ||
} | ||
} | ||
|
||
migration.migrate().map_err(|err| { | ||
eprintln!("Run error: {:?}", err); | ||
let bulk_load_db_db = migrate.open_bulk_load_db().map_err(|e| { | ||
eprintln!("migrate error {}", e); | ||
ExitCode::Failure | ||
})?; | ||
|
||
if let Some(db) = bulk_load_db_db { | ||
migrate.migrate(db).map_err(|err| { | ||
eprintln!("Run error: {:?}", err); | ||
ExitCode::Failure | ||
})?; | ||
} | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.