Skip to content

Commit 65b9a74

Browse files
committed
fix: Explicit version
1 parent 2e9c7a4 commit 65b9a74

2 files changed

Lines changed: 16 additions & 21 deletions

File tree

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
using LinkDotNet.Blog.UpgradeAssistant.Migrations;
2+
13
namespace LinkDotNet.Blog.UpgradeAssistant;
24

35
public static class MigrationDiscovery
46
{
57
public static IReadOnlyList<IMigration> DiscoverAll()
68
{
7-
return typeof(IMigration).Assembly
8-
.GetTypes()
9-
.Where(t => t is { IsClass: true, IsAbstract: false }
10-
&& typeof(IMigration).IsAssignableFrom(t))
11-
.Select(t => (IMigration)Activator.CreateInstance(t)!)
9+
return new IMigration[]
10+
{
11+
new Migration11To12()
12+
}
13+
.OrderBy(m => Version.TryParse(m.FromVersion, out var v) ? v : new Version(0, 0))
14+
.ThenBy(m => Version.TryParse(m.ToVersion, out var v) ? v : new Version(0, 0))
1215
.ToList();
1316
}
1417
}

tools/LinkDotNet.Blog.UpgradeAssistant/MigrationManager.cs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ public async Task<bool> MigrateFileAsync(string filePath, bool dryRun, string ba
5252
return false;
5353
}
5454

55-
var currentVersion = GetVersion(document);
56-
ConsoleOutput.WriteInfo($"Current version: {currentVersion ?? $"Not set (pre-{this.currentVersion})"}");
55+
var configVersion = GetVersion(document);
56+
ConsoleOutput.WriteInfo($"Current version: {configVersion ?? $"Not set (pre-{this.currentVersion})"}");
5757

58-
var applicableMigrations = GetApplicableMigrations(currentVersion);
58+
var applicableMigrations = GetApplicableMigrations(configVersion);
5959

6060
if (applicableMigrations.Count == 0)
6161
{
@@ -138,22 +138,14 @@ private static bool IsVersionControlledAppsettingsFile(string fileName)
138138
private List<IMigration> GetApplicableMigrations(string? currentVersion)
139139
{
140140
var result = new List<IMigration>();
141-
var startVersion = currentVersion ?? "11.0";
142-
var currentMigrationVersion = startVersion;
143-
var foundMigration = true;
141+
var currentMigrationVersion = currentVersion ?? "11.0";
144142

145-
while (foundMigration)
143+
foreach (var migration in migrations)
146144
{
147-
foundMigration = false;
148-
foreach (var migration in migrations)
145+
if (migration.FromVersion == currentMigrationVersion)
149146
{
150-
if (migration.FromVersion == currentMigrationVersion)
151-
{
152-
result.Add(migration);
153-
currentMigrationVersion = migration.ToVersion;
154-
foundMigration = true;
155-
break;
156-
}
147+
result.Add(migration);
148+
currentMigrationVersion = migration.ToVersion;
157149
}
158150
}
159151

0 commit comments

Comments
 (0)