Skip to content

Commit b5e416f

Browse files
committed
feat(aggregator): add database vacuum clap command
1 parent 4cbe62a commit b5e416f

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

mithril-aggregator/src/commands/database_command.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,16 @@ impl DatabaseCommand {
2626
pub enum DatabaseSubCommand {
2727
/// Migrate databases located in the given stores directory
2828
Migrate(MigrateCommand),
29+
30+
/// Vacuum the aggregator main database
31+
Vacuum(VacuumCommand),
2932
}
3033

3134
impl DatabaseSubCommand {
3235
pub async fn execute(&self, root_logger: Logger) -> StdResult<()> {
3336
match self {
3437
Self::Migrate(cmd) => cmd.execute(root_logger).await,
38+
Self::Vacuum(cmd) => cmd.execute(root_logger).await,
3539
}
3640
}
3741
}
@@ -79,3 +83,38 @@ impl MigrateCommand {
7983
Ok(())
8084
}
8185
}
86+
87+
#[derive(Parser, Debug, Clone)]
88+
pub struct VacuumCommand {
89+
/// Stores directory
90+
#[clap(long, env = "STORES_DIRECTORY")]
91+
stores_directory: PathBuf,
92+
}
93+
94+
impl VacuumCommand {
95+
pub async fn execute(&self, root_logger: Logger) -> StdResult<()> {
96+
let config = Configuration {
97+
environment: ExecutionEnvironment::Production,
98+
data_stores_directory: self.stores_directory.clone(),
99+
// Temporary solution to avoid the need to provide a full configuration
100+
..Configuration::new_sample(std::env::temp_dir())
101+
};
102+
debug!(root_logger, "DATABASE VACUUM command"; "config" => format!("{config:?}"));
103+
println!(
104+
"Vacuuming database from stores directory: {}",
105+
self.stores_directory.to_string_lossy()
106+
);
107+
let mut dependencies_builder =
108+
DependenciesBuilder::new(root_logger.clone(), config.clone());
109+
110+
dependencies_builder
111+
.get_upkeep_service()
112+
.await
113+
.with_context(|| "Dependencies Builder can not get upkeep service")?
114+
.vacuum()
115+
.await
116+
.with_context(|| "Upkeep service can not vacuum")?;
117+
118+
Ok(())
119+
}
120+
}

0 commit comments

Comments
 (0)