-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from rickbutterfield/feature/nodeid-to-nodekey
Change NodeId to NodeKey for better v14 support/migrations
- Loading branch information
Showing
8 changed files
with
63 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/Umbraco.Community.Sustainability/Migrations/03_ChangeNodeIdToKey.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Microsoft.Extensions.Logging; | ||
using Umbraco.Cms.Infrastructure.Migrations; | ||
using Umbraco.Community.Sustainability.Schemas; | ||
|
||
namespace Umbraco.Community.Sustainability.Migrations | ||
{ | ||
public class ChangeNodeIdToNodeKey : MigrationBase | ||
{ | ||
public ChangeNodeIdToNodeKey(IMigrationContext context) : base(context) | ||
{ | ||
} | ||
|
||
protected override void Migrate() | ||
{ | ||
Logger.LogDebug("Running migration {MigrationStep}", "ChangeNodeIdToNodeKey"); | ||
|
||
if (ColumnExists(PageMetric.TableName, "NodeId")) | ||
{ | ||
Alter.Table(PageMetric.TableName).AddColumn("NodeKey").AsGuid().Nullable().Do(); | ||
|
||
Database.Execute($@"UPDATE {PageMetric.TableName} SET NodeKey = {Cms.Core.Constants.DatabaseSchema.Tables.Node}.uniqueId | ||
FROM {Cms.Core.Constants.DatabaseSchema.Tables.Node} | ||
INNER JOIN {PageMetric.TableName} ON {Cms.Core.Constants.DatabaseSchema.Tables.Node}.id = {PageMetric.TableName}.NodeId"); | ||
|
||
Delete.Column("NodeId").FromTable(PageMetric.TableName).Do(); | ||
} | ||
else | ||
{ | ||
Logger.LogDebug("The column NodeKey already exists, skipping"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters