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

mendersoftware / mender-server / 1961830404

01 Aug 2025 06:29PM UTC coverage: 65.815% (+0.3%) from 65.555%
1961830404

Pull #849

gitlab-ci

web-flow
chore: bump the backend-docker-dependencies group across 10 directories with 2 updates

Bumps the backend-docker-dependencies group with 2 updates in the /backend/services/create-artifact-worker directory: golang and alpine.
Bumps the backend-docker-dependencies group with 1 update in the /backend/services/deployments directory: golang.
Bumps the backend-docker-dependencies group with 1 update in the /backend/services/deviceauth directory: golang.
Bumps the backend-docker-dependencies group with 1 update in the /backend/services/deviceconfig directory: golang.
Bumps the backend-docker-dependencies group with 1 update in the /backend/services/deviceconnect directory: golang.
Bumps the backend-docker-dependencies group with 1 update in the /backend/services/inventory directory: golang.
Bumps the backend-docker-dependencies group with 1 update in the /backend/services/iot-manager directory: golang.
Bumps the backend-docker-dependencies group with 1 update in the /backend/services/reporting directory: golang.
Bumps the backend-docker-dependencies group with 1 update in the /backend/services/useradm directory: golang.
Bumps the backend-docker-dependencies group with 1 update in the /backend/services/workflows directory: golang.


Updates `golang` from 1.24.4 to 1.24.5

Updates `alpine` from 3.22.0 to 3.22.1

Updates `golang` from 1.24.4 to 1.24.5

Updates `golang` from 1.24.4 to 1.24.5

Updates `golang` from 1.24.4 to 1.24.5

Updates `golang` from 1.24.4 to 1.24.5

Updates `golang` from 1.24.4 to 1.24.5

Updates `golang` from 1.24.4 to 1.24.5

Updates `golang` from 1.24.4 to 1.24.5

Updates `golang` from 1.24.4 to 1.24.5

Updates `golang` from 1.24.4 to 1.24.5

---
updated-dependencies:
- dependency-name: golang
  dependency-version: 1.24.5
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: backend-docker-dependencies
- dependency-name: alpine
  dependency-version: 3.22.1
  dependency-type: direct:production... (continued)
Pull Request #849: chore: bump the backend-docker-dependencies group across 10 directories with 2 updates

29335 of 44572 relevant lines covered (65.81%)

1.44 hits per line

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

80.85
/backend/pkg/mongo/migrate/db.go
1
// Copyright 2024 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
package migrate
15

16
import (
17
        "context"
18
        "time"
19

20
        "github.com/pkg/errors"
21
        "go.mongodb.org/mongo-driver/bson"
22
        "go.mongodb.org/mongo-driver/mongo"
23
        mopts "go.mongodb.org/mongo-driver/mongo/options"
24

25
        "github.com/mendersoftware/mender-server/pkg/store"
26
)
27

28
// this is a small internal data layer for the migration utils, may be shared by diff migrators
29
const (
30
        DbMigrationsColl = "migration_info"
31
)
32

33
type MigrationEntry struct {
34
        Version   Version   `bson:"version"`
35
        Timestamp time.Time `bson:"timestamp"`
36
}
37

38
// GetMigrationInfo retrieves a list of migrations applied to the db.
39
// On success the function returns the MigrationEntries present in the db
40
// sorted by the version in decending order.
41
func GetMigrationInfo(
42
        ctx context.Context,
43
        sess *mongo.Client,
44
        db string,
45
) ([]MigrationEntry, error) {
9✔
46
        c := sess.Database(db).Collection(DbMigrationsColl)
9✔
47
        findOpts := mopts.Find()
9✔
48
        findOpts.SetSort(bson.D{{
9✔
49
                Key: "version.major", Value: -1,
9✔
50
        }, {
9✔
51
                Key: "version.minor", Value: -1,
9✔
52
        }, {
9✔
53
                Key: "version.patch", Value: -1,
9✔
54
        }})
9✔
55

9✔
56
        cursor, err := c.Find(ctx, bson.M{
9✔
57
                "version": bson.M{"$exists": true},
9✔
58
        }, findOpts)
9✔
59
        if cursor == nil || err != nil {
9✔
60
                return nil, errors.Wrap(err, "db: failed to get migration info")
×
61
        }
×
62

63
        var infoArray []MigrationEntry
9✔
64
        err = cursor.All(ctx, &infoArray)
9✔
65
        return infoArray, err
9✔
66
}
67

68
// UpdateMigrationInfo inserts a migration entry in the migration info collection.
69
func UpdateMigrationInfo(
70
        ctx context.Context,
71
        version Version,
72
        sess *mongo.Client,
73
        db string,
74
) error {
9✔
75
        c := sess.Database(db).Collection(DbMigrationsColl)
9✔
76

9✔
77
        entry := MigrationEntry{
9✔
78
                Version:   version,
9✔
79
                Timestamp: time.Now(),
9✔
80
        }
9✔
81
        _, err := c.InsertOne(ctx, entry)
9✔
82
        if err != nil {
9✔
83
                return errors.Wrap(err, "db: failed to insert migration info")
×
84
        }
×
85
        // result.InsertedID (InsertOneResult)
86

87
        return nil
9✔
88
}
89

90
func GetTenantDbs(
91
        ctx context.Context,
92
        client *mongo.Client,
93
        matcher store.TenantDbMatchFunc,
94
) ([]string, error) {
5✔
95
        result, err := client.ListDatabaseNames(ctx, bson.M{})
5✔
96
        if err != nil {
5✔
97
                return nil, err
×
98
        }
×
99

100
        tenantDbs := make([]string, len(result))
5✔
101
        j := 0
5✔
102
        for _, db := range result {
10✔
103
                if matcher(db) {
5✔
104
                        tenantDbs[j] = db
×
105
                        j++
×
106
                }
×
107
        }
108
        tenantDbs = tenantDbs[:j]
5✔
109

5✔
110
        return tenantDbs, nil
5✔
111
}
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