From 85a4a4fa81e5aec44f8a1ce406e9ff1d194d452d Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 24 Jun 2015 17:46:52 +0200 Subject: [PATCH] fixes migration check to ensure that migrations for the current version always run if the current installation version is a pre-release --- src/Umbraco.Core/DatabaseContext.cs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Umbraco.Core/DatabaseContext.cs b/src/Umbraco.Core/DatabaseContext.cs index 08553de620..f3665ae0b8 100644 --- a/src/Umbraco.Core/DatabaseContext.cs +++ b/src/Umbraco.Core/DatabaseContext.cs @@ -656,17 +656,28 @@ namespace Umbraco.Core //set the installedMigrationVersion to be one less than the target so the latest migrations are guaranteed to execute installedMigrationVersion = new SemVersion(targetVersion.SubtractRevision()); } - - //DO the upgrade! - - var currentVersion = string.IsNullOrEmpty(GlobalSettings.ConfigurationStatus) + + //Figure out what our current installed version is. If the web.config doesn't have a version listed, then we'll use the minimum + // version detected between the schema installed and the migrations listed in the migration table. + // If there is a version in the web.config, we'll take the minimum between the listed migration in the db and what + // is declared in the web.config. + + var currentInstalledVersion = string.IsNullOrEmpty(GlobalSettings.ConfigurationStatus) //Take the minimum version between the detected schema version and the installed migration version ? new[] {installedSchemaVersion, installedMigrationVersion}.Min() //Take the minimum version between the installed migration version and the version specified in the config : new[] { SemVersion.Parse(GlobalSettings.ConfigurationStatus), installedMigrationVersion }.Min(); + //Ok, another edge case here. If the current version is a pre-release, + // then we want to ensure all migrations for the current release are executed. + if (currentInstalledVersion.Prerelease.IsNullOrWhiteSpace() == false) + { + currentInstalledVersion = new SemVersion(currentInstalledVersion.GetVersion().SubtractRevision()); + } - var runner = new MigrationRunner(migrationEntryService, _logger, currentVersion, UmbracoVersion.GetSemanticVersion(), GlobalSettings.UmbracoMigrationName); + //DO the upgrade! + + var runner = new MigrationRunner(migrationEntryService, _logger, currentInstalledVersion, UmbracoVersion.GetSemanticVersion(), GlobalSettings.UmbracoMigrationName); var upgraded = runner.Execute(database, true);