diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 8bfd3bc..4f08da3 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -13,11 +13,11 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions/setup-dotnet@v4 + - uses: actions/checkout@v6 + - uses: actions/setup-dotnet@v5 - name: Restore dependencies run: dotnet restore - name: Build run: dotnet build -c Release --no-restore - name: Test - run: dotnet test -c Release --no-build --framework net9.0 + run: dotnet test -c Release --no-build --framework net10.0 diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 648fa69..be99135 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -16,14 +16,14 @@ jobs: packages: write contents: read steps: - - uses: actions/checkout@v4 - - uses: actions/setup-dotnet@v4 + - uses: actions/checkout@v6 + - uses: actions/setup-dotnet@v5 - name: Set VERSION variable from tag run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV - name: Build run: dotnet build -c Release /p:Version=${VERSION} - name: Test - run: dotnet test -c Release /p:Version=${VERSION} --no-build --framework net9.0 + run: dotnet test -c Release /p:Version=${VERSION} --no-build --framework net10.0 - name: Pack run: dotnet pack -c Release /p:Version=${VERSION} --no-build --output . - name: Push diff --git a/LICENSE.txt b/LICENSE.md similarity index 95% rename from LICENSE.txt rename to LICENSE.md index 6442aad..cfd64ed 100644 --- a/LICENSE.txt +++ b/LICENSE.md @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017 Sean Roddis +Copyright (c) 2026 Rafael Pallares Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE. diff --git a/Mongo.Migration.Tests/Documents/Serializers/DocumentVersionSerializer_when_serialize_and_deserialize.cs b/Mongo.Migration.Tests/Documents/Serializers/DocumentVersionSerializer_when_serialize_and_deserialize.cs index 7231754..5a89afe 100644 --- a/Mongo.Migration.Tests/Documents/Serializers/DocumentVersionSerializer_when_serialize_and_deserialize.cs +++ b/Mongo.Migration.Tests/Documents/Serializers/DocumentVersionSerializer_when_serialize_and_deserialize.cs @@ -63,7 +63,7 @@ private static BsonDocumentReader CreateVersionReader(BsonDocument document) private static BsonDocumentWriter CreateVersionWriter() { - var writer = new BsonDocumentWriter(new BsonDocument()); + var writer = new BsonDocumentWriter([]); writer.WriteStartDocument(); writer.WriteName("version"); return writer; diff --git a/Mongo.Migration.Tests/IntegrationTest.cs b/Mongo.Migration.Tests/IntegrationTest.cs index 518feab..00ce512 100644 --- a/Mongo.Migration.Tests/IntegrationTest.cs +++ b/Mongo.Migration.Tests/IntegrationTest.cs @@ -5,7 +5,7 @@ namespace Mongo.Migration.Tests; [TestFixture] -public class IntegrationTest +public abstract class IntegrationTest { private const string DatabaseName = "IntegrationTest"; private const string CollectionName = "Test"; diff --git a/Mongo.Migration.Tests/Migrations/Database/DatabaseIntegrationTest.cs b/Mongo.Migration.Tests/Migrations/Database/DatabaseIntegrationTest.cs index cecabb3..f1d6172 100644 --- a/Mongo.Migration.Tests/Migrations/Database/DatabaseIntegrationTest.cs +++ b/Mongo.Migration.Tests/Migrations/Database/DatabaseIntegrationTest.cs @@ -6,7 +6,7 @@ namespace Mongo.Migration.Tests.Migrations.Database; [TestFixture] -internal class DatabaseIntegrationTest +internal abstract class DatabaseIntegrationTest { private const string MigrationsCollectionName = "_migrations"; diff --git a/Mongo.Migration.Tests/Migrations/Database/DatabaseMigrationRunner_when_migrating_up.cs b/Mongo.Migration.Tests/Migrations/Database/DatabaseMigrationRunner_when_migrating_up.cs index 33ba1e5..bea4bd8 100644 --- a/Mongo.Migration.Tests/Migrations/Database/DatabaseMigrationRunner_when_migrating_up.cs +++ b/Mongo.Migration.Tests/Migrations/Database/DatabaseMigrationRunner_when_migrating_up.cs @@ -22,13 +22,13 @@ public async Task When_database_has_no_migrations_Then_all_migrations_are_used() // Assert var migrations = GetMigrationHistory(); - Assert.Multiple(() => + using (Assert.EnterMultipleScope()) { Assert.That(migrations, Is.Not.Empty); Assert.That(migrations[0].Version.ToString(), Is.EqualTo("0.0.1")); Assert.That(migrations[1].Version.ToString(), Is.EqualTo("0.0.2")); Assert.That(migrations[2].Version.ToString(), Is.EqualTo("0.0.3")); - }); + } } [Test] @@ -45,11 +45,11 @@ public async Task When_database_has_migrations_Then_latest_migrations_are_used() // Assert var migrations = GetMigrationHistory(); - Assert.Multiple(() => + using (Assert.EnterMultipleScope()) { Assert.That(migrations, Is.Not.Empty); Assert.That(migrations[2].Version.ToString(), Is.EqualTo("0.0.3")); - }); + } } [Test] @@ -71,12 +71,12 @@ public async Task When_database_has_latest_version_Then_nothing_happens() // Assert var migrations = GetMigrationHistory(); - Assert.Multiple(() => + using (Assert.EnterMultipleScope()) { Assert.That(migrations, Is.Not.Empty); Assert.That(migrations[0].Version.ToString(), Is.EqualTo("0.0.1")); Assert.That(migrations[1].Version.ToString(), Is.EqualTo("0.0.2")); Assert.That(migrations[2].Version.ToString(), Is.EqualTo("0.0.3")); - }); + } } } \ No newline at end of file diff --git a/Mongo.Migration.Tests/Migrations/Document/DocumentMigrationRunner_when_migrating_down.cs b/Mongo.Migration.Tests/Migrations/Document/DocumentMigrationRunner_when_migrating_down.cs index 9c218a7..ce7ed76 100644 --- a/Mongo.Migration.Tests/Migrations/Document/DocumentMigrationRunner_when_migrating_down.cs +++ b/Mongo.Migration.Tests/Migrations/Document/DocumentMigrationRunner_when_migrating_down.cs @@ -24,11 +24,11 @@ public void When_migrating_down_Then_all_migrations_are_used() runner.Run(typeof(TestDocumentWithTwoMigration), document); // Assert - Assert.Multiple(() => + using (Assert.EnterMultipleScope()) { Assert.That(document.Names.ToList()[1], Is.EqualTo("Dors")); Assert.That(document.Values.ToList()[0].AsString, Is.EqualTo("0.0.0")); - }); + } } [Test] @@ -46,10 +46,10 @@ public void When_document_has_Then_all_migrations_are_used_to_that_version() runner.Run(typeof(TestDocumentWithTwoMigrationMiddleVersion), document); // Assert - Assert.Multiple(() => + using (Assert.EnterMultipleScope()) { Assert.That(document.Names.ToList()[1], Is.EqualTo("Doors1")); Assert.That(document.Values.ToList()[0].AsString, Is.EqualTo("0.0.1")); - }); + } } } \ No newline at end of file diff --git a/Mongo.Migration.Tests/Migrations/Document/DocumentMigrationRunner_when_migrating_up.cs b/Mongo.Migration.Tests/Migrations/Document/DocumentMigrationRunner_when_migrating_up.cs index a6eced9..1d775b0 100644 --- a/Mongo.Migration.Tests/Migrations/Document/DocumentMigrationRunner_when_migrating_up.cs +++ b/Mongo.Migration.Tests/Migrations/Document/DocumentMigrationRunner_when_migrating_up.cs @@ -24,11 +24,11 @@ public void When_migrate_up_the_lowest_version_Then_all_migrations_are_used() runner.Run(typeof(TestDocumentWithTwoMigrationHighestVersion), document); // Assert - Assert.Multiple(() => + using (Assert.EnterMultipleScope()) { Assert.That(document.Names.ToList()[1], Is.EqualTo("Door")); Assert.That(document.Values.ToList()[0].AsString, Is.EqualTo("0.0.2")); - }); + } } [Test] @@ -45,11 +45,11 @@ public void When_document_has_no_version_Then_all_migrations_are_used() runner.Run(typeof(TestDocumentWithTwoMigrationHighestVersion), document); // Assert - Assert.Multiple(() => + using (Assert.EnterMultipleScope()) { Assert.That(document["Door"].AsInt32, Is.EqualTo(3)); Assert.That(document["Version"].AsString, Is.EqualTo("0.0.2")); - }); + } } [Test] @@ -67,10 +67,10 @@ public void When_document_has_current_version_Then_nothing_happens() runner.Run(typeof(TestDocumentWithTwoMigrationHighestVersion), document); // Assert - Assert.Multiple(() => + using (Assert.EnterMultipleScope()) { Assert.That(document.Names.ToList()[1], Is.EqualTo("Door")); Assert.That(document.Values.ToList()[0].AsString, Is.EqualTo("0.0.2")); - }); + } } } \ No newline at end of file diff --git a/Mongo.Migration.Tests/Migrations/Document/DocumentMigration_when_creating.cs b/Mongo.Migration.Tests/Migrations/Document/DocumentMigration_when_creating.cs index 9acc13c..d32c488 100644 --- a/Mongo.Migration.Tests/Migrations/Document/DocumentMigration_when_creating.cs +++ b/Mongo.Migration.Tests/Migrations/Document/DocumentMigration_when_creating.cs @@ -33,6 +33,6 @@ public void Then_migration_should_be_created() var migration = new TestDocumentWithOneMigration001(); // Assert - Assert.That(migration, Is.TypeOf(typeof(TestDocumentWithOneMigration001))); + Assert.That(migration, Is.TypeOf()); } } \ No newline at end of file diff --git a/Mongo.Migration.Tests/Migrations/Interceptor/InterceptorTests.cs b/Mongo.Migration.Tests/Migrations/Interceptor/InterceptorTests.cs index 31f2e2d..36442e1 100644 --- a/Mongo.Migration.Tests/Migrations/Interceptor/InterceptorTests.cs +++ b/Mongo.Migration.Tests/Migrations/Interceptor/InterceptorTests.cs @@ -38,45 +38,41 @@ public async Task TestDeserializationIntercepted() IMongoCollection testDocumentCollection = GetCollection(); - await untypedCollection.InsertManyAsync(new[] - { - new BsonDocument - { + await untypedCollection.InsertManyAsync( + [ + [ new("Doors0", new BsonInt32(0)) - }, - new BsonDocument - { + ], + [ new("Doors0", new BsonInt32(1)), new("Version", new BsonString("0.0.0")) - }, - new BsonDocument - { + ], + [ new("Doors1", new BsonInt32(2)), new("Version", new BsonString("0.0.1")) - }, - new BsonDocument - { + ], + [ new("Doors2", new BsonInt32(3)), new("Version", new BsonString("0.0.2")) - } - }); + ] + ]); var asyncCursor = await testDocumentCollection .FindAsync(FilterDefinition.Empty); List documents = await asyncCursor.ToListAsync(); - Assert.Multiple(() => + using (Assert.EnterMultipleScope()) { Assert.That(documents, Has.Count.EqualTo(4)); Assert.That( documents.Select(d => d.Version.ToString()), Is.All.EqualTo("0.0.1")); - Assert.That(documents[0].Doors1, Is.EqualTo(0)); + Assert.That(documents[0].Doors1, Is.Zero); Assert.That(documents[1].Doors1, Is.EqualTo(1)); Assert.That(documents[2].Doors1, Is.EqualTo(2)); Assert.That(documents[3].Doors1, Is.EqualTo(3)); - }); + } } [Test] @@ -106,45 +102,41 @@ public async Task TestDeserializationVersionAsStringIntercepted() IMongoCollection testDocumentCollection = GetCollection(); - await untypedCollection.InsertManyAsync(new[] - { - new BsonDocument - { + await untypedCollection.InsertManyAsync( + [ + [ new("Doors0", new BsonInt32(0)) - }, - new BsonDocument - { + ], + [ new("Doors0", new BsonInt32(1)), new("Version", new BsonString("0.0.0")) - }, - new BsonDocument - { + ], + [ new("Doors1", new BsonInt32(2)), new("Version", new BsonString("0.0.1")) - }, - new BsonDocument - { + ], + [ new("Doors2", new BsonInt32(3)), new("Version", new BsonString("0.0.2")) - } - }); + ] + ]); var asyncCursor = await testDocumentCollection .FindAsync(FilterDefinition.Empty); List documents = await asyncCursor.ToListAsync(); - Assert.Multiple(() => + using (Assert.EnterMultipleScope()) { Assert.That(documents, Has.Count.EqualTo(4)); Assert.That( documents.Select(d => d.Version.ToString()), Is.All.EqualTo("0.0.1")); - Assert.That(documents[0].Doors1, Is.EqualTo(0)); + Assert.That(documents[0].Doors1, Is.Zero); Assert.That(documents[1].Doors1, Is.EqualTo(1)); Assert.That(documents[2].Doors1, Is.EqualTo(2)); Assert.That(documents[3].Doors1, Is.EqualTo(3)); - }); + } } diff --git a/Mongo.Migration.Tests/Mongo.Migration.Tests.csproj b/Mongo.Migration.Tests/Mongo.Migration.Tests.csproj index e99abf9..706aaf7 100644 --- a/Mongo.Migration.Tests/Mongo.Migration.Tests.csproj +++ b/Mongo.Migration.Tests/Mongo.Migration.Tests.csproj @@ -1,8 +1,8 @@  - net8.0;net9.0 - 13.0 + net10.0;net9.0;net8.0 + 14.0 enable enable false @@ -17,16 +17,16 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/Mongo.Migration.Tests/MongoDB/VariousCrudOperations.cs b/Mongo.Migration.Tests/MongoDB/VariousCrudOperations.cs index 9a8386c..9e1a044 100644 --- a/Mongo.Migration.Tests/MongoDB/VariousCrudOperations.cs +++ b/Mongo.Migration.Tests/MongoDB/VariousCrudOperations.cs @@ -62,8 +62,11 @@ public async Task TestRead() .Where(d => d.Doors >= 98) .Single(); - Assert.That(documentById.Id, Is.EqualTo(id)); - Assert.That(documentByExpression.Id, Is.EqualTo(id)); + using (Assert.EnterMultipleScope()) + { + Assert.That(documentById.Id, Is.EqualTo(id)); + Assert.That(documentByExpression.Id, Is.EqualTo(id)); + } } [Test] @@ -95,8 +98,11 @@ public async Task TestUpdate() .Where(d => d.Id == id) .Single(); - Assert.That(documentUpdated.Id, Is.EqualTo(id)); - Assert.That(documentUpdated.Doors, Is.EqualTo(8)); + using (Assert.EnterMultipleScope()) + { + Assert.That(documentUpdated.Id, Is.EqualTo(id)); + Assert.That(documentUpdated.Doors, Is.EqualTo(8)); + } } [Test] diff --git a/Mongo.Migration.Tests/Performance/PerformanceOnStartup.cs b/Mongo.Migration.Tests/Performance/PerformanceOnStartup.cs index bcb45ce..7581fbc 100644 --- a/Mongo.Migration.Tests/Performance/PerformanceOnStartup.cs +++ b/Mongo.Migration.Tests/Performance/PerformanceOnStartup.cs @@ -85,13 +85,13 @@ private static async Task> QueryAllAsync(bool withVersion) var versionedCollection = client.GetDatabase(DatabaseName) .GetCollection(CollectionName); var versionedResult = await (await versionedCollection.FindAsync(_ => true)).ToListAsync(); - return versionedResult.Cast().ToList(); + return [.. versionedResult.Cast()]; } var collection = client.GetDatabase(DatabaseName) .GetCollection(CollectionName); var result = await (await collection.FindAsync(_ => true)).ToListAsync(); - return result.Cast().ToList(); + return [.. result.Cast()]; } private static async Task AddDocumentsToCacheAsync() diff --git a/Mongo.Migration.Tests/Services/Interceptors/MigrationInterceptorFactory_when_creating.cs b/Mongo.Migration.Tests/Services/Interceptors/MigrationInterceptorFactory_when_creating.cs index 779bd08..1bf0cc3 100644 --- a/Mongo.Migration.Tests/Services/Interceptors/MigrationInterceptorFactory_when_creating.cs +++ b/Mongo.Migration.Tests/Services/Interceptors/MigrationInterceptorFactory_when_creating.cs @@ -19,7 +19,7 @@ public void If_type_is_assignable_to_document_Then_interceptor_is_created() IBsonSerializer serializer = serializerProvider.GetSerializer(typeof(TestDocumentWithOneMigration)); // Assert - Assert.That(serializer, Is.TypeOf(typeof(MigrationDocumentSerializer))); + Assert.That(serializer, Is.TypeOf>()); } [Test] @@ -45,6 +45,6 @@ public void If_type_is_not_assignable_to_document_but_manually_added_Then_interc IBsonSerializer serializer = serializerProvider.GetSerializer(typeof(TestClassWithTwoMigrationMiddleVersion)); // Assert - Assert.That(serializer, Is.TypeOf(typeof(MigrationReflexionSerializer))); + Assert.That(serializer, Is.TypeOf>()); } } \ No newline at end of file diff --git a/Mongo.Migration.Tests/Startup/MigrationBuilderTests.cs b/Mongo.Migration.Tests/Startup/MigrationBuilderTests.cs index 22948bb..ae22427 100644 --- a/Mongo.Migration.Tests/Startup/MigrationBuilderTests.cs +++ b/Mongo.Migration.Tests/Startup/MigrationBuilderTests.cs @@ -26,12 +26,12 @@ public void AllMigrationsEnabledWhenNotSet() MongoMigrationStartupSettings startupSettings = provider.GetRequiredService(); - Assert.Multiple(() => + using (Assert.EnterMultipleScope()) { Assert.That(startupSettings.RuntimeMigrationEnabled, Is.True); Assert.That(startupSettings.DatabaseMigrationEnabled, Is.True); Assert.That(startupSettings.StartupDocumentMigrationEnabled, Is.True); - }); + } } [Test] @@ -45,7 +45,7 @@ public void RuntimeMigrationOnlyRequiredRegistered() MongoMigrationStartupSettings startupSettings = provider.GetRequiredService(); - Assert.Multiple(() => + using (Assert.EnterMultipleScope()) { Assert.That(startupSettings.RuntimeMigrationEnabled, Is.True); Assert.That(startupSettings.DatabaseMigrationEnabled, Is.False); @@ -57,7 +57,7 @@ public void RuntimeMigrationOnlyRequiredRegistered() Assert.Throws(() => provider.GetRequiredService()); Assert.Throws(() => provider.GetRequiredService()); Assert.Throws(() => provider.GetRequiredService()); - }); + } } [Test] @@ -71,7 +71,7 @@ public void DatabaseMigrationOnlyRequiredRegistered() MongoMigrationStartupSettings startupSettings = provider.GetRequiredService(); - Assert.Multiple(() => + using (Assert.EnterMultipleScope()) { Assert.That(startupSettings.RuntimeMigrationEnabled, Is.False); Assert.That(startupSettings.DatabaseMigrationEnabled, Is.True); @@ -87,7 +87,7 @@ public void DatabaseMigrationOnlyRequiredRegistered() Assert.Throws(() => provider.GetRequiredService()); Assert.Throws(() => provider.GetRequiredService()); Assert.Throws(() => provider.GetRequiredService()); - }); + } } [Test] @@ -101,7 +101,7 @@ public void DocumentStartupMigrationOnlyRequiredRegistered() MongoMigrationStartupSettings startupSettings = provider.GetRequiredService(); - Assert.Multiple(() => + using (Assert.EnterMultipleScope()) { Assert.That(startupSettings.RuntimeMigrationEnabled, Is.False); Assert.That(startupSettings.DatabaseMigrationEnabled, Is.False); @@ -116,7 +116,7 @@ public void DocumentStartupMigrationOnlyRequiredRegistered() Assert.Throws(() => provider.GetRequiredService()); Assert.Throws(() => provider.GetRequiredService()); - }); + } } private static IServiceCollection CreateEmptyServiceCollection() diff --git a/Mongo.Migration.Tests/TestcontainersContext.cs b/Mongo.Migration.Tests/TestcontainersContext.cs index fe3db24..249684a 100644 --- a/Mongo.Migration.Tests/TestcontainersContext.cs +++ b/Mongo.Migration.Tests/TestcontainersContext.cs @@ -13,9 +13,7 @@ namespace Mongo.Migration.Tests; [SetUpFixture] public sealed class TestcontainersContext { - private static readonly Lazy s_lazyMongoDbContainer = new(() => - new MongoDbBuilder().Build() - ); + private static readonly Lazy s_lazyMongoDbContainer = new(() => new MongoDbBuilder("mongo:8").Build()); private static ServiceProvider? s_provider; diff --git a/Mongo.Migration.sln b/Mongo.Migration.sln deleted file mode 100644 index b4a4326..0000000 --- a/Mongo.Migration.sln +++ /dev/null @@ -1,44 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.4.33122.133 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Git", "Git", "{CB26356F-6A6A-4B13-BD95-672A8AF24518}" - ProjectSection(SolutionItems) = preProject - .gitignore = .gitignore - LICENSE.txt = LICENSE.txt - Readme.md = Readme.md - EndProjectSection -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{E7B1F839-44B5-46BE-9CAB-AEBC376EB100}" - ProjectSection(SolutionItems) = preProject - .github\workflows\build.yaml = .github\workflows\build.yaml - .github\workflows\publish.yaml = .github\workflows\publish.yaml - EndProjectSection -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mongo.Migration", "Mongo.Migration\Mongo.Migration.csproj", "{8DFFD615-1E1A-4BED-8A96-CAF4C3637E81}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mongo.Migration.Tests", "Mongo.Migration.Tests\Mongo.Migration.Tests.csproj", "{1EEC8464-61D1-4FA3-97D4-21A35A45F3FE}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {8DFFD615-1E1A-4BED-8A96-CAF4C3637E81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8DFFD615-1E1A-4BED-8A96-CAF4C3637E81}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8DFFD615-1E1A-4BED-8A96-CAF4C3637E81}.Release|Any CPU.ActiveCfg = Debug|Any CPU - {8DFFD615-1E1A-4BED-8A96-CAF4C3637E81}.Release|Any CPU.Build.0 = Debug|Any CPU - {1EEC8464-61D1-4FA3-97D4-21A35A45F3FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1EEC8464-61D1-4FA3-97D4-21A35A45F3FE}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1EEC8464-61D1-4FA3-97D4-21A35A45F3FE}.Release|Any CPU.ActiveCfg = Debug|Any CPU - {1EEC8464-61D1-4FA3-97D4-21A35A45F3FE}.Release|Any CPU.Build.0 = Debug|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {141CC212-9A27-4082-94E7-A80340DFDF4C} - EndGlobalSection -EndGlobal diff --git a/Mongo.Migration.slnx b/Mongo.Migration.slnx new file mode 100644 index 0000000..13f16be --- /dev/null +++ b/Mongo.Migration.slnx @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/Mongo.Migration/Mongo.Migration.csproj b/Mongo.Migration/Mongo.Migration.csproj index e16246d..9b6d526 100644 --- a/Mongo.Migration/Mongo.Migration.csproj +++ b/Mongo.Migration/Mongo.Migration.csproj @@ -1,8 +1,8 @@  - net8.0;net9.0 - 13.0 + net10.0;net9.0;net8.0 + 14.0 enable enable embedded @@ -25,7 +25,7 @@ - + diff --git a/Mongo.Migration/Startup/MongoMigrationConfigurator.cs b/Mongo.Migration/Startup/MongoMigrationConfigurator.cs index fabf142..1be0f20 100644 --- a/Mongo.Migration/Startup/MongoMigrationConfigurator.cs +++ b/Mongo.Migration/Startup/MongoMigrationConfigurator.cs @@ -15,7 +15,7 @@ internal MongoMigrationConfigurator() { MongoMigrationSettings = new MongoMigrationSettings(); MongoMigrationStartupSettings = new MongoMigrationStartupSettings(); - RuntimeMigrationDictionary = new Dictionary(); + RuntimeMigrationDictionary = []; } public MongoMigrationConfigurator SetVersionFieldName(string fieldName) diff --git a/README.md b/README.md index 112c9be..19431cf 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -![GitHub License](https://img.shields.io/github/license/rpallares/Mongo.Migration) -![NuGet Downloads](https://img.shields.io/nuget/dt/Mongo.RuntimeMigration) -![NuGet](https://img.shields.io/nuget/v/Mongo.RuntimeMigration) -![GitHub last commit](https://img.shields.io/github/last-commit/rpallares/Mongo.Migration) +[![GitHub License](https://img.shields.io/github/license/rpallares/Mongo.Migration)]() +[![NuGet Downloads](https://img.shields.io/nuget/dt/Mongo.RuntimeMigration)](https://www.nuget.org/packages/Mongo.RuntimeMigration/) +[![NuGet](https://img.shields.io/nuget/v/Mongo.RuntimeMigration)](https://www.nuget.org/packages/Mongo.RuntimeMigration/) +[![GitHub last commit](https://img.shields.io/github/last-commit/rpallares/Mongo.Migration)](https://github.com/rpallares/Mongo.Migration/commits/master/) # Mongo.RuntimeMigration @@ -10,9 +10,10 @@ Mongo.RuntimeMigration is designed for the [MongoDB C# Driver](https://github.com/mongodb/mongo-csharp-driver) to migrate your documents easily and on-the-fly. No more downtime for schema-migrations. Just write small and simple `migrations`. -Version 5.0.0 of Mongo.RuntimeMigration is a code modernization and simplification release. It also has a strong focus on performance. +Version Mongo.RuntimeMigration is a code modernization and simplification release of [SRoddis/Mongo.Migration](https://github.com/SRoddis/Mongo.Migration). It also has a strong focus on performance. + +The library is still based on the official [MongoDB.Driver](https://www.mongodb.com/docs/drivers/csharp/) (3.5.2+) and supports the following 3 types of migration: -The library is still based on the official [MongoDB.Driver](https://www.mongodb.com/docs/drivers/csharp/) (3.0.0+) and supports the following 3 types of migration: - **Runtime document migration:** This kind of migration is executed at serialization/deserialization process. It allows your application to consume data serialized at another version - **Startup document migration:** @@ -21,19 +22,19 @@ The library is still based on the official [MongoDB.Driver](https://www.mongodb. - **Database migration:** This kind of migration give access to the entire database and allows to write much faster migrations. They also allow to manage indexes, rights, or any other maintenance of the database. -**Notes:** -A robust application will probably use two kind of migrations. +**Notes:** A robust application will probably use two kind of migrations. + - The database migration executed by the continuous integration - The runtime document migration executed by the runtime to prevent any error during the database migration # Installation -Install via nuget https://www.nuget.org/packages/Mongo.RuntimeMigration -**Note:** The package isn't maintained since a while, so for now it's preferable to compile it locally +Install via nuget [Mongo.RuntimeMigration](https://www.nuget.org/packages/Mongo.RuntimeMigration): ```shell dotnet add package Mongo.RuntimeMigration ``` + # Register migration services ```c# @@ -53,6 +54,7 @@ services ``` # Execute migrations + ```c# IServiceProvider provider = services.BuildServiceProvider(); @@ -113,13 +115,13 @@ You can still execute them at startup to migrate your database but this **is not } } ``` -3`(Optional)` If you choose to put your migrations into an extra project, +3. `(Optional)` If you choose to put your migrations into an extra project, add the suffix `".MongoMigrations"` to the name and make sure it is referenced in the main project. By convention Mongo.RuntimeMigration collects all .dlls named like that in your bin folder. Compile, run and enjoy! - # Database migrations quick start + Database migrations are very efficient to migrate large volume of data, and it allows to manage indexes or whatever you need. Here are some tips to implement your migrations: - Do not create transactions @@ -169,6 +171,7 @@ Here are some tips to implement your migrations: # Attributes ## RuntimeVersion + Add `RuntimeVersion` attribute to mark the current version of the document. So you have the possibility to downgrade in case of a rollback. If you do not set the `RuntimeVersion`, all migrations will be applied. @@ -215,19 +218,19 @@ Performance is also measured manually for runtime migration which has benefited Example output of the automated test: ```bash vanilla -- 1_000 => 15 ms -- 10_000 => 45 ms -- 50_000 => 168 ms +- 1_000 => 19 ms +- 10_000 => 38 ms +- 50_000 => 159 ms no migration: -- 1_000 => 13 ms -- 10_000 => 77 ms -- 50_000 => 157 ms +- 1_000 => 30 ms +- 10_000 => 95 ms +- 50_000 => 175 ms 2 migrations: -- 1_000 => 34 ms -- 10_000 => 258 ms -- 50_000 => 883 ms +- 1_000 => 68 ms +- 10_000 => 196 ms +- 50_000 => 768 ms ``` **Note:** These performance tests are not benchmark and results could vary. @@ -235,6 +238,13 @@ They should rely on BenchMarkDotNet and use in memory streams instead of mongo d # Release notes +## v5.1.0 +This version mostly introduce .Net 10 support. + +### Updates +- .Net version update (.net10.0, .net9.0, .net8.0) +- MongoDB.Driver@3.5.2 (required for .Net 10) + ## v5.0.0 This could be not 100% exhaustive but v5.0.0 did a lot of changes comparing to older versions. Consider also there was a lot of changes between the last 3.1.4 officially published version and the source code. @@ -265,11 +275,11 @@ Consider also there was a lot of changes between the last 3.1.4 officially publi # Next Feature/Todo 1. Create startup setting to limit database migrations ran at startup on fresh database -2. Remove .net7_0 support +2. Add real benchmark for runtime migrations # License -Mongo.RuntimeMigration is licensed under [MIT](http://www.opensource.org/licenses/mit-license.php "Read more about the MIT license form"). Refer to license.txt for more information. +Mongo.RuntimeMigration is licensed under [MIT](http://www.opensource.org/licenses/mit-license.php "Read more about the MIT license form"). Refer to [LICENSE.md](LICENSE.md) for more information. It has been forked from [SRoddis/Mongo.Migration](https://github.com/SRoddis/Mongo.Migration) that is no longer maintained. That's why the nuget name is `Mongo.RuntimeMigration` whereas namespace is still `Mongo.Migration`. -Thanks to SRoddis for that library. +Thanks to @SRoddis for that library. diff --git a/global.json b/global.json index 3f285f0..11fd6aa 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,9 @@ { "sdk": { - "rollForward": "feature", - "version": "9.0.103" + "version": "10.0.101", + "rollForward": "latestMajor" + }, + "test": { + "runner": "Microsoft.Testing.Platform" } } \ No newline at end of file