@@ -233,6 +233,10 @@ pub enum Command {
233233 #[ clap( long, short, default_value = "10000" ) ]
234234 history : usize ,
235235 } ,
236+
237+ /// General database management
238+ #[ clap( subcommand) ]
239+ Database ( DatabaseCommand ) ,
236240}
237241
238242impl Command {
@@ -495,6 +499,18 @@ pub enum IndexCommand {
495499 } ,
496500}
497501
502+ #[ derive( Clone , Debug , Subcommand ) ]
503+ pub enum DatabaseCommand {
504+ /// Apply any pending migrations to the database schema in all shards
505+ Migrate ,
506+ /// Refresh the mapping of tables into different shards
507+ ///
508+ /// This command rebuilds the mappings of tables from one shard into all
509+ /// other shards. It makes it possible to fix these mappings when a
510+ /// database migration was interrupted before it could rebuild the
511+ /// mappings
512+ Remap ,
513+ }
498514#[ derive( Clone , Debug , Subcommand ) ]
499515pub enum CheckBlockMethod {
500516 /// The number of the target block
@@ -644,7 +660,7 @@ impl Context {
644660 }
645661
646662 fn store_and_pools ( self ) -> ( Arc < Store > , HashMap < Shard , ConnectionPool > ) {
647- let ( subgraph_store, pools) = StoreBuilder :: make_subgraph_store_and_pools (
663+ let ( subgraph_store, pools, _ ) = StoreBuilder :: make_subgraph_store_and_pools (
648664 & self . logger ,
649665 & self . node_id ,
650666 & self . config ,
@@ -1059,6 +1075,20 @@ async fn main() -> anyhow::Result<()> {
10591075 }
10601076 }
10611077 }
1078+ Database ( cmd) => {
1079+ match cmd {
1080+ DatabaseCommand :: Migrate => {
1081+ /* creating the store builder runs migrations */
1082+ let _store_builder = ctx. store_builder ( ) . await ;
1083+ println ! ( "All database migrations have been applied" ) ;
1084+ Ok ( ( ) )
1085+ }
1086+ DatabaseCommand :: Remap => {
1087+ let store_builder = ctx. store_builder ( ) . await ;
1088+ commands:: database:: remap ( & store_builder. coord ) . await
1089+ }
1090+ }
1091+ }
10621092 Prune {
10631093 deployment,
10641094 history,
0 commit comments