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

mendersoftware / deployments / 1197570064

01 Mar 2024 06:24PM UTC coverage: 52.222% (-28.4%) from 80.645%
1197570064

Pull #998

gitlab-ci

web-flow
chore: bump github.com/Azure/azure-sdk-for-go/sdk/azcore

Bumps [github.com/Azure/azure-sdk-for-go/sdk/azcore](https://github.com/Azure/azure-sdk-for-go) from 1.9.1 to 1.10.0.
- [Release notes](https://github.com/Azure/azure-sdk-for-go/releases)
- [Changelog](https://github.com/Azure/azure-sdk-for-go/blob/main/documentation/release.md)
- [Commits](https://github.com/Azure/azure-sdk-for-go/compare/sdk/azcore/v1.9.1...sdk/azcore/v1.10.0)

---
updated-dependencies:
- dependency-name: github.com/Azure/azure-sdk-for-go/sdk/azcore
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #998: chore: bump github.com/Azure/azure-sdk-for-go/sdk/azcore from 1.9.1 to 1.10.0

5218 of 9992 relevant lines covered (52.22%)

0.55 hits per line

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

41.27
/store/mongo/migration_1_2_3.go
1
// Copyright 2021 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
        "fmt"
20

21
        "github.com/mendersoftware/go-lib-micro/mongo/doc"
22
        "github.com/mendersoftware/go-lib-micro/mongo/migrate"
23
        "github.com/pkg/errors"
24
        "go.mongodb.org/mongo-driver/bson"
25
        "go.mongodb.org/mongo-driver/mongo"
26

27
        "github.com/mendersoftware/deployments/model"
28
)
29

30
type migration_1_2_3 struct {
31
        client *mongo.Client
32
        db     string
33
}
34

35
// Up intrduces a unique index on artifact depends_idx and name to ensure unique depends in a
36
// release, also:
37
// - drops index on DeviceTypesCompatible, superseded by the above
38
// - rewrites DeviceTypesCompatible to 'depends.device_type' - even for v1, v2 artifacts
39
func (m *migration_1_2_3) Up(from migrate.Version) error {
1✔
40
        ctx := context.Background()
1✔
41
        c := m.client.Database(m.db).Collection(CollectionImages)
1✔
42

1✔
43
        // drop old device type + name index
1✔
44
        _, err := c.Indexes().DropOne(ctx, IndexUniqueNameAndDeviceTypeName)
1✔
45

1✔
46
        // the index might not be there - was created only on image inserts (not upfront)
1✔
47
        if err != nil {
2✔
48
                if except, ok := err.(mongo.CommandError); ok {
2✔
49
                        if except.Code != errorCodeNamespaceNotFound &&
1✔
50
                                except.Code != errorCodeIndexNotFound {
1✔
51
                                return err
×
52
                        }
×
53
                        // continue
54
                } else {
×
55
                        return err
×
56
                }
×
57
        }
58

59
        // transform existing device_types_compatible in v1 and v2 artifacts into 'depends.device_type'
60
        cursor, err := c.Find(ctx, bson.M{})
1✔
61
        if err != nil {
1✔
62
                return err
×
63
        }
×
64
        var artifacts []*model.Image
1✔
65
        if err = cursor.All(ctx, &artifacts); err != nil {
1✔
66
                return err
×
67
        }
×
68

69
        for _, a := range artifacts {
1✔
70
                // storage.Update is broken, do it manually via the driver
×
71
                dtypes := make([]interface{}, len(a.ArtifactMeta.DeviceTypesCompatible))
×
72

×
73
                for i, d := range a.ArtifactMeta.DeviceTypesCompatible {
×
74
                        dtypes[i] = interface{}(d)
×
75
                }
×
76

77
                depends := bson.M{
×
78
                        ArtifactDependsDeviceType: dtypes,
×
79
                }
×
80

×
81
                dependsIdx, err := doc.UnwindMap(depends)
×
82
                if err != nil {
×
83
                        return err
×
84
                }
×
85

86
                up := bson.M{
×
87
                        "$set": bson.M{
×
88
                                StorageKeyImageDepends:    depends,
×
89
                                StorageKeyImageDependsIdx: dependsIdx,
×
90
                        },
×
91
                }
×
92

×
93
                res, err := c.UpdateOne(ctx, bson.M{"_id": a.Id}, up)
×
94
                if err != nil {
×
95
                        return err
×
96
                }
×
97

98
                if res.MatchedCount != 1 {
×
99
                        return errors.New(fmt.Sprintf("failed to update artifact %s: not found", a.Id))
×
100
                }
×
101
        }
102

103
        // create new artifact depends + name index
104
        storage := NewDataStoreMongoWithClient(m.client)
1✔
105
        err = storage.EnsureIndexes(m.db,
1✔
106
                CollectionImages,
1✔
107
                IndexArtifactNameDepends)
1✔
108

1✔
109
        return err
1✔
110
}
111

112
func (m *migration_1_2_3) Version() migrate.Version {
1✔
113
        return migrate.MakeVersion(1, 2, 3)
1✔
114
}
1✔
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