From f167c5fac9bd96528f26a8514849311789277666 Mon Sep 17 00:00:00 2001 From: Benedek Farkas Date: Thu, 15 Feb 2024 19:40:18 +0100 Subject: [PATCH] Simplifying the merged migrations in Common and Projections that had conflicts between 1.10.x and dev --- src/Orchard.Web/Core/Common/Migrations.cs | 46 ++++--------------- .../Modules/Orchard.Projections/Migrations.cs | 25 +++------- 2 files changed, 15 insertions(+), 56 deletions(-) diff --git a/src/Orchard.Web/Core/Common/Migrations.cs b/src/Orchard.Web/Core/Common/Migrations.cs index f331ecd80..2c2d9e1dc 100644 --- a/src/Orchard.Web/Core/Common/Migrations.cs +++ b/src/Orchard.Web/Core/Common/Migrations.cs @@ -167,33 +167,20 @@ namespace Orchard.Core.Common { return 6; } - // When upgrading from version 6 of 1.10.x (up until version 9), we'll just execute the same steps, but in a - // different order. - public int UpdateFrom6() { - // This is the original step of the dev branch. - AddIndexForIdentityPartRecordIdentifier(); + // This step's logic is executed together with the original logic from UpdateFrom7 and UpdateFrom8 and in + // UpdateFrom8 to make sure that an upgrade is possible from version 6 of both 1.10.x and dev, which both + // included these steps, but in a different order. + public int UpdateFrom6() => 7; - return 7; - } - - public int UpdateFrom7() { - // This is the original step of the dev branch. - AddIndexForCommonPartRecordContainerId(); - - // When upgrading from version 7 of 1.10.x, this index isn't created yet, so we need to run this step - // "again". On the other hand, AddIndexesForCommonPartOwner in UpdateFrom8 won't do anything, because those - // indexes were added in the 1.10.x version of UpdateFrom6. - AddIndexForIdentityPartRecordIdentifier(); - - return 8; - } + // See UpdateFrom6 for explanation. + public int UpdateFrom7() => 8; + // See UpdateFrom6 for explanation. public int UpdateFrom8() { - // This is the original step of the dev branch. + AddIndexForIdentityPartRecordIdentifier(); + AddIndexesForCommonPartOwner(); - // When upgrading from version 8 of 1.10.x, this index isn't created yet, so we need to run this step - // "again" AddIndexForCommonPartRecordContainerId(); return 9; @@ -208,8 +195,6 @@ namespace Orchard.Core.Common { SchemaBuilder.AlterTable(nameof(IdentityPartRecord), table => table.CreateIndex( indexName, nameof(IdentityPartRecord.Identifier))); - - IndexCreated(nameof(IdentityPartRecord), indexName); } // This change was originally UpdateFrom8 on 1.10.x and UpdateFrom7 on dev. @@ -220,8 +205,6 @@ namespace Orchard.Core.Common { // Container_Id is used in several queries like a foreign key. SchemaBuilder.AlterTable(nameof(CommonPartRecord), table => table.CreateIndex(indexName, "Container_id")); - - IndexCreated(nameof(CommonPartRecord), indexName); } // This change was originally UpdateFrom6 on 1.10.x and UpdateFrom8 on dev. @@ -258,10 +241,6 @@ namespace Orchard.Core.Common { table.CreateIndex(modifiedUtcIndexName, nameof(CommonPartRecord.OwnerId), nameof(CommonPartRecord.ModifiedUtc)); table.CreateIndex(publishedUtcIndexName, nameof(CommonPartRecord.OwnerId), nameof(CommonPartRecord.PublishedUtc)); }); - - IndexCreated(nameof(CommonPartRecord), createdUtcIndexName); - IndexCreated(nameof(CommonPartRecord), modifiedUtcIndexName); - IndexCreated(nameof(CommonPartRecord), publishedUtcIndexName); } private bool IndexExists(string tableName, string indexName) { @@ -286,12 +265,5 @@ namespace Orchard.Core.Common { return _existingIndexNames.Contains($"{SchemaBuilder.TableDbName(tableName)}.{tenantTablesPrefix}{indexName}"); } - - private void IndexCreated(string tableName, string indexName) { - var tenantTablesPrefix = string.IsNullOrEmpty(_shellSettings.DataTablePrefix) - ? string.Empty : $"{_shellSettings.DataTablePrefix}_"; - - _existingIndexNames.Add($"{SchemaBuilder.TableDbName(tableName)}.{tenantTablesPrefix}{indexName}"); - } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Projections/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Projections/Migrations.cs index 9c413a325..32475f4d2 100644 --- a/src/Orchard.Web/Modules/Orchard.Projections/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Projections/Migrations.cs @@ -366,27 +366,21 @@ namespace Orchard.Projections { return 5; } - // When upgrading from version 5 of 1.10.x (up until version 7), we'll just execute the same steps, but in a - // different order. - public int UpdateFrom5() { - // This is the original step of the dev branch. - MigratePropertyRecordToRewriteOutputCondition(); - - return 6; - } + // This step's logic is now executed in UpdateFrom6 as MigratePropertyRecordToRewriteOutputCondition to make + // sure that it's executed even when upgrading from version 6 of 1.10.x, which (as opposed to dev) executed the + // changes that make up AddLayoutRecordGuid in UpdateFrom6. + public int UpdateFrom5() => 6; + // See UpdateFrom5 for explanation. public int UpdateFrom6() { - // This is the original step of the dev branch. AddLayoutRecordGuid(); - // When upgrading from version 6 of 1.10.x, this column isn't created yet, so we need to run this step - // "again". MigratePropertyRecordToRewriteOutputCondition(); return 7; } - // This change was originally UpdateFrom5 on dev (but didn't exist on 1.10.x). + // This change was originally in UpdateFrom5 on dev, but didn't exist on 1.10.x. private void MigratePropertyRecordToRewriteOutputCondition() { if (ColumnExists("PropertyRecord", "RewriteOutputCondition")) return; @@ -399,8 +393,6 @@ namespace Orchard.Projections { // Reading this obsolete property to migrate its data to a new one. if (property.RewriteOutput) property.RewriteOutputCondition = "true"; #pragma warning restore CS0618 // Type or member is obsolete - - ColumnAdded("PropertyRecord", "RewriteOutputCondition"); } // This change was originally UpdateFrom5 on 1.10.x and UpdateFrom6 on dev. @@ -414,8 +406,6 @@ namespace Orchard.Projections { foreach (var layout in layoutRecords) { layout.GUIdentifier = Guid.NewGuid().ToString(); } - - ColumnAdded("LayoutRecord", "GUIdentifier"); } private bool ColumnExists(string tableName, string columnName) { @@ -437,8 +427,5 @@ namespace Orchard.Projections { return _existingColumnNames.Contains($"{SchemaBuilder.TableDbName(tableName)}.{columnName}"); } - - private void ColumnAdded(string tableName, string columnName) => - _existingColumnNames.Add($"{SchemaBuilder.TableDbName(tableName)}.{columnName}"); } }