You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I run the app, nothing happens. No MigrationService gets instantiated and nothing runs. So what's the trigger to get this to work? I do have a bunch of public classes that derive from DatabaseMigration in my namespace (MyNamespace.Migrations to be precise). I do not have any Tags (CollectionLocation, StartupVersion, RuntimeVersion) in my model yet, since I only run collection level updates.
I then build the lib from the source, exposing MigrationService as public, then instantiating an IMigrationService manually after building the host:
var migrator = host.Services.GetRequiredService<IMigrationService>();
Now I get things rolling, but it's not really the way it's meant to be used, is it? Plus, this then throws a MongoMigrationNoMongoClientException in the StartUpDocumentMigrationRunner constructor since settings.ClientSettings is null. And looking at the code, either the documentation is wrong and clientSettings is mandatory when not re-using the IMongoClient, or the code is wrong (imho):
if (settings.ConnectionString == null && settings.Database == null || settings.ClientSettings == null)
{
throw new MongoMigrationNoMongoClientException();
}
if (settings.ClientSettings != null)
{
this._client = new MongoClient(settings.ClientSettings);
}
else
{
this._client = new MongoClient(settings.ConnectionString);
}
this._databaseName = settings.Database;
Shouldn't it be 'if there's no Database => throw, if there's no ConnectionString and no ClientSettings => throw. If there's either a ConnectionString or ClientSettings, use it to instantiate the new MongoClient, and thus the code should look like:
if ((settings.ConnectionString == null && settings.ClientSettings == null) && settings.Database == null)
{
throw new MongoMigrationNoMongoClientException();
}
if (settings.ClientSettings != null)
{
this._client = new MongoClient(settings.ClientSettings);
}
else
{
this._client = new MongoClient(settings.ConnectionString);
}
this._databaseName = settings.Database;
The text was updated successfully, but these errors were encountered:
so I managed to find the right approach (I hope). It seems IMongoMigration is the interface I want. Thus, running the migrations would entail
using IHost host = builder.Build();
var migration = host.Services.GetRequiredService<IMongoMigration>();
migration.Run();
that works without having to expose any classes/interfaces. Still, the problem with the ConnectionString and ClientSettings persists when you're not reusing the MongoClient.
I'm building a proof of concept project in .NET 8.
When I run the app, nothing happens. No
MigrationService
gets instantiated and nothing runs. So what's the trigger to get this to work? I do have a bunch of public classes that derive fromDatabaseMigration
in my namespace (MyNamespace.Migrations to be precise). I do not have any Tags (CollectionLocation
,StartupVersion
,RuntimeVersion
) in my model yet, since I only run collection level updates.I then build the lib from the source, exposing
MigrationService
as public, then instantiating anIMigrationService
manually after building the host:var migrator = host.Services.GetRequiredService<IMigrationService>();
Now I get things rolling, but it's not really the way it's meant to be used, is it? Plus, this then throws a
MongoMigrationNoMongoClientException
in theStartUpDocumentMigrationRunner
constructor sincesettings.ClientSettings
is null. And looking at the code, either the documentation is wrong and clientSettings is mandatory when not re-using the IMongoClient, or the code is wrong (imho):Shouldn't it be 'if there's no Database => throw, if there's no ConnectionString and no ClientSettings => throw. If there's either a ConnectionString or ClientSettings, use it to instantiate the new MongoClient, and thus the code should look like:
The text was updated successfully, but these errors were encountered: