Files
Umbraco-CMS/src/Umbraco.Infrastructure/Migrations/MigrationContext.cs

55 lines
1.7 KiB
C#
Raw Normal View History

using System;
2019-02-13 09:53:17 +01:00
using System.Collections.Generic;
2020-09-17 13:36:26 +02:00
using Microsoft.Extensions.Logging;
using Umbraco.Cms.Infrastructure.Persistence;
namespace Umbraco.Cms.Infrastructure.Migrations
{
2018-11-15 19:34:32 +01:00
/// <summary>
2019-02-13 09:53:17 +01:00
/// Implements <see cref="IMigrationContext"/>.
2018-11-15 19:34:32 +01:00
/// </summary>
internal class MigrationContext : IMigrationContext
{
private readonly List<Type> _postMigrations = new List<Type>();
2018-11-15 19:34:32 +01:00
/// <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);
}
2018-11-15 19:34:32 +01:00
/// <inheritdoc />
2020-09-17 13:36:26 +02:00
public ILogger<IMigrationContext> Logger { get; }
public MigrationPlan Plan { get; }
2018-11-15 19:34:32 +01:00
/// <inheritdoc />
public IUmbracoDatabase Database { get; }
2018-11-15 19:34:32 +01:00
/// <inheritdoc />
public ISqlContext SqlContext => Database.SqlContext;
2018-11-15 19:34:32 +01:00
/// <inheritdoc />
public int Index { get; set; }
2018-11-15 19:34:32 +01:00
/// <inheritdoc />
public bool BuildingExpression { get; set; }
2019-02-13 09:53:17 +01:00
2019-02-13 10:14:01 +01:00
// this is only internally exposed
public IReadOnlyList<Type> PostMigrations => _postMigrations;
2019-02-13 10:14:01 +01:00
/// <inheritdoc />
public void AddPostMigration<TMigration>()
where TMigration : MigrationBase
2019-02-13 10:14:01 +01:00
{
2019-05-07 19:28:51 +02:00
// just adding - will be de-duplicated when executing
_postMigrations.Add(typeof(TMigration));
2019-02-13 10:14:01 +01:00
}
}
}