From 18a368cb421f0fd97e16eb3ed2924a2c32f5bd8e Mon Sep 17 00:00:00 2001 From: Athanasios Eleftheriadis Date: Thu, 8 Dec 2022 13:19:15 +0200 Subject: [PATCH 1/2] update mongo migration --- Mongo.Migration/Mongo.Migration.csproj | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Mongo.Migration/Mongo.Migration.csproj b/Mongo.Migration/Mongo.Migration.csproj index 54fa498..787007e 100644 --- a/Mongo.Migration/Mongo.Migration.csproj +++ b/Mongo.Migration/Mongo.Migration.csproj @@ -7,19 +7,19 @@ net5.0;netcoreapp3.1 - + - - - - - - - - - - + + + + + + + + + + \ No newline at end of file From 484651b3e92e9b18a0fe155bbba150a9027706d8 Mon Sep 17 00:00:00 2001 From: Athanasios Eleftheriadis Date: Thu, 8 Dec 2022 14:40:21 +0200 Subject: [PATCH 2/2] add new setting for document migration --- .../Mongo.Migration.Test.Core.csproj | 2 +- Mongo.Migration/Mongo.Migration.csproj | 4 ++-- Mongo.Migration/MongoMigration.cs | 19 +++++++++++++++---- Mongo.Migration/Services/MigrationService.cs | 15 +++++++++++---- .../Startup/IMongoMigrationSettings.cs | 1 + .../Startup/MongoMigrationSettings.cs | 2 ++ 6 files changed, 32 insertions(+), 11 deletions(-) diff --git a/Mongo.Migration.Test.Core/Mongo.Migration.Test.Core.csproj b/Mongo.Migration.Test.Core/Mongo.Migration.Test.Core.csproj index 61bc545..fc2f7ef 100644 --- a/Mongo.Migration.Test.Core/Mongo.Migration.Test.Core.csproj +++ b/Mongo.Migration.Test.Core/Mongo.Migration.Test.Core.csproj @@ -2,7 +2,7 @@ false Library - net5.0;netcoreapp3.1 + net6.0 diff --git a/Mongo.Migration/Mongo.Migration.csproj b/Mongo.Migration/Mongo.Migration.csproj index 787007e..8120e77 100644 --- a/Mongo.Migration/Mongo.Migration.csproj +++ b/Mongo.Migration/Mongo.Migration.csproj @@ -1,10 +1,10 @@ - + Mongo.Migration Mongo.Migration 3.1.4 3.1.4 - net5.0;netcoreapp3.1 + net6.0 diff --git a/Mongo.Migration/MongoMigration.cs b/Mongo.Migration/MongoMigration.cs index 38cbe50..64979b4 100644 --- a/Mongo.Migration/MongoMigration.cs +++ b/Mongo.Migration/MongoMigration.cs @@ -1,7 +1,8 @@ -using Mongo.Migration.Documents.Locators; +using Mongo.Migration.Documents.Locators; using Mongo.Migration.Migrations.Document; using Mongo.Migration.Migrations.Locators; using Mongo.Migration.Services; +using Mongo.Migration.Startup; namespace Mongo.Migration { @@ -13,6 +14,7 @@ internal class MongoMigration : IMongoMigration private readonly IDatabaseTypeMigrationDependencyLocator _databaseMigrationLocator; private readonly IMigrationService _migrationService; private readonly IRuntimeVersionLocator _runtimeVersionLocator; + private readonly IMongoMigrationSettings _settings; public MongoMigration( IMigrationLocator documentMigrationLocator, @@ -20,7 +22,8 @@ public MongoMigration( IRuntimeVersionLocator runtimeVersionLocator, ICollectionLocator collectionLocator, IStartUpVersionLocator startUpVersionLocator, - IMigrationService migrationService) + IMigrationService migrationService, + IMongoMigrationSettings settings) { _documentMigrationLocator = documentMigrationLocator; _databaseMigrationLocator = databaseMigrationLocator; @@ -28,14 +31,22 @@ public MongoMigration( _collectionLocator = collectionLocator; _startUpVersionLocator = startUpVersionLocator; _migrationService = migrationService; + _settings = settings; } public void Run() { - _documentMigrationLocator.Locate(); + if (!_settings.SkipDocumentMigration) + { + _documentMigrationLocator.Locate(); + } _databaseMigrationLocator.Locate(); _runtimeVersionLocator.Locate(); - _collectionLocator.Locate(); + if(!_settings.SkipDocumentMigration) + { + _collectionLocator.Locate(); + } + _startUpVersionLocator.Locate(); _migrationService.Migrate(); diff --git a/Mongo.Migration/Services/MigrationService.cs b/Mongo.Migration/Services/MigrationService.cs index d925805..9f62538 100644 --- a/Mongo.Migration/Services/MigrationService.cs +++ b/Mongo.Migration/Services/MigrationService.cs @@ -4,6 +4,7 @@ using Mongo.Migration.Migrations.Database; using Mongo.Migration.Migrations.Document; using Mongo.Migration.Services.Interceptors; +using Mongo.Migration.Startup; using MongoDB.Bson; using MongoDB.Bson.Serialization; @@ -16,10 +17,11 @@ internal class MigrationService : IMigrationService private readonly IStartUpDatabaseMigrationRunner _startUpDatabaseMigrationRunner; private readonly IMigrationInterceptorProvider _provider; private readonly DocumentVersionSerializer _serializer; + private readonly IMongoMigrationSettings _settings; public MigrationService(DocumentVersionSerializer serializer, IMigrationInterceptorProvider provider, - IStartUpDocumentMigrationRunner startUpDocumentMigrationRunner, IStartUpDatabaseMigrationRunner startUpDatabaseMigrationRunner) - : this(serializer, provider, NullLoggerFactory.Instance) + IStartUpDocumentMigrationRunner startUpDocumentMigrationRunner, IStartUpDatabaseMigrationRunner startUpDatabaseMigrationRunner, IMongoMigrationSettings settings) + : this(serializer, provider, NullLoggerFactory.Instance, settings) { _startUpDocumentMigrationRunner = startUpDocumentMigrationRunner; _startUpDatabaseMigrationRunner = startUpDatabaseMigrationRunner; @@ -28,11 +30,13 @@ public MigrationService(DocumentVersionSerializer serializer, IMigrationIntercep private MigrationService( DocumentVersionSerializer serializer, IMigrationInterceptorProvider provider, - ILoggerFactory loggerFactory) + ILoggerFactory loggerFactory, + IMongoMigrationSettings settings) { _serializer = serializer; _provider = provider; _logger = loggerFactory.CreateLogger(); + _settings = settings; } public void Migrate() @@ -46,7 +50,10 @@ public void Migrate() private void OnStartup() { _startUpDatabaseMigrationRunner.RunAll(); - _startUpDocumentMigrationRunner.RunAll(); + if (!_settings.SkipDocumentMigration) + { + _startUpDocumentMigrationRunner.RunAll(); + } } private void RegisterSerializer() diff --git a/Mongo.Migration/Startup/IMongoMigrationSettings.cs b/Mongo.Migration/Startup/IMongoMigrationSettings.cs index 07f2aaf..ed9864f 100644 --- a/Mongo.Migration/Startup/IMongoMigrationSettings.cs +++ b/Mongo.Migration/Startup/IMongoMigrationSettings.cs @@ -10,5 +10,6 @@ public interface IMongoMigrationSettings DocumentVersion DatabaseMigrationVersion { get; set; } string VersionFieldName { get; set; } MongoClientSettings ClientSettings { get; set; } + public bool SkipDocumentMigration { get; set; } } } \ No newline at end of file diff --git a/Mongo.Migration/Startup/MongoMigrationSettings.cs b/Mongo.Migration/Startup/MongoMigrationSettings.cs index 25def9f..6fddab9 100644 --- a/Mongo.Migration/Startup/MongoMigrationSettings.cs +++ b/Mongo.Migration/Startup/MongoMigrationSettings.cs @@ -14,5 +14,7 @@ public class MongoMigrationSettings : IMongoMigrationSettings public string VersionFieldName { get; set; } public MongoClientSettings ClientSettings { get; set; } + + public bool SkipDocumentMigration { get; set; } = true; } } \ No newline at end of file