From afc236316349dca7614c8086daa68f4634fcdcbb Mon Sep 17 00:00:00 2001 From: Martin Blackwell Date: Wed, 31 Aug 2016 16:22:41 +0100 Subject: [PATCH 1/2] Resolution for U4-8927 --- src/Umbraco.Core/Persistence/Migrations/MigrationRunner.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Core/Persistence/Migrations/MigrationRunner.cs b/src/Umbraco.Core/Persistence/Migrations/MigrationRunner.cs index 51751b07ad..af894c453c 100644 --- a/src/Umbraco.Core/Persistence/Migrations/MigrationRunner.cs +++ b/src/Umbraco.Core/Persistence/Migrations/MigrationRunner.cs @@ -171,8 +171,8 @@ namespace Umbraco.Core.Persistence.Migrations from migrationAttribute in migrationAttributes where migrationAttribute != null where - migrationAttribute.TargetVersion > currentVersionToCompare && - migrationAttribute.TargetVersion <= targetVersionToCompare && + migrationAttribute.TargetVersion > targetVersionToCompare && + migrationAttribute.TargetVersion <= currentVersionToCompare && migrationAttribute.ProductName == _productName && //filter if the migration specifies a minimum current version for which to execute (migrationAttribute.MinimumCurrentVersion == null || currentVersionToCompare >= migrationAttribute.MinimumCurrentVersion) From 99ce7c07363d07ce7b943b401423add9e4124931 Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Thu, 12 Apr 2018 14:35:34 +0200 Subject: [PATCH 2/2] Throw error when "downgrading" to a higher version, make sure to give the results back in the correct order (newest version first, oldest last). --- src/Umbraco.Core/Persistence/Migrations/MigrationRunner.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Core/Persistence/Migrations/MigrationRunner.cs b/src/Umbraco.Core/Persistence/Migrations/MigrationRunner.cs index af894c453c..7c3e131b4c 100644 --- a/src/Umbraco.Core/Persistence/Migrations/MigrationRunner.cs +++ b/src/Umbraco.Core/Persistence/Migrations/MigrationRunner.cs @@ -166,6 +166,9 @@ namespace Umbraco.Core.Persistence.Migrations var targetVersionToCompare = _targetVersion.GetVersion(3); var currentVersionToCompare = _currentVersion.GetVersion(3); + if(currentVersionToCompare <= targetVersionToCompare) + throw new ArgumentException("When downgrading, make sure that the target version is lower than the current version."); + var migrations = (from migration in foundMigrations let migrationAttributes = migration.GetType().GetCustomAttributes(false) from migrationAttribute in migrationAttributes @@ -176,7 +179,7 @@ namespace Umbraco.Core.Persistence.Migrations migrationAttribute.ProductName == _productName && //filter if the migration specifies a minimum current version for which to execute (migrationAttribute.MinimumCurrentVersion == null || currentVersionToCompare >= migrationAttribute.MinimumCurrentVersion) - orderby migrationAttribute.TargetVersion, migrationAttribute.SortOrder descending + orderby migrationAttribute.TargetVersion descending, migrationAttribute.SortOrder descending select migration).Distinct(); return migrations; }