Files
Umbraco-CMS/src/Umbraco.Cms.Persistence.EFCore.SqlServer/SqlServerMigrationProvider.cs
Bjarke Berg fcda25af50 Premigrations + Updated NuGet Dependencies (#15987)
* Updated nuget packages + added migrations for OpenIddict - Currently can only be executed using unatttended installs

* Added new Premigration concept - Migrations that always runs unattended before other migrations

* Apply suggestions from code review

Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com>

---------

Co-authored-by: Zeegaan <skrivdetud@gmail.com>
Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com>
2024-04-10 12:30:30 +02:00

37 lines
1.4 KiB
C#

using Microsoft.EntityFrameworkCore;
using Umbraco.Cms.Core;
using Umbraco.Cms.Persistence.EFCore.Migrations;
using Umbraco.Extensions;
namespace Umbraco.Cms.Persistence.EFCore.SqlServer;
public class SqlServerMigrationProvider : IMigrationProvider
{
private readonly IDbContextFactory<UmbracoDbContext> _dbContextFactory;
public SqlServerMigrationProvider(IDbContextFactory<UmbracoDbContext> dbContextFactory) => _dbContextFactory = dbContextFactory;
public string ProviderName => Constants.ProviderNames.SQLServer;
public async Task MigrateAsync(EFCoreMigration migration)
{
UmbracoDbContext context = await _dbContextFactory.CreateDbContextAsync();
await context.MigrateDatabaseAsync(GetMigrationType(migration));
}
public async Task MigrateAllAsync()
{
UmbracoDbContext context = await _dbContextFactory.CreateDbContextAsync();
await context.Database.MigrateAsync();
}
private static Type GetMigrationType(EFCoreMigration migration) =>
migration switch
{
EFCoreMigration.InitialCreate => typeof(Migrations.InitialCreate),
EFCoreMigration.AddOpenIddict => typeof(Migrations.AddOpenIddict),
EFCoreMigration.UpdateOpenIddictToV5 => typeof(Migrations.UpdateOpenIddictToV5),
_ => throw new ArgumentOutOfRangeException(nameof(migration), $@"Not expected migration value: {migration}")
};
}