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
(cherry picked from commit d0cd22b09d)
This commit is contained in:
committed by
Bjarke Berg
parent
8ffddb77ff
commit
b8a1c42660
@@ -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();
|
||||
|
||||
@@ -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:
|
||||
|
||||
21
src/Umbraco.Cms.Persistence.EFCore/StringExtensions.cs
Normal file
21
src/Umbraco.Cms.Persistence.EFCore/StringExtensions.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user