-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrations.go
43 lines (33 loc) · 967 Bytes
/
migrations.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package keeper
import (
"github.com/gogo/protobuf/grpc"
v043 "github.com/mycodeku/transtionhelper/x/auth/migrations/v043"
"github.com/mycodeku/transtionhelper/x/auth/types"
sdk "github.com/mycodeku/transtionhelper/types"
)
// Migrator is a struct for handling in-place store migrations.
type Migrator struct {
keeper AccountKeeper
queryServer grpc.Server
}
// NewMigrator returns a new Migrator.
func NewMigrator(keeper AccountKeeper, queryServer grpc.Server) Migrator {
return Migrator{keeper: keeper, queryServer: queryServer}
}
// Migrate1to2 migrates from version 1 to 2.
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
var iterErr error
m.keeper.IterateAccounts(ctx, func(account types.AccountI) (stop bool) {
wb, err := v043.MigrateAccount(ctx, account, m.queryServer)
if err != nil {
iterErr = err
return true
}
if wb == nil {
return false
}
m.keeper.SetAccount(ctx, wb)
return false
})
return iterErr
}