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

mendersoftware / deployments / 1280684078

06 May 2024 08:13PM UTC coverage: 79.689% (+0.08%) from 79.606%
1280684078

Pull #1018

gitlab-ci

tranchitella
feat: return 409 on conflicts where creating a deployment with the same parameters as an already existing and active deployment

Changelog: none
Ticket: MEN-6622

Signed-off-by: Fabio Tranchitella <fabio.tranchitella@northern.tech>
Pull Request #1018: feat: prevent the creation of deployments if there is already an active deployment with the same constructor parameters

61 of 66 new or added lines in 7 files covered. (92.42%)

12 existing lines in 2 files now uncovered.

8102 of 10167 relevant lines covered (79.69%)

34.63 hits per line

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

95.24
/store/mongo/migration_1_2_16.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

15
package mongo
16

17
import (
18
        "context"
19
        "fmt"
20

21
        "github.com/mendersoftware/go-lib-micro/mongo/migrate"
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

27
type migration_1_2_16 struct {
28
        client *mongo.Client
29
        db     string
30
}
31

32
func (m *migration_1_2_16) Up(from migrate.Version) error {
18✔
33
        ctx := context.Background()
18✔
34
        idxDeployments := m.client.
18✔
35
                Database(m.db).
18✔
36
                Collection(CollectionDeployments).
18✔
37
                Indexes()
18✔
38

18✔
39
        _, err := idxDeployments.CreateOne(ctx, mongo.IndexModel{
18✔
40
                Keys: bson.D{
18✔
41
                        {
18✔
42
                                Key:   StorageKeyDeploymentConstructorChecksum,
18✔
43
                                Value: 1,
18✔
44
                        },
18✔
45
                },
18✔
46
                Options: mopts.Index().
18✔
47
                        SetName(IndexNameDeploymentConstructorChecksum).
18✔
48
                        SetPartialFilterExpression(
18✔
49
                                bson.D{
18✔
50
                                        {
18✔
51
                                                Key: StorageKeyDeploymentConstructorChecksum,
18✔
52
                                                Value: bson.D{
18✔
53
                                                        {
18✔
54
                                                                Key:   "$exists",
18✔
55
                                                                Value: true,
18✔
56
                                                        },
18✔
57
                                                },
18✔
58
                                        },
18✔
59
                                        {
18✔
60
                                                Key:   StorageKeyDeploymentActive,
18✔
61
                                                Value: true,
18✔
62
                                        },
18✔
63
                                },
18✔
64
                        ).
18✔
65
                        SetUnique(true),
18✔
66
        })
18✔
67
        if err != nil {
18✔
NEW
68
                return fmt.Errorf("mongo(1.2.16): failed to create index: %w", err)
×
NEW
69
        }
×
70
        return nil
18✔
71
}
72

73
func (m *migration_1_2_16) Version() migrate.Version {
55✔
74
        return migrate.MakeVersion(1, 2, 16)
55✔
75
}
55✔
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