@@ -26,12 +26,16 @@ impl DatabaseCommand {
26
26
pub enum DatabaseSubCommand {
27
27
/// Migrate databases located in the given stores directory
28
28
Migrate ( MigrateCommand ) ,
29
+
30
+ /// Vacuum the aggregator main database
31
+ Vacuum ( VacuumCommand ) ,
29
32
}
30
33
31
34
impl DatabaseSubCommand {
32
35
pub async fn execute ( & self , root_logger : Logger ) -> StdResult < ( ) > {
33
36
match self {
34
37
Self :: Migrate ( cmd) => cmd. execute ( root_logger) . await ,
38
+ Self :: Vacuum ( cmd) => cmd. execute ( root_logger) . await ,
35
39
}
36
40
}
37
41
}
@@ -79,3 +83,38 @@ impl MigrateCommand {
79
83
Ok ( ( ) )
80
84
}
81
85
}
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