From 2402768eaee1466b803e9e0d6804b3b72803f4d9 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 30 Jun 2021 17:09:59 +0300 Subject: [PATCH] [#102] container: Migrate container listing storage Signed-off-by: Alex Vanin --- container/container_contract.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/container/container_contract.go b/container/container_contract.go index 2b3d53a..a12fd1a 100644 --- a/container/container_contract.go +++ b/container/container_contract.go @@ -66,6 +66,7 @@ func _deploy(data interface{}, isUpdate bool) { ctx := storage.GetContext() if isUpdate { + migrateContainerLists(ctx) // from v0.9.1 to v0.9.2 return } @@ -99,6 +100,23 @@ func _deploy(data interface{}, isUpdate bool) { 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 { ctx := storage.GetReadOnlyContext()