From 33f76d25f7bed97594647822065b58e91b60e8d7 Mon Sep 17 00:00:00 2001 From: Stephan Date: Wed, 14 Jun 2017 15:04:56 +0200 Subject: [PATCH] U4-9993 - fix upgrade issues --- .../UpdateUniqueIdToHaveCorrectIndexType.cs | 32 +++++++------------ 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenThreeZero/UpdateUniqueIdToHaveCorrectIndexType.cs b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenThreeZero/UpdateUniqueIdToHaveCorrectIndexType.cs index 79d7b3111c..dc8415a9f8 100644 --- a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenThreeZero/UpdateUniqueIdToHaveCorrectIndexType.cs +++ b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenThreeZero/UpdateUniqueIdToHaveCorrectIndexType.cs @@ -1,5 +1,4 @@ using System.Linq; -using Umbraco.Core.Configuration; using Umbraco.Core.Logging; using Umbraco.Core.Persistence.DatabaseModelDefinitions; using Umbraco.Core.Persistence.SqlSyntax; @@ -11,15 +10,11 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenThreeZe { public UpdateUniqueIdToHaveCorrectIndexType(ISqlSyntaxProvider sqlSyntax, ILogger logger) : base(sqlSyntax, logger) - { - } + { } - //see: http://issues.umbraco.org/issue/U4-6188, http://issues.umbraco.org/issue/U4-6187 public override void Up() { - - - var dbIndexes = SqlSyntax.GetDefinedIndexes(Context.Database) + var indexes = SqlSyntax.GetDefinedIndexes(Context.Database) .Select(x => new DbIndexDefinition() { TableName = x.Item1, @@ -28,24 +23,19 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenThreeZe IsUnique = x.Item4 }).ToArray(); - //must be non-nullable + // drop the index if it exists + if (indexes.Any(x => x.IndexName.InvariantEquals("IX_umbracoNodeUniqueID"))) + Delete.Index("IX_umbracoNodeUniqueID").OnTable("umbracoNode"); + + // set uniqueID to be non-nullable + // the index *must* be dropped else 'one or more objects access this column' exception Alter.Table("umbracoNode").AlterColumn("uniqueID").AsGuid().NotNullable(); - //make sure it already exists - if (dbIndexes.Any(x => x.IndexName.InvariantEquals("IX_umbracoNodeUniqueID"))) - { - Delete.Index("IX_umbracoNodeUniqueID").OnTable("umbracoNode"); - } - //make sure it doesn't already exist - if (dbIndexes.Any(x => x.IndexName.InvariantEquals("IX_umbracoNode_uniqueID")) == false) - { - //must be a uniqe index - Create.Index("IX_umbracoNode_uniqueID").OnTable("umbracoNode").OnColumn("uniqueID").Unique(); - } + // create the index + Create.Index("IX_umbracoNode_uniqueID").OnTable("umbracoNode").OnColumn("uniqueID").Unique(); } public override void Down() - { - } + { } } } \ No newline at end of file