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

HicServices / RDMP / 6245535001

20 Sep 2023 07:44AM UTC coverage: 57.013%. First build
6245535001

push

github

web-flow
8.1.0 Release (#1628)

* Bump Newtonsoft.Json from 13.0.1 to 13.0.2

Bumps [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json) from 13.0.1 to 13.0.2.
- [Release notes](https://github.com/JamesNK/Newtonsoft.Json/releases)
- [Commits](https://github.com/JamesNK/Newtonsoft.Json/compare/13.0.1...13.0.2)

---
updated-dependencies:
- dependency-name: Newtonsoft.Json
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump NLog from 5.0.5 to 5.1.0

Bumps [NLog](https://github.com/NLog/NLog) from 5.0.5 to 5.1.0.
- [Release notes](https://github.com/NLog/NLog/releases)
- [Changelog](https://github.com/NLog/NLog/blob/dev/CHANGELOG.md)
- [Commits](https://github.com/NLog/NLog/compare/v5.0.5...v5.1.0)

---
updated-dependencies:
- dependency-name: NLog
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump NLog from 5.0.5 to 5.1.0

* Fix -r flag - should have been --results-directory all along

* Bump Newtonsoft.Json from 13.0.1 to 13.0.2

* Bump YamlDotNet from 12.0.2 to 12.1.0

Bumps [YamlDotNet](https://github.com/aaubry/YamlDotNet) from 12.0.2 to 12.1.0.
- [Release notes](https://github.com/aaubry/YamlDotNet/releases)
- [Commits](https://github.com/aaubry/YamlDotNet/compare/v12.0.2...v12.1.0)

---
updated-dependencies:
- dependency-name: YamlDotNet
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump Moq from 4.18.2 to 4.18.3

Bumps [Moq](https://github.com/moq/moq4) from 4.18.2 to 4.18.3.
- [Release notes](https://github.com/moq/moq4/releases)
- [Changelog](https://github.com/moq/moq4/blob/main/CHANGELOG.md)
- [Commits](https://github.com/moq/moq4/compare/v4.18.2...v4.18.3)

---
updated-dependencies:
- dependency-name: Moq
... (continued)

10732 of 20257 branches covered (0.0%)

Branch coverage included in aggregate %.

48141 of 48141 new or added lines in 1086 files covered. (100.0%)

30685 of 52388 relevant lines covered (58.57%)

7387.88 hits per line

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

62.79
/Rdmp.Core/MapsDirectlyToDatabaseTable/Versioning/Patch.cs
1
// Copyright (c) The University of Dundee 2018-2019
2
// This file is part of the Research Data Management Platform (RDMP).
3
// RDMP is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
4
// RDMP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
5
// You should have received a copy of the GNU General Public License along with RDMP. If not, see <https://www.gnu.org/licenses/>.
6

7
using System;
8
using System.Collections.Generic;
9
using System.Linq;
10
using FAnsi.Discovery;
11

12
namespace Rdmp.Core.MapsDirectlyToDatabaseTable.Versioning;
13

14
/// <summary>
15
/// Represents a Embedded Resource file in the up directory of a assembly found using an <see cref="IPatcher"/>.  Used during patching
16
/// to ensure that the live database that is about to be patched is in the expected state and ready for new patches to be applied.
17
/// </summary>
18
public class Patch : IComparable
19
{
20
    public const string VersionKey = "--Version:";
21
    public const string DescriptionKey = "--Description:";
22

23
    public string EntireScript { get; set; }
7,108✔
24
    public string locationInAssembly { get; private set; }
9,196✔
25

26
    public Version DatabaseVersionNumber { get; set; }
6,374✔
27
    public string Description { get; set; }
3,372✔
28

29

30
    public Patch(string scriptName, string entireScriptContents)
3,372✔
31
    {
32
        locationInAssembly = scriptName;
3,372✔
33
        EntireScript = entireScriptContents;
3,372✔
34

35
        ExtractDescriptionAndVersionFromScriptContents();
3,372✔
36
    }
3,372✔
37

38
    public override string ToString()
39
    {
40
        if (string.IsNullOrWhiteSpace(Description))
×
41
            return $"Patch {DatabaseVersionNumber}";
×
42

43
        return Description.Length > 100
×
44
            ? $"Patch {DatabaseVersionNumber}({Description[..100]}...)"
×
45
            : $"Patch {DatabaseVersionNumber}({Description})";
×
46
    }
47

48
    private void ExtractDescriptionAndVersionFromScriptContents()
49
    {
50
        var lines = EntireScript.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
3,372✔
51

52
        var idx = lines[0].IndexOf(VersionKey, StringComparison.Ordinal);
3,372✔
53

54
        if (idx == -1)
3,372!
55
            throw new InvalidPatchException(locationInAssembly, $"Script does not start with {VersionKey}");
×
56

57
        var versionNumber = lines[0][(idx + VersionKey.Length)..].Trim(':', ' ', '\n', '\r', '/', '*');
3,372✔
58

59
        try
60
        {
61
            DatabaseVersionNumber = new Version(versionNumber);
3,372✔
62
        }
3,372✔
63
        catch (Exception e)
×
64
        {
65
            throw new InvalidPatchException(locationInAssembly,
×
66
                $"Could not process the scripts --Version: entry ('{versionNumber}') into a valid C# Version object",
×
67
                e);
×
68
        }
69

70
        if (lines.Length >= 2)
3,372✔
71
        {
72
            idx = lines[1].IndexOf(DescriptionKey, StringComparison.Ordinal);
3,372✔
73

74
            if (idx == -1)
3,372!
75
                throw new InvalidPatchException(locationInAssembly,
×
76
                    $"Second line of patch scripts must start with {DescriptionKey}");
×
77

78
            var description = lines[1][(idx + DescriptionKey.Length)..].Trim(':', ' ', '\n', '\r', '/', '*');
3,372✔
79
            Description = description;
3,372✔
80
        }
81
    }
3,372✔
82

83
    /// <summary>
84
    /// Returns the body without the header text "--Version:1.2.0 etc".
85
    /// </summary>
86
    /// <returns></returns>
87
    public string GetScriptBody()
88
    {
89
        return string.Join(Environment.NewLine,
90✔
90
            EntireScript.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Skip(2));
90✔
91
    }
92

93
    public override int GetHashCode() => locationInAssembly.GetHashCode();
2,912✔
94

95
    public override bool Equals(object obj)
96
    {
97
        var x = this;
1,456✔
98

99
        if (obj is not Patch y)
1,456!
100
            return false;
×
101

102
        var equal = x.locationInAssembly.Equals(y.locationInAssembly);
1,456✔
103

104

105
        if (!equal)
1,456!
106
            return false;
×
107

108
        return x.DatabaseVersionNumber.Equals(y.DatabaseVersionNumber)
1,456!
109
            ? true
1,456✔
110
            : throw new InvalidPatchException(x.locationInAssembly,
1,456✔
111
                $"Patches x and y are being compared and they have the same location in assembly ({x.locationInAssembly})  but different Version numbers",
1,456✔
112
                null);
1,456✔
113
    }
114

115
    public int CompareTo(object obj)
116
    {
117
        if (obj is Patch patch)
×
118
            return -string.Compare(patch.locationInAssembly, locationInAssembly,
×
119
                StringComparison.Ordinal); //sort alphabetically (reverse)
×
120

121
        throw new Exception($"Cannot compare {GetType().Name} to {obj.GetType().Name}");
×
122
    }
123

124
    /// <summary>
125
    /// Describes the state of a database schema when compared to the <see cref="IPatcher"/> which manages its schema
126
    /// </summary>
127
    public enum PatchingState
128
    {
129
        /// <summary>
130
        /// Indicates that the running <see cref="IPatcher"/> has not detected any patches that require to be run on
131
        /// the database schema
132
        /// </summary>
133
        NotRequired,
134

135
        /// <summary>
136
        /// Indicates that the running <see cref="IPatcher"/> has identified patches that should be applied to the
137
        /// database schema
138
        /// </summary>
139
        Required,
140

141
        /// <summary>
142
        /// Indicates that the running <see cref="IPatcher"/> is older than the current database schema that is being
143
        /// connected to
144
        /// </summary>
145
        SoftwareBehindDatabase
146
    }
147

148
    public static PatchingState IsPatchingRequired(DiscoveredDatabase database, IPatcher patcher,
149
        out Version databaseVersion, out Patch[] patchesInDatabase,
150
        out SortedDictionary<string, Patch> allPatchesInAssembly)
151
    {
152
        databaseVersion = DatabaseVersionProvider.GetVersionFromDatabase(database);
56✔
153

154
        var scriptExecutor = new MasterDatabaseScriptExecutor(database);
56✔
155
        patchesInDatabase = scriptExecutor.GetPatchesRun();
56✔
156

157
        allPatchesInAssembly = patcher.GetAllPatchesInAssembly(database);
56✔
158

159
        var databaseAssemblyName = patcher.GetDbAssembly().GetName();
56✔
160

161
        if (databaseAssemblyName.Version < databaseVersion)
56!
162
            return PatchingState.SoftwareBehindDatabase;
×
163

164
        //if there are patches that have not been applied
165
        return
56!
166
            allPatchesInAssembly.Values
56✔
167
                .Except(patchesInDatabase)
56✔
168
                .Any()
56✔
169
                ? PatchingState.Required
56✔
170
                : PatchingState.NotRequired;
56✔
171
    }
172
}
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

© 2026 Coveralls, Inc