-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
forest-cli db
subcommands migration
#3355
Merged
elmattic
merged 7 commits into
elmattic/forest-tool-migration
from
elmattic/db-cmds-tool-migration
Aug 11, 2023
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b03ca6a
Migrate db stats and db clean subcommands
elmattic b335cfe
Fix spellcheck
elmattic a76173e
Maintain order
elmattic f3628fc
Merge remote-tracking branch 'origin/elmattic/forest-tool-migration' …
elmattic aa15c3f
Update scripts
elmattic 04032f7
Update CHANGELOG
elmattic 2ebdc84
Merge branch 'elmattic/forest-tool-migration' into elmattic/db-cmds-t…
elmattic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright 2019-2023 ChainSafe Systems | ||
// SPDX-License-Identifier: Apache-2.0, MIT | ||
|
||
use super::read_config; | ||
use crate::cli::subcommands::prompt_confirm; | ||
use crate::cli_shared::chain_path; | ||
use crate::db::db_engine::db_root; | ||
use crate::networks::NetworkChain; | ||
use clap::Subcommand; | ||
use tracing::error; | ||
|
||
#[derive(Debug, Subcommand)] | ||
pub enum DBCommands { | ||
/// Show DB stats | ||
Stats { | ||
/// Optional TOML file containing forest daemon configuration | ||
#[arg(short, long)] | ||
config: Option<String>, | ||
/// Optional chain, will override the chain section of configuration file if used | ||
#[arg(long)] | ||
chain: Option<NetworkChain>, | ||
}, | ||
/// DB destruction | ||
Destroy { | ||
/// Answer yes to all forest-cli yes/no questions without prompting | ||
#[arg(long)] | ||
force: bool, | ||
/// Optional TOML file containing forest daemon configuration | ||
#[arg(short, long)] | ||
config: Option<String>, | ||
/// Optional chain, will override the chain section of configuration file if used | ||
#[arg(long)] | ||
chain: Option<NetworkChain>, | ||
}, | ||
} | ||
|
||
impl DBCommands { | ||
pub async fn run(&self) -> anyhow::Result<()> { | ||
match self { | ||
Self::Stats { config, chain } => { | ||
use human_repr::HumanCount; | ||
|
||
let config = read_config(config, chain)?; | ||
|
||
let dir = db_root(&chain_path(&config)); | ||
println!("Database path: {}", dir.display()); | ||
let size = fs_extra::dir::get_size(dir).unwrap_or_default(); | ||
println!("Database size: {}", size.human_count_bytes()); | ||
Ok(()) | ||
} | ||
Self::Destroy { | ||
force, | ||
config, | ||
chain, | ||
} => { | ||
let config = read_config(config, chain)?; | ||
|
||
let dir = chain_path(&config); | ||
if !dir.is_dir() { | ||
println!( | ||
"Aborted. Database path {} is not a valid directory", | ||
dir.display() | ||
); | ||
return Ok(()); | ||
} | ||
println!("Deleting {}", dir.display()); | ||
if !force && !prompt_confirm() { | ||
println!("Aborted."); | ||
return Ok(()); | ||
} | ||
match fs_extra::dir::remove(&dir) { | ||
Ok(_) => { | ||
println!("Deleted {}", dir.display()); | ||
Ok(()) | ||
} | ||
Err(err) => { | ||
error!("{err}"); | ||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does it have to be a macro?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a personal preference here. At some point I believe this code will be deleted anyway, once users have migrated to the new binaries.