From b9ff056b613b2aa394b24d72f6fb8948a1d3ae91 Mon Sep 17 00:00:00 2001 From: Stephan Date: Thu, 10 Sep 2015 10:19:28 +0200 Subject: [PATCH] Revert "U4-6992 - fix db migrations" This reverts commit 406d172169588344e0c2d4bcbe0bcf189adb0f18. --- .../AddServerRegistrationColumnsAndLock.cs | 70 +++++++++++++++++++ .../AddServerRegistrationIsMasterColumn.cs | 30 -------- src/Umbraco.Core/Umbraco.Core.csproj | 2 +- .../Migrations/EnsureServerLockNodeExists.cs | 63 ----------------- src/Umbraco.Web/Umbraco.Web.csproj | 1 - 5 files changed, 71 insertions(+), 95 deletions(-) create mode 100644 src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenThreeZero/AddServerRegistrationColumnsAndLock.cs delete mode 100644 src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenThreeZero/AddServerRegistrationIsMasterColumn.cs delete mode 100644 src/Umbraco.Web/Strategies/Migrations/EnsureServerLockNodeExists.cs diff --git a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenThreeZero/AddServerRegistrationColumnsAndLock.cs b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenThreeZero/AddServerRegistrationColumnsAndLock.cs new file mode 100644 index 0000000000..0a29fbb6ef --- /dev/null +++ b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenThreeZero/AddServerRegistrationColumnsAndLock.cs @@ -0,0 +1,70 @@ +using System; +using System.Linq; +using Umbraco.Core.Configuration; +using Umbraco.Core.Logging; +using Umbraco.Core.Models.Rdbms; +using Umbraco.Core.Persistence.SqlSyntax; + +namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenThreeZero +{ + [Migration("7.3.0", 17, GlobalSettings.UmbracoMigrationName)] + public class AddServerRegistrationColumnsAndLock : MigrationBase + { + public AddServerRegistrationColumnsAndLock(ISqlSyntaxProvider sqlSyntax, ILogger logger) + : base(sqlSyntax, logger) + { } + + public override void Up() + { + // don't execute if the column is already there + var columns = SqlSyntax.GetColumnsInSchema(Context.Database).ToArray(); + if (columns.Any(x => x.TableName.InvariantEquals("umbracoServer") && x.ColumnName.InvariantEquals("isMaster")) == false) + { + Create.Column("isMaster").OnTable("umbracoServer").AsBoolean().NotNullable().WithDefaultValue(0); + } + + // wrap in a transaction so that everything runs on the same connection + // and the IDENTITY_INSERT stuff is effective for all inserts. + using (var tr = Context.Database.GetTransaction()) + { + // turn on identity insert if db provider is not mysql + if (SqlSyntax.SupportsIdentityInsert()) + Context.Database.Execute(new Sql(string.Format("SET IDENTITY_INSERT {0} ON", SqlSyntax.GetQuotedTableName("umbracoNode")))); + + InsertLockObject(Constants.System.ServersLock, "0AF5E610-A310-4B6F-925F-E928D5416AF7", "LOCK: Servers"); + + // turn off identity insert if db provider is not mysql + if (SqlSyntax.SupportsIdentityInsert()) + Context.Database.Execute(new Sql(string.Format("SET IDENTITY_INSERT {0} OFF", SqlSyntax.GetQuotedTableName("umbracoNode")))); + + tr.Complete(); + } + } + + public override void Down() + { + // not implemented + } + + private void InsertLockObject(int id, string uniqueId, string text) + { + var exists = Context.Database.Exists(id); + if (exists) return; + + Context.Database.Insert("umbracoNode", "id", false, new NodeDto + { + NodeId = id, + Trashed = false, + ParentId = -1, + UserId = 0, + Level = 1, + Path = "-1," + id, + SortOrder = 0, + UniqueId = new Guid(uniqueId), + Text = text, + NodeObjectType = new Guid(Constants.ObjectTypes.LockObject), + CreateDate = DateTime.Now + }); + } + } +} diff --git a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenThreeZero/AddServerRegistrationIsMasterColumn.cs b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenThreeZero/AddServerRegistrationIsMasterColumn.cs deleted file mode 100644 index b511d8271e..0000000000 --- a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenThreeZero/AddServerRegistrationIsMasterColumn.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Linq; -using Umbraco.Core.Configuration; -using Umbraco.Core.Logging; -using Umbraco.Core.Persistence.SqlSyntax; - -namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenThreeZero -{ - [Migration("7.3.0", 17, GlobalSettings.UmbracoMigrationName)] - public class AddServerRegistrationIsMasterColumn : MigrationBase - { - public AddServerRegistrationIsMasterColumn(ISqlSyntaxProvider sqlSyntax, ILogger logger) - : base(sqlSyntax, logger) - { } - - public override void Up() - { - // don't execute if the column is already there - var columns = SqlSyntax.GetColumnsInSchema(Context.Database).ToArray(); - if (columns.Any(x => x.TableName.InvariantEquals("umbracoServer") && x.ColumnName.InvariantEquals("isMaster")) == false) - { - Create.Column("isMaster").OnTable("umbracoServer").AsBoolean().NotNullable().WithDefaultValue(0); - } - } - - public override void Down() - { - // not implemented - } - } -} diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index a40dd520a6..2ea422c3a6 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -406,7 +406,7 @@ - + diff --git a/src/Umbraco.Web/Strategies/Migrations/EnsureServerLockNodeExists.cs b/src/Umbraco.Web/Strategies/Migrations/EnsureServerLockNodeExists.cs deleted file mode 100644 index 0659c62383..0000000000 --- a/src/Umbraco.Web/Strategies/Migrations/EnsureServerLockNodeExists.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System; -using Semver; -using Umbraco.Core; -using Umbraco.Core.Events; -using Umbraco.Core.Models.Rdbms; -using Umbraco.Core.Persistence; -using Umbraco.Core.Persistence.Migrations; -using Umbraco.Core.Persistence.SqlSyntax; - -namespace Umbraco.Web.Strategies.Migrations -{ - public class EnsureServerLockNodeExists : MigrationStartupHander - { - protected override void AfterMigration(MigrationRunner sender, MigrationEventArgs e) - { - var target = new SemVersion(7, 3); - - if (e.ConfiguredSemVersion > target) - return; - - var context = e.MigrationContext; - var sqlSyntax = SqlSyntaxContext.SqlSyntaxProvider; - - // wrap in a transaction so that everything runs on the same connection - // and the IDENTITY_INSERT stuff is effective for all inserts. - using (var tr = context.Database.GetTransaction()) - { - // turn on identity insert if db provider is not mysql - if (sqlSyntax.SupportsIdentityInsert()) - context.Database.Execute(new Sql(string.Format("SET IDENTITY_INSERT {0} ON", sqlSyntax.GetQuotedTableName("umbracoNode")))); - - EnsureLockNode(context, Constants.System.ServersLock, "0AF5E610-A310-4B6F-925F-E928D5416AF7", "LOCK: Servers"); - - // turn off identity insert if db provider is not mysql - if (sqlSyntax.SupportsIdentityInsert()) - context.Database.Execute(new Sql(string.Format("SET IDENTITY_INSERT {0} OFF", sqlSyntax.GetQuotedTableName("umbracoNode")))); - - tr.Complete(); - } - } - - private static void EnsureLockNode(IMigrationContext context, int id, string uniqueId, string text) - { - var exists = context.Database.Exists(id); - if (exists) return; - - context.Database.Insert("umbracoNode", "id", false, new NodeDto - { - NodeId = id, - Trashed = false, - ParentId = -1, - UserId = 0, - Level = 1, - Path = "-1," + id, - SortOrder = 0, - UniqueId = new Guid(uniqueId), - Text = text, - NodeObjectType = new Guid(Constants.ObjectTypes.LockObject), - CreateDate = DateTime.Now - }); - } - } -} diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 1ad99b4315..39b693af90 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -313,7 +313,6 @@ -