From 49430ca0a537c76a04b96d12509ebc01ab52b58e Mon Sep 17 00:00:00 2001 From: Shannon Date: Fri, 17 Aug 2018 16:07:53 +1000 Subject: [PATCH] fixes logic order of dropping indexes --- .../IncreaseLanguageIsoCodeColumnLength.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenTwelveZero/IncreaseLanguageIsoCodeColumnLength.cs b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenTwelveZero/IncreaseLanguageIsoCodeColumnLength.cs index fc788bb4a7..d79ff24517 100644 --- a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenTwelveZero/IncreaseLanguageIsoCodeColumnLength.cs +++ b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenTwelveZero/IncreaseLanguageIsoCodeColumnLength.cs @@ -18,15 +18,20 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenTwelveZ Execute.Code(database => { var localContext = new LocalMigrationContext(Context.CurrentDatabaseProvider, database, SqlSyntax, Logger); - var hasSql = false; // Some people seem to have a constraint in their DB instead of an index, we'd need to drop that one // See: https://our.umbraco.com/forum/using-umbraco-and-getting-started/93282-upgrade-from-711-to-712-fails var constraints = SqlSyntax.GetConstraintsPerTable(database).Distinct().ToArray(); if (constraints.Any(x => x.Item2.InvariantEquals("IX_umbracoLanguage_languageISOCode"))) { localContext.Delete.UniqueConstraint("IX_umbracoLanguage_languageISOCode").FromTable("umbracoLanguage"); - hasSql = true; + return localContext.GetSql(); } + return null; + }); + + Execute.Code(database => + { + var localContext = new LocalMigrationContext(Context.CurrentDatabaseProvider, database, SqlSyntax, Logger); //Now check for indexes of that name and drop that if it exists var dbIndexes = SqlSyntax.GetDefinedIndexes(database) @@ -34,10 +39,9 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenTwelveZ if (dbIndexes.Any(x => x.IndexName.InvariantEquals("IX_umbracoLanguage_languageISOCode"))) { localContext.Delete.Index("IX_umbracoLanguage_languageISOCode").OnTable("umbracoLanguage"); - hasSql = true; + return localContext.GetSql(); } - - return hasSql ? localContext.GetSql() : null; + return null; }); Alter.Table("umbracoLanguage")