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

mendersoftware / mender-server / 1495380963

14 Oct 2024 03:35PM UTC coverage: 70.373% (-2.5%) from 72.904%
1495380963

Pull #101

gitlab-ci

mineralsfree
feat: tenant list added

Ticket: MEN-7568
Changelog: None

Signed-off-by: Mikita Pilinka <mikita.pilinka@northern.tech>
Pull Request #101: feat: tenant list added

4406 of 6391 branches covered (68.94%)

Branch coverage included in aggregate %.

88 of 183 new or added lines in 10 files covered. (48.09%)

2623 existing lines in 65 files now uncovered.

36673 of 51982 relevant lines covered (70.55%)

31.07 hits per line

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

74.26
/backend/services/deployments/store/mongo/migrations.go
1
// Copyright 2023 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 mongo
15

16
import (
17
        "context"
18

19
        "github.com/pkg/errors"
20
        "go.mongodb.org/mongo-driver/mongo"
21

22
        "github.com/mendersoftware/mender-server/pkg/log"
23
        "github.com/mendersoftware/mender-server/pkg/mongo/migrate"
24
        ctx_store "github.com/mendersoftware/mender-server/pkg/store"
25
)
26

27
const (
28
        DbVersion        = "1.2.16"
29
        DbMinimumVersion = "1.2.16"
30
        DbName           = "deployment_service"
31
)
32

33
func Migrate(ctx context.Context,
34
        version string,
35
        client *mongo.Client,
UNCOV
36
        automigrate bool) error {
×
UNCOV
37

×
UNCOV
38
        l := log.FromContext(ctx)
×
UNCOV
39

×
UNCOV
40
        dbs, err := migrate.GetTenantDbs(ctx, client, ctx_store.IsTenantDb(DbName))
×
UNCOV
41
        if err != nil {
×
42
                return errors.Wrap(err, "failed go retrieve tenant DBs")
×
43
        }
×
44

UNCOV
45
        if len(dbs) == 0 {
×
UNCOV
46
                dbs = []string{DbName}
×
UNCOV
47
        }
×
48

UNCOV
49
        if automigrate {
×
UNCOV
50
                l.Infof("automigrate is ON, will apply migrations")
×
UNCOV
51
        } else {
×
52
                l.Infof("automigrate is OFF, will check db version compatibility")
×
53
        }
×
54

UNCOV
55
        for _, d := range dbs {
×
UNCOV
56
                err := MigrateSingle(ctx, d, version, client, automigrate)
×
UNCOV
57
                if err != nil {
×
58
                        return err
×
59
                }
×
60
        }
61

UNCOV
62
        return nil
×
63
}
64

65
func MigrateSingle(ctx context.Context,
66
        db string,
67
        version string,
68
        client *mongo.Client,
69
        automigrate bool) error {
1✔
70
        l := log.FromContext(ctx)
1✔
71

1✔
72
        l.Infof("migrating %s", db)
1✔
73

1✔
74
        ver, err := migrate.NewVersion(version)
1✔
75
        if err != nil {
1✔
76
                return errors.Wrap(err, "failed to parse service version")
×
77
        }
×
78

79
        m := migrate.SimpleMigrator{
1✔
80
                Client:      client,
1✔
81
                Db:          db,
1✔
82
                Automigrate: automigrate,
1✔
83
        }
1✔
84

1✔
85
        migrations := []migrate.Migration{
1✔
86
                &migration_1_2_1{
1✔
87
                        client: client,
1✔
88
                        db:     db,
1✔
89
                },
1✔
90
                &migration_1_2_2{
1✔
91
                        client: client,
1✔
92
                        db:     db,
1✔
93
                },
1✔
94
                &migration_1_2_3{
1✔
95
                        client: client,
1✔
96
                        db:     db,
1✔
97
                },
1✔
98
                &migration_1_2_4{
1✔
99
                        client: client,
1✔
100
                        db:     db,
1✔
101
                },
1✔
102
                &migration_1_2_5{
1✔
103
                        client: client,
1✔
104
                        db:     db,
1✔
105
                },
1✔
106
                &migration_1_2_6{
1✔
107
                        client: client,
1✔
108
                        db:     db,
1✔
109
                },
1✔
110
                &migration_1_2_7{
1✔
111
                        client: client,
1✔
112
                        db:     db,
1✔
113
                },
1✔
114
                &migration_1_2_9{
1✔
115
                        client: client,
1✔
116
                        db:     db,
1✔
117
                },
1✔
118
                &migration_1_2_10{
1✔
119
                        client: client,
1✔
120
                        db:     db,
1✔
121
                },
1✔
122
                &migration_1_2_11{
1✔
123
                        client: client,
1✔
124
                        db:     db,
1✔
125
                },
1✔
126
                &migration_1_2_13{
1✔
127
                        client: client,
1✔
128
                        db:     db,
1✔
129
                },
1✔
130
                &migration_1_2_14{
1✔
131
                        client: client,
1✔
132
                        db:     db,
1✔
133
                },
1✔
134
                &migration_1_2_15{
1✔
135
                        client: client,
1✔
136
                        db:     db,
1✔
137
                },
1✔
138
                &migration_1_2_16{
1✔
139
                        client: client,
1✔
140
                        db:     db,
1✔
141
                },
1✔
142
        }
1✔
143

1✔
144
        err = m.Apply(ctx, *ver, migrations)
1✔
145
        if err != nil {
1✔
146
                return errors.Wrap(err, "failed to apply migrations")
×
147
        }
×
148

149
        return nil
1✔
150
}
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