Browse Source

Migrator fixed.

pull/208/head
Sebastian Stehle 8 years ago
parent
commit
fdf5d5da0a
  1. 4
      src/Squidex.Infrastructure.MongoDb/Migrations/MongoMigrationStatus.cs
  2. 2
      src/Squidex.Infrastructure/Migrations/IMigrationStatus.cs
  3. 2
      src/Squidex.Infrastructure/Migrations/Migrator.cs
  4. 4
      tests/Squidex.Infrastructure.Tests/Migrations/MigratorTests.cs

4
src/Squidex.Infrastructure.MongoDb/Migrations/MongoMigrationStatus.cs

@ -34,13 +34,13 @@ namespace Squidex.Infrastructure.Migrations
return entity.Version; return entity.Version;
} }
public async Task<bool> TryLockAsync(int currentVersion) public async Task<bool> TryLockAsync()
{ {
var entity = var entity =
await Collection.FindOneAndUpdateAsync<MongoMigrationEntity>(x => x.Id == DefaultId, await Collection.FindOneAndUpdateAsync<MongoMigrationEntity>(x => x.Id == DefaultId,
Update Update
.Set(x => x.IsLocked, true) .Set(x => x.IsLocked, true)
.Set(x => x.Version, currentVersion), .Set(x => x.Version, 0),
UpsertFind); UpsertFind);
return entity == null || entity.IsLocked == false; return entity == null || entity.IsLocked == false;

2
src/Squidex.Infrastructure/Migrations/IMigrationStatus.cs

@ -14,7 +14,7 @@ namespace Squidex.Infrastructure.Migrations
{ {
Task<int> GetVersionAsync(); Task<int> GetVersionAsync();
Task<bool> TryLockAsync(int currentVersion); Task<bool> TryLockAsync();
Task UnlockAsync(int newVersion); Task UnlockAsync(int newVersion);
} }

2
src/Squidex.Infrastructure/Migrations/Migrator.cs

@ -42,7 +42,7 @@ namespace Squidex.Infrastructure.Migrations
{ {
var lastMigrator = migrations.FirstOrDefault(); var lastMigrator = migrations.FirstOrDefault();
while (!await migrationStatus.TryLockAsync(lastMigrator.ToVersion)) while (!await migrationStatus.TryLockAsync())
{ {
log.LogInformation(w => w log.LogInformation(w => w
.WriteProperty("action", "Migrate") .WriteProperty("action", "Migrate")

4
tests/Squidex.Infrastructure.Tests/Migrations/MigratorTests.cs

@ -32,7 +32,7 @@ namespace Squidex.Infrastructure.Migrations
return Task.FromResult(version); return Task.FromResult(version);
} }
public Task<bool> TryLockAsync(int currentVersion) public Task<bool> TryLockAsync()
{ {
var lockAcquired = false; var lockAcquired = false;
@ -65,7 +65,7 @@ namespace Squidex.Infrastructure.Migrations
public MigratorTests() public MigratorTests()
{ {
A.CallTo(() => status.GetVersionAsync()).Returns(0); A.CallTo(() => status.GetVersionAsync()).Returns(0);
A.CallTo(() => status.TryLockAsync(A<int>.Ignored)).Returns(true); A.CallTo(() => status.TryLockAsync()).Returns(true);
} }
[Fact] [Fact]

Loading…
Cancel
Save