Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update mongo migration #63

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions Mongo.Migration.Test.Core/Mongo.Migration.Test.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
<PropertyGroup>
<IsPackable>false</IsPackable>
<OutputType>Library</OutputType>
<TargetFrameworks>net5.0;netcoreapp3.1</TargetFrameworks>
<LangVersion>9.0</LangVersion>
<TargetFrameworks>net6.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Mongo.Migration.Test\**\*.cs" />
Expand All @@ -21,9 +20,9 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="5.6.0" />
<PackageReference Include="IsExternalInit" Version="1.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PackageReference Include="IsExternalInit" Version="1.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.0" />
<PackageReference Include="NSubstitute" Version="4.1.0" />
Expand Down
31 changes: 13 additions & 18 deletions Mongo.Migration/Mongo.Migration.csproj
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Mongo.Migration</AssemblyName>
<RootNamespace>Mongo.Migration</RootNamespace>
<Version>3.1.4</Version>
<PackageVersion>3.1.4</PackageVersion>
<TargetFrameworks>net5.0;netcoreapp3.1</TargetFrameworks>
<LangVersion>9.0</LangVersion>
<TargetFrameworks>net6.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="IsExternalInit" Version="1.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="LightInject" Version="5.4.0" />
<PackageReference Include="LightInject" Version="6.6.1" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="2.2.0" />
<PackageReference Include="MongoDB.Driver" Version="2.13.1" />
<PackageReference Include="NLog" Version="4.7.11" />
<PackageReference Include="Serilog" Version="2.8.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="2.0.4" />
<PackageReference Include="Serilog.Extensions.Logging.File" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.3" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
<PackageReference Include="MongoDB.Driver" Version="2.18.0" />
<PackageReference Include="NLog" Version="5.1.0" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
<PackageReference Include="Serilog.Extensions.Logging.File" Version="3.0.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
</Project>
19 changes: 15 additions & 4 deletions Mongo.Migration/MongoMigration.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -13,29 +14,39 @@ internal class MongoMigration : IMongoMigration
private readonly IDatabaseTypeMigrationDependencyLocator _databaseMigrationLocator;
private readonly IMigrationService _migrationService;
private readonly IRuntimeVersionLocator _runtimeVersionLocator;
private readonly IMongoMigrationSettings _settings;

public MongoMigration(
IMigrationLocator<IDocumentMigration> documentMigrationLocator,
IDatabaseTypeMigrationDependencyLocator databaseMigrationLocator,
IRuntimeVersionLocator runtimeVersionLocator,
ICollectionLocator collectionLocator,
IStartUpVersionLocator startUpVersionLocator,
IMigrationService migrationService)
IMigrationService migrationService,
IMongoMigrationSettings settings)
{
_documentMigrationLocator = documentMigrationLocator;
_databaseMigrationLocator = databaseMigrationLocator;
_runtimeVersionLocator = runtimeVersionLocator;
_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();
Expand Down
15 changes: 11 additions & 4 deletions Mongo.Migration/Services/MigrationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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<MigrationService>();
_settings = settings;
}

public void Migrate()
Expand All @@ -46,7 +50,10 @@ public void Migrate()
private void OnStartup()
{
_startUpDatabaseMigrationRunner.RunAll();
_startUpDocumentMigrationRunner.RunAll();
if (!_settings.SkipDocumentMigration)
{
_startUpDocumentMigrationRunner.RunAll();
}
}

private void RegisterSerializer()
Expand Down
1 change: 1 addition & 0 deletions Mongo.Migration/Startup/IMongoMigrationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public interface IMongoMigrationSettings
DocumentVersion DatabaseMigrationVersion { get; set; }
string VersionFieldName { get; set; }
MongoClientSettings ClientSettings { get; set; }
public bool SkipDocumentMigration { get; set; }
}
}
2 changes: 2 additions & 0 deletions Mongo.Migration/Startup/MongoMigrationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ public class MongoMigrationSettings : IMongoMigrationSettings
public string VersionFieldName { get; set; }

public MongoClientSettings ClientSettings { get; set; }

public bool SkipDocumentMigration { get; set; } = true;
}
}