Skip to content

Commit e8642d0

Browse files
committed
* Corrected a database migration bug
* Increased the version column to allow non conformant versioning
1 parent 38d1a26 commit e8642d0

File tree

15 files changed

+6820
-5085
lines changed

15 files changed

+6820
-5085
lines changed

src/Server/Coderr.Server.SqlServer/Migrations/MigrationScripts.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4+
using System.Linq;
45
using System.Reflection;
56

67
namespace Coderr.Server.SqlServer.Migrations
@@ -9,6 +10,9 @@ public class MigrationScripts
910
{
1011
internal const string SchemaNamespace = "Coderr.Server.SqlServer.Schema";
1112
private readonly Dictionary<int, VersionMigration> _versions = new Dictionary<int, VersionMigration>();
13+
private bool _isEmpty;
14+
15+
public bool IsEmpty => _versions.Count == 0;
1216

1317
public void AddScript(int version, string scriptName)
1418
{
@@ -38,5 +42,10 @@ public IEnumerable<string> GetScripts(int version)
3842
yield return new StreamReader(res).ReadToEnd();
3943
}
4044
}
45+
46+
public int GetHighestVersion()
47+
{
48+
return _versions.Max(x => x.Key);
49+
}
4150
}
4251
}

src/Server/Coderr.Server.SqlServer/Migrations/SchemaManager.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ public int GetCurrentSchemaVersion()
7878

7979
public int GetLatestSchemaVersion()
8080
{
81+
if (!_migrationScripts.IsEmpty)
82+
{
83+
return _migrationScripts.GetHighestVersion();
84+
}
8185
var highestVersion = 0;
8286
var names =
8387
Assembly.GetExecutingAssembly()
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
--alter table ApplicationVersions alter column Version varchar(20) not null;
1+
alter table ApplicationVersions alter column Version varchar(20) not null;
22

3-
--UPDATE DatabaseSchema SET Version = 14;
3+
UPDATE DatabaseSchema SET Version = 14;

src/Server/Coderr.Server.Web/Boot/Cqs/RegisterCqsServices.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ public void Stop()
8888
{
8989
_log.Debug("Shutting down");
9090
_messagingQueueListenerTask.Wait(10000);
91+
}
92+
catch (TaskCanceledException)
93+
{
94+
9195
}
9296
catch (Exception ex)
9397
{

0 commit comments

Comments
 (0)