• 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

84.91
/store/mongo/migration_1_2_10.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/deployments/model"
21

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
        mopts "go.mongodb.org/mongo-driver/mongo/options"
27
)
28

29
type migration_1_2_10 struct {
30
        client *mongo.Client
31
        db     string
32
}
33

34
const IndexDeploymentsActiveCreatedV2 = "active_created:v2"
35

36
func (m *migration_1_2_10) Up(from migrate.Version) (err error) {
1✔
37

1✔
38
        ctx := context.Background()
1✔
39
        // MEN-5695: This index from the parent collection is not reliably
1✔
40
        //           created in the parent collection because of the
1✔
41
        //           renameCollection operation (removed).
1✔
42
        db := m.client.Database(m.db)
1✔
43
        _, err = db.Collection(CollectionDevices).
1✔
44
                Indexes().
1✔
45
                CreateOne(ctx, IndexDeviceDeploymentsActiveCreatedModel)
1✔
46
        if err != nil {
1✔
47
                return errors.Wrapf(err, "failed to create index '%s'",
×
48
                        IndexDeviceDeploymentsActiveCreated)
×
49
        }
×
50

51
        // Ensure that we can index the 'active' field.
52
        // NOTE: Requires that no client prior to 1.2.8 writes to the
53
        //       database.
54
        collDpl := db.Collection(CollectionDeployments)
1✔
55
        _, err = collDpl.UpdateMany(ctx, bson.D{{
1✔
56
                Key: StorageKeyDeploymentStatus,
1✔
57
                Value: bson.D{{
1✔
58
                        Key: "$ne", Value: model.DeploymentStatusFinished,
1✔
59
                }},
1✔
60
        }}, bson.D{{
1✔
61
                Key: "$set", Value: bson.D{{
1✔
62
                        Key:   StorageKeyDeploymentActive,
1✔
63
                        Value: true,
1✔
64
                }},
1✔
65
        }})
1✔
66
        if err != nil {
1✔
67
                return errors.Wrap(err, "failed to update database schema")
×
68
        }
×
69

70
        // MEN-5695: The index from migration 1.2.8 (removed) is not
71
        //           utilized for the majority of queries targetted at
72
        //           it because of the missing key on the "active"
73
        //           field. We make it sparse since we don't care about
74
        //           old 'inactive' deployments.
75
        idxDpl := collDpl.Indexes()
1✔
76
        _, err = idxDpl.CreateOne(ctx, mongo.IndexModel{
1✔
77
                Keys: bson.D{
1✔
78
                        {Key: StorageKeyDeploymentActive, Value: 1},
1✔
79
                        {Key: StorageKeyDeploymentCreated, Value: 1},
1✔
80
                },
1✔
81
                Options: mopts.Index().
1✔
82
                        SetName(IndexDeploymentsActiveCreatedV2).
1✔
83
                        SetSparse(true),
1✔
84
        })
1✔
85
        if err != nil {
1✔
86
                return errors.Wrapf(err, "failed to create index '%s'",
×
87
                        IndexDeploymentsActiveCreatedV2)
×
88
        }
×
89
        // MEN-5695: This index is no longer needed.
90
        _, err = idxDpl.DropOne(ctx, IndexDeploymentsActiveCreated)
1✔
91
        var srvErr mongo.ServerError
1✔
92
        if errors.As(err, &srvErr) {
2✔
93
                if srvErr.HasErrorCode(errorCodeIndexNotFound) {
2✔
94
                        err = nil
1✔
95
                }
1✔
96
        }
97

98
        return err
1✔
99
}
100

101
func (m *migration_1_2_10) Version() migrate.Version {
1✔
102
        return migrate.MakeVersion(1, 2, 10)
1✔
103
}
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