V12 Bugfix, Added compare provider name extension for Sqlite (#15189)

* Created an extension for comparing the current and the outdated providerName for Sqlite

* Added usages for the CompareProviderNames

* Added another case if the providerName is the outdated SQLite

* Both cases use Sqlite, so there is no need to have duplicate code
This commit is contained in:
Andreas Zerbst
2023-11-14 20:38:18 +01:00
committed by GitHub
parent 46d5db51e8
commit d0cd22b09d
4 changed files with 25 additions and 4 deletions

View File

@@ -21,7 +21,7 @@ public class EfCoreMigrationExecutor : IEFCoreMigrationExecutor
public async Task ExecuteSingleMigrationAsync(EFCoreMigration migration)
{
IMigrationProvider? provider = _migrationProviders.FirstOrDefault(x => x.ProviderName == _options.Value.ProviderName);
IMigrationProvider? provider = _migrationProviders.FirstOrDefault(x => x.ProviderName.CompareProviderNames(_options.Value.ProviderName));
if (provider is not null)
{
@@ -31,8 +31,7 @@ public class EfCoreMigrationExecutor : IEFCoreMigrationExecutor
public async Task ExecuteAllMigrationsAsync()
{
IMigrationProvider? provider = _migrationProviders.FirstOrDefault(x => x.ProviderName == _options.Value.ProviderName);
IMigrationProvider? provider = _migrationProviders.FirstOrDefault(x => x.ProviderName.CompareProviderNames(_options.Value.ProviderName));
if (provider is not null)
{
await provider.MigrateAllAsync();

View File

@@ -136,6 +136,7 @@ public static class UmbracoEFCoreServiceCollectionExtensions
builder.UseSqlServer(connectionString);
break;
case Constants.ProviderNames.SQLLite:
case "Microsoft.Data.SQLite":
builder.UseSqlite(connectionString);
break;
default:

View File

@@ -0,0 +1,21 @@
using Umbraco.Cms.Core;
namespace Umbraco.Cms.Persistence.EFCore;
internal static class StringExtensions
{
internal static bool CompareProviderNames(this string connectionProvider, string? compareString)
{
if (compareString is null)
{
return false;
}
if (connectionProvider == compareString)
{
return true;
}
return connectionProvider is "Microsoft.Data.SQLite" or Constants.ProviderNames.SQLLite && compareString is "Microsoft.Data.SQLite" or Constants.ProviderNames.SQLLite;
}
}

View File

@@ -58,7 +58,7 @@ public class UmbracoDbContext : DbContext
}
IEnumerable<IMigrationProviderSetup> migrationProviders = StaticServiceProvider.Instance.GetServices<IMigrationProviderSetup>();
IMigrationProviderSetup? migrationProvider = migrationProviders.FirstOrDefault(x => x.ProviderName == connectionStrings.ProviderName);
IMigrationProviderSetup? migrationProvider = migrationProviders.FirstOrDefault(x => x.ProviderName.CompareProviderNames(connectionStrings.ProviderName));
if (migrationProvider == null && connectionStrings.ProviderName != null)
{