Skip to content

Commit

Permalink
Merge pull request #7 from NikRimington/feature/legacy-data-migration
Browse files Browse the repository at this point in the history
[IMPLEMENT] Migration to move over legacy config to new config
  • Loading branch information
NikRimington authored Sep 15, 2021
2 parents 2cc7b79 + ee15d13 commit 015ea26
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/HC.PageNotFoundManager.Core/Migrations/InitialMigration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,33 @@ protected override void Migrate()
}
}

public class PageNotFoundMigrationPlan : MigrationPlan
public class MigrateV8DataMigration : MigrationBase
{
public const string MigrationName = "page-not-found-manager-migration-legacy-data";
private readonly ILogger<MigrateV8DataMigration> logger;

public PageNotFoundMigrationPlan()
: base("PageNotFoundManager") => DefinePlan();
public MigrateV8DataMigration(IMigrationContext context, ILogger<MigrateV8DataMigration> logger) : base(context)
{
this.logger = logger ?? throw new ArgumentNullException(nameof(logger));

}

protected override void Migrate()
{
logger.LogDebug("Starting migration - {migrationName}", MigrationName);

/// <inheritdoc/>
public override string InitialState => "{pagenotfound-init-state}";
if (TableExists("pageNotFoundConfig"))
MigrateLegacyData();
}

/// <summary>
/// Defines the plan.
/// </summary>
protected void DefinePlan()
private void MigrateLegacyData()
{
From("{pagenotfound-init-state}")
.To<InitialMigration>("{pagenotfound-init-complete}");
var sql = this.Sql().Select("unP.uniqueId as ParentId", "unF.uniqueId as NotFoundPageId").From("pageNotFoundConfig as org")
.LeftJoin("umbracoNode as unP").On("org.ParentId = unP.id")
.LeftJoin("umbracoNode as unF").On("org.NotFoundPageId = unF.id");

var toMigrate = Database.Fetch<PageNotFoundInitialMigrationModel>(sql);
Database.InsertBatch(toMigrate);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Umbraco.Cms.Infrastructure.Migrations;

namespace HC.PageNotFoundManager.Core.Migrations
{
public class PageNotFoundMigrationPlan : MigrationPlan
{

public PageNotFoundMigrationPlan()
: base("PageNotFoundManager") => DefinePlan();

/// <inheritdoc/>
public override string InitialState => "{pagenotfound-init-state}";

/// <summary>
/// Defines the plan.
/// </summary>
protected void DefinePlan()
{
From("{pagenotfound-init-state}")
.To<InitialMigration>("{pagenotfound-init-complete}")
.To<MigrateV8DataMigration>("{pagenotfound-legacy-data-complete}");
}
}

}

0 comments on commit 015ea26

Please sign in to comment.