diff --git a/src/Umbraco.Core/Persistence/Migrations/MigrationRunner.cs b/src/Umbraco.Core/Persistence/Migrations/MigrationRunner.cs index 51751b07ad..7c3e131b4c 100644 --- a/src/Umbraco.Core/Persistence/Migrations/MigrationRunner.cs +++ b/src/Umbraco.Core/Persistence/Migrations/MigrationRunner.cs @@ -166,17 +166,20 @@ 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 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) - orderby migrationAttribute.TargetVersion, migrationAttribute.SortOrder descending + orderby migrationAttribute.TargetVersion descending, migrationAttribute.SortOrder descending select migration).Distinct(); return migrations; }