From ff7bdb0f5b38c144bf3e64e2307a25b09b20adcb Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 22 Jun 2015 19:31:34 +0200 Subject: [PATCH] Ensures the migrations table is created on install, updates the installation to create the latest migration version once complete. --- src/Umbraco.Core/DatabaseContext.cs | 6 ++++-- src/Umbraco.Core/Persistence/DatabaseSchemaHelper.cs | 11 ++++++++--- .../Migrations/Initial/DatabaseSchemaCreation.cs | 3 ++- .../Install/InstallSteps/DatabaseInstallStep.cs | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Core/DatabaseContext.cs b/src/Umbraco.Core/DatabaseContext.cs index 7a05c2925e..df5ed33bd3 100644 --- a/src/Umbraco.Core/DatabaseContext.cs +++ b/src/Umbraco.Core/DatabaseContext.cs @@ -542,7 +542,7 @@ namespace Umbraco.Core return _result; } - internal Result CreateDatabaseSchemaAndData() + internal Result CreateDatabaseSchemaAndData(ApplicationContext applicationContext) { try { @@ -584,7 +584,9 @@ namespace Umbraco.Core //If Configuration Status is empty and the determined version is "empty" its a new install - otherwise upgrade the existing if (string.IsNullOrEmpty(GlobalSettings.ConfigurationStatus) && installedVersion.Equals(new Version(0, 0, 0))) { - database.CreateDatabaseSchema(); + var helper = new DatabaseSchemaHelper(database, _logger, SqlSyntax); + helper.CreateDatabaseSchema(true, applicationContext); + message = message + "

Installation completed!

"; //now that everything is done, we need to determine the version of SQL server that is executing diff --git a/src/Umbraco.Core/Persistence/DatabaseSchemaHelper.cs b/src/Umbraco.Core/Persistence/DatabaseSchemaHelper.cs index 5129032bcf..fbc5285767 100644 --- a/src/Umbraco.Core/Persistence/DatabaseSchemaHelper.cs +++ b/src/Umbraco.Core/Persistence/DatabaseSchemaHelper.cs @@ -1,10 +1,12 @@ using System; using System.Linq; +using Umbraco.Core.Configuration; using Umbraco.Core.Logging; using Umbraco.Core.Models.Rdbms; using Umbraco.Core.Persistence.DatabaseModelDefinitions; using Umbraco.Core.Persistence.Migrations.Initial; using Umbraco.Core.Persistence.SqlSyntax; +using Umbraco.Core.Services; namespace Umbraco.Core.Persistence { @@ -60,7 +62,7 @@ namespace Umbraco.Core.Persistence if (guardConfiguration && applicationContext.IsConfigured) throw new Exception("Umbraco is already configured!"); - CreateDatabaseSchemaDo(); + CreateDatabaseSchemaDo(applicationContext.Services.MigrationEntryService); } internal void CreateDatabaseSchemaDo(bool guardConfiguration, ApplicationContext applicationContext) @@ -68,16 +70,19 @@ namespace Umbraco.Core.Persistence if (guardConfiguration && applicationContext.IsConfigured) throw new Exception("Umbraco is already configured!"); - CreateDatabaseSchemaDo(); + CreateDatabaseSchemaDo(applicationContext.Services.MigrationEntryService); } - internal void CreateDatabaseSchemaDo() + internal void CreateDatabaseSchemaDo(IMigrationEntryService migrationEntryService) { _logger.Info("Initializing database schema creation"); var creation = new DatabaseSchemaCreation(_db, _logger, _syntaxProvider); creation.InitializeDatabaseSchema(); + //Now ensure to cretae the tag in the db for the current migration version + migrationEntryService.CreateEntry(GlobalSettings.UmbracoMigrationName, UmbracoVersion.Current); + _logger.Info("Finalized database schema creation"); } diff --git a/src/Umbraco.Core/Persistence/Migrations/Initial/DatabaseSchemaCreation.cs b/src/Umbraco.Core/Persistence/Migrations/Initial/DatabaseSchemaCreation.cs index d30f9e4f3c..ce2a53ea95 100644 --- a/src/Umbraco.Core/Persistence/Migrations/Initial/DatabaseSchemaCreation.cs +++ b/src/Umbraco.Core/Persistence/Migrations/Initial/DatabaseSchemaCreation.cs @@ -82,7 +82,8 @@ namespace Umbraco.Core.Persistence.Migrations.Initial {41, typeof (AccessDto)}, {42, typeof (AccessRuleDto)}, {43, typeof(CacheInstructionDto)}, - {44, typeof (ExternalLoginDto)} + {44, typeof (ExternalLoginDto)}, + {45, typeof (MigrationDto)} }; #endregion diff --git a/src/Umbraco.Web/Install/InstallSteps/DatabaseInstallStep.cs b/src/Umbraco.Web/Install/InstallSteps/DatabaseInstallStep.cs index fe3725e45d..57c8e67465 100644 --- a/src/Umbraco.Web/Install/InstallSteps/DatabaseInstallStep.cs +++ b/src/Umbraco.Web/Install/InstallSteps/DatabaseInstallStep.cs @@ -21,7 +21,7 @@ namespace Umbraco.Web.Install.InstallSteps public override InstallSetupResult Execute(object model) { - var result = _applicationContext.DatabaseContext.CreateDatabaseSchemaAndData(); + var result = _applicationContext.DatabaseContext.CreateDatabaseSchemaAndData(_applicationContext); if (result.Success == false) {