-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #759 from dolittle/migrations
Added support for painless upgrades from V6 & older runtimes.
- Loading branch information
Showing
25 changed files
with
535 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
Source/Diagnostics/OpenTelemetry/Tracing/RuntimeActivity.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright (c) Dolittle. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Dolittle.Runtime.Diagnostics.OpenTelemetry; | ||
|
||
public static class RuntimeActivity | ||
{ | ||
public const string SourceName = "Dolittle.Runtime"; | ||
public static readonly System.Diagnostics.ActivitySource Source = new(SourceName); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright (c) Dolittle. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Dolittle.Runtime.Diagnostics.OpenTelemetry; | ||
|
||
public static class Tags | ||
{ | ||
public const string TenantId = "tenant_id"; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 0 additions & 14 deletions
14
Source/Events.Store.MongoDB/Legacy/EventStoreBackwardsCompatibilityConfiguration.cs
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
Source/Events.Store.MongoDB/Legacy/EventStoreBackwardsCompatibleVersion.cs
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
Source/Events.Store.MongoDB/Migrations/DatabaseMetadata.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) Dolittle. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using MongoDB.Bson.Serialization.Attributes; | ||
|
||
namespace Dolittle.Runtime.Events.Store.MongoDB.Migrations; | ||
|
||
public class DatabaseMetadata | ||
{ | ||
[BsonId] public string Id { get; set; } = "database"; | ||
public List<Migration> Migrations { get; set; } = new(); | ||
public required string CurrentVersion { get; set; } | ||
public required DateTimeOffset UpdatedAt { get; set; } | ||
|
||
public class Migration | ||
{ | ||
public required string Version { get; set; } | ||
public required DateTimeOffset Timestamp { get; set; } | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
Source/Events.Store.MongoDB/Migrations/DatabaseMigrator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) Dolittle. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Dolittle.Runtime.Domain.Tenancy; | ||
using Dolittle.Runtime.Events.Store.MongoDB.Migrations; | ||
using Dolittle.Runtime.Server.Bootstrap; | ||
|
||
namespace Dolittle.Runtime.Events.Store.MongoDB; | ||
|
||
public class DatabaseMigrator : ICanPerformBoostrapProcedure | ||
{ | ||
readonly Func<TenantId, IDbMigration> _getMigrator; | ||
|
||
public DatabaseMigrator(Func<TenantId, IDbMigration> getMigrator) | ||
{ | ||
_getMigrator = getMigrator; | ||
} | ||
|
||
public async Task PerformForTenant(TenantId tenant) | ||
{ | ||
await _getMigrator(tenant).MigrateTenant(); | ||
} | ||
|
||
|
||
public int Priority => 1000; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright (c) Dolittle. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Dolittle.Runtime.Events.Store.MongoDB.Migrations; | ||
|
||
static class Extensions | ||
{ | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
Source/Events.Store.MongoDB/Migrations/MetadataRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) Dolittle. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Threading.Tasks; | ||
using Dolittle.Runtime.DependencyInversion.Scoping; | ||
using MongoDB.Driver; | ||
|
||
namespace Dolittle.Runtime.Events.Store.MongoDB.Migrations; | ||
|
||
public interface IManageDatabaseMetadata | ||
{ | ||
public Task<DatabaseMetadata?> Get(); | ||
public Task Set(DatabaseMetadata metadata); | ||
} | ||
|
||
[PerTenant] | ||
public class MetadataRepository : IManageDatabaseMetadata | ||
{ | ||
const string CollectionName = "metadata"; | ||
const string MetadataId = "database"; | ||
|
||
|
||
IMongoCollection<DatabaseMetadata> _collection; | ||
|
||
public MetadataRepository(IDatabaseConnection db) | ||
{ | ||
_collection = db.Database.GetCollection<DatabaseMetadata>(CollectionName); | ||
} | ||
|
||
public async Task<DatabaseMetadata?> Get() => await _collection.Find(Builders<DatabaseMetadata>.Filter.Eq(it => it.Id, MetadataId)) | ||
.FirstOrDefaultAsync(); | ||
|
||
public Task Set(DatabaseMetadata metadata) => _collection.ReplaceOneAsync(Builders<DatabaseMetadata>.Filter.Eq(it => it.Id, MetadataId), metadata, | ||
new ReplaceOptions { IsUpsert = true }); | ||
} |
Oops, something went wrong.