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