[#102] container: Migrate container listing storage

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-06-30 17:09:59 +03:00 committed by Alex Vanin
parent 98c5fd25c3
commit 2402768eae

View file

@ -66,6 +66,7 @@ func _deploy(data interface{}, isUpdate bool) {
ctx := storage.GetContext() ctx := storage.GetContext()
if isUpdate { if isUpdate {
migrateContainerLists(ctx) // from v0.9.1 to v0.9.2
return return
} }
@ -99,6 +100,23 @@ func _deploy(data interface{}, isUpdate bool) {
runtime.Log("container contract initialized") runtime.Log("container contract initialized")
} }
func migrateContainerLists(ctx storage.Context) {
const ownersKey = "ownersList"
containers := getAllContainers(ctx)
for i := range containers {
containerID := containers[i]
ownerID := getOwnerByID(ctx, containerID)
containerListKey := append(ownerID, containerID...)
storage.Put(ctx, containerListKey, containerID)
storage.Delete(ctx, ownerID)
}
storage.Delete(ctx, ownersKey)
}
func Migrate(script []byte, manifest []byte, data interface{}) bool { func Migrate(script []byte, manifest []byte, data interface{}) bool {
ctx := storage.GetReadOnlyContext() ctx := storage.GetReadOnlyContext()