Files
Umbraco-CMS/src/Umbraco.Infrastructure/Migrations/MigrationContext.cs
Bjarke Berg 9e4dead0f5 Merge remote-tracking branch 'origin/v9/dev' into v9/task/package-refactor
# Conflicts:
#	src/Umbraco.Core/Migrations/IMigration.cs
#	src/Umbraco.Core/Migrations/MigrationPlan.cs
#	src/Umbraco.Infrastructure/Migrations/IMigrationContext.cs
#	src/Umbraco.Infrastructure/Runtime/RuntimeState.cs
#	src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/MigrationTests.cs
#	src/Umbraco.Web.UI.NetCore/umbraco/config/lang/en.xml
#	src/Umbraco.Web.UI.NetCore/umbraco/config/lang/en_us.xml
2021-06-29 14:23:08 +02:00

55 lines
1.7 KiB
C#

using System;
using System.Collections.Generic;
using Microsoft.Extensions.Logging;
using Umbraco.Cms.Infrastructure.Persistence;
namespace Umbraco.Cms.Infrastructure.Migrations
{
/// <summary>
/// Implements <see cref="IMigrationContext"/>.
/// </summary>
internal class MigrationContext : IMigrationContext
{
private readonly List<Type> _postMigrations = new List<Type>();
/// <summary>
/// Initializes a new instance of the <see cref="MigrationContext"/> class.
/// </summary>
public MigrationContext(MigrationPlan plan, IUmbracoDatabase database, ILogger<MigrationContext> logger)
{
Plan = plan;
Database = database ?? throw new ArgumentNullException(nameof(database));
Logger = logger ?? throw new ArgumentNullException(nameof(logger));
_postMigrations.AddRange(plan.PostMigrationTypes);
}
/// <inheritdoc />
public ILogger<IMigrationContext> Logger { get; }
public MigrationPlan Plan { get; }
/// <inheritdoc />
public IUmbracoDatabase Database { get; }
/// <inheritdoc />
public ISqlContext SqlContext => Database.SqlContext;
/// <inheritdoc />
public int Index { get; set; }
/// <inheritdoc />
public bool BuildingExpression { get; set; }
// this is only internally exposed
public IReadOnlyList<Type> PostMigrations => _postMigrations;
/// <inheritdoc />
public void AddPostMigration<TMigration>()
where TMigration : MigrationBase
{
// just adding - will be de-duplicated when executing
_postMigrations.Add(typeof(TMigration));
}
}
}