@@ -176,6 +176,27 @@ pub trait MigratableKVStore: KVStore {
176176 fn list_all_keys ( & self ) -> Result < Vec < ( String , String , String ) > , io:: Error > ;
177177}
178178
179+ /// Migrates all data from one store to another.
180+ ///
181+ /// This operation assumes that `target_store` is empty, i.e., any data present under copied keys
182+ /// might get overriden. User must ensure `source_store` is not modified during operation,
183+ /// otherwise no consistency guarantees can be given.
184+ ///
185+ /// Will abort and return an error if any IO operation fails. Note that in this case the
186+ /// `target_store` might get left in an intermediate state.
187+ pub fn migrate_kv_store_data < S : MigratableKVStore , T : MigratableKVStore > (
188+ source_store : & mut S , target_store : & mut T ,
189+ ) -> Result < ( ) , io:: Error > {
190+ let keys_to_migrate = source_store. list_all_keys ( ) ?;
191+
192+ for ( primary_namespace, secondary_namespace, key) in & keys_to_migrate {
193+ let data = source_store. read ( primary_namespace, secondary_namespace, key) ?;
194+ target_store. write ( primary_namespace, secondary_namespace, key, & data) ?;
195+ }
196+
197+ Ok ( ( ) )
198+ }
199+
179200/// Trait that handles persisting a [`ChannelManager`], [`NetworkGraph`], and [`WriteableScore`] to disk.
180201///
181202/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
0 commit comments