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:
cool-developer
2024-08-05 12:34:36 +00:00
committed by GitHub
co-authored by Matt Kocubinski
parent 0ddf5c0bfa
commit 6d4097bfb7
41 changed files with 1218 additions and 192 deletions
+2 -25
View File
@@ -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 ""
}