Skip to content

Commit 0917af8

Browse files
committed
refactor: let 'volt migrate lockjson' use JSON DSL
1 parent 3fe1681 commit 0917af8

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

migration/lockjson.go

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package migration
22

33
import (
4-
"errors"
4+
"context"
55

6+
"github.com/pkg/errors"
67
"github.com/vim-volt/volt/config"
8+
"github.com/vim-volt/volt/dsl"
9+
"github.com/vim-volt/volt/dsl/dslctx"
10+
"github.com/vim-volt/volt/dsl/ops"
711
"github.com/vim-volt/volt/lockjson"
8-
"github.com/vim-volt/volt/transaction"
912
)
1013

1114
func init() {
@@ -32,22 +35,12 @@ Description
3235
To suppress this, running this command simply reads and writes migrated structure to lock.json.`
3336
}
3437

35-
func (*lockjsonMigrater) Migrate(lockJSON *lockjson.LockJSON, cfg *config.Config) (result error) {
36-
// Begin transaction
37-
trx, err := transaction.Start()
38+
func (*lockjsonMigrater) Migrate(lockJSON *lockjson.LockJSON, cfg *config.Config) error {
39+
ctx := dslctx.WithDSLValues(context.Background(), lockJSON, cfg)
40+
expr, err := ops.LockJSONWriteOp.Bind()
3841
if err != nil {
39-
return err
42+
return errors.Wrapf(err, "cannot bind %s operator", ops.LockJSONWriteOp.String())
4043
}
41-
defer func() {
42-
if err := trx.Done(); err != nil {
43-
result = err
44-
}
45-
}()
46-
47-
// Write to lock.json
48-
err = lockJSON.Write()
49-
if err != nil {
50-
return errors.New("could not write to lock.json: " + err.Error())
51-
}
52-
return nil
44+
_, err = dsl.Execute(ctx, expr)
45+
return err
5346
}

0 commit comments

Comments
 (0)