feat(store/v2): implement the feature to upgrade the store keys (#20453)
Co-authored-by: Matt Kocubinski <mkocubinski@gmail.com>
This commit is contained in:
co-authored by
Matt Kocubinski
parent
0ddf5c0bfa
commit
6d4097bfb7
+2
-25
@@ -2,17 +2,8 @@ package store
|
||||
|
||||
// StoreUpgrades defines a series of transformations to apply the multistore db upon load
|
||||
type StoreUpgrades struct {
|
||||
Added []string `json:"added"`
|
||||
Renamed []StoreRename `json:"renamed"`
|
||||
Deleted []string `json:"deleted"`
|
||||
}
|
||||
|
||||
// StoreRename defines a name change of a sub-store.
|
||||
// All data previously under a PrefixStore with OldKey will be copied
|
||||
// to a PrefixStore with NewKey, then deleted from OldKey store.
|
||||
type StoreRename struct {
|
||||
OldKey string `json:"old_key"`
|
||||
NewKey string `json:"new_key"`
|
||||
Added []string `json:"added"`
|
||||
Deleted []string `json:"deleted"`
|
||||
}
|
||||
|
||||
// IsAdded returns true if the given key should be added
|
||||
@@ -40,17 +31,3 @@ func (s *StoreUpgrades) IsDeleted(key string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// RenamedFrom returns the oldKey if it was renamed
|
||||
// Returns "" if it was not renamed
|
||||
func (s *StoreUpgrades) RenamedFrom(key string) string {
|
||||
if s == nil {
|
||||
return ""
|
||||
}
|
||||
for _, re := range s.Renamed {
|
||||
if re.NewKey == key {
|
||||
return re.OldKey
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user