• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / inventory / 1401701972

05 Aug 2024 08:32PM UTC coverage: 91.217%. Remained the same
1401701972

push

gitlab-ci

web-flow
Merge pull request #460 from mendersoftware/dependabot/docker/docker-dependencies-03b04ac819

chore: bump golang from 1.22.4-alpine3.19 to 1.22.5-alpine3.19 in the docker-dependencies group

3095 of 3393 relevant lines covered (91.22%)

148.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.0
/store/mongo/migration_1_1_0.go
1
// Copyright 2022 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14

15
package mongo
16

17
import (
18
        "context"
19

20
        "github.com/mendersoftware/go-lib-micro/mongo/migrate"
21
        mstore "github.com/mendersoftware/go-lib-micro/store"
22
        "go.mongodb.org/mongo-driver/bson"
23
        "go.mongodb.org/mongo-driver/mongo"
24
        mopts "go.mongodb.org/mongo-driver/mongo/options"
25

26
        "github.com/mendersoftware/inventory/model"
27
        "github.com/mendersoftware/inventory/utils"
28
)
29

30
type migration_1_1_0 struct {
31
        ms  *DataStoreMongo
32
        ctx context.Context
33
}
34

35
func (m *migration_1_1_0) Up(from migrate.Version) error {
13✔
36
        databaseName := mstore.DbFromContext(m.ctx, DbName)
13✔
37
        coll := m.ms.client.Database(databaseName).Collection(DbDevicesColl)
13✔
38
        indexView := coll.Indexes()
13✔
39
        keys := bson.D{
13✔
40
                {Key: DbDevAttributesText, Value: "text"},
13✔
41
        }
13✔
42
        name := DbDevAttributesText
13✔
43
        _, err := indexView.CreateOne(m.ctx, mongo.IndexModel{Keys: keys, Options: &mopts.IndexOptions{
13✔
44
                Name: &name,
13✔
45
        }})
13✔
46
        if err != nil {
13✔
47
                return err
×
48
        }
×
49
        //
50
        opts := &mopts.FindOptions{}
13✔
51
        opts.SetSort(bson.M{DbDevId: 1})
13✔
52
        c, err := coll.Find(m.ctx, bson.M{}, opts)
13✔
53
        if err != nil {
13✔
54
                return err
×
55
        }
×
56
        store := NewDataStoreMongoWithSession(m.ms.client)
13✔
57
        device := &model.Device{}
13✔
58
        for {
39✔
59
                hasNext := c.Next(m.ctx)
26✔
60
                if !hasNext {
39✔
61
                        break
13✔
62
                }
63
                err = c.Decode(device)
13✔
64
                if err != nil {
13✔
65
                        return err
×
66
                }
×
67
                text := utils.GetTextField(device)
13✔
68
                if device.Text != text {
26✔
69
                        err = store.UpdateDeviceText(m.ctx, device.ID, text)
13✔
70
                        if err != nil {
13✔
71
                                return err
×
72
                        }
×
73
                }
74
        }
75
        return err
13✔
76
}
77

78
func (m *migration_1_1_0) Version() migrate.Version {
35✔
79
        return migrate.MakeVersion(1, 1, 0)
35✔
80
}
35✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc