From 97a0956aab804c23d52300b7e54e845554c9812d Mon Sep 17 00:00:00 2001 From: Jasmin Savard Date: Fri, 19 Jan 2024 14:45:59 -0500 Subject: [PATCH 01/11] Id's not null --- .../OrchardCore.Alias/Migrations.cs | 12 ++--- .../OrchardCore.ArchiveLater/Migrations.cs | 2 +- .../OrchardCore.AuditTrail/Migrations.cs | 6 +-- .../OrchardCore.Autoroute/Migrations.cs | 14 +++--- .../Indexing/SQL/Migrations.cs | 44 +++++++++---------- .../Indexing/SQL/UserPickerMigrations.cs | 4 +- .../Migrations.cs | 6 +-- .../OrchardCore.Indexing/Migrations.cs | 6 +-- .../OrchardCore.Layers/Migrations.cs | 2 +- .../OrchardCore.Lists/Migrations.cs | 6 +-- .../Migrations/NotificationMigrations.cs | 2 +- .../OrchardCore.PublishLater/Migrations.cs | 4 +- .../OrchardCore.Taxonomies/Migrations.cs | 18 ++++---- .../OrchardCore.Users/Migrations.cs | 20 ++++----- .../OrchardCore.Workflows/Migrations.cs | 20 ++++----- .../Records/Migrations.cs | 6 +-- .../YesSql/Migrations/OpenIdMigrations.cs | 28 ++++++------ .../GraphQL/ContentItemsFieldTypeTests.cs | 4 +- 18 files changed, 102 insertions(+), 102 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Alias/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Alias/Migrations.cs index 93c556cc3ff..751854b585a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Alias/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Alias/Migrations.cs @@ -24,10 +24,10 @@ await _contentDefinitionManager.AlterPartDefinitionAsync(nameof(AliasPart), buil .WithDescription("Provides a way to define custom aliases for content items.")); await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("Alias", col => col.WithLength(AliasPart.MaxAliasLength)) - .Column("ContentItemId", c => c.WithLength(26)) - .Column("Latest", c => c.WithDefault(false)) - .Column("Published", c => c.WithDefault(true)) + .Column("Alias", column => column.WithLength(AliasPart.MaxAliasLength)) + .Column("ContentItemId", column => column.NotNull().WithLength(26)) + .Column("Latest", column => column.WithDefault(false)) + .Column("Published", column => column.WithDefault(true)) ); await SchemaBuilder.AlterIndexTableAsync(table => table @@ -47,11 +47,11 @@ await SchemaBuilder.AlterIndexTableAsync(table => table public async Task UpdateFrom1Async() { await SchemaBuilder.AlterIndexTableAsync(table => table - .AddColumn("Latest", c => c.WithDefault(false)) + .AddColumn("Latest", column => column.WithDefault(false)) ); await SchemaBuilder.AlterIndexTableAsync(table => table - .AddColumn("Published", c => c.WithDefault(true)) + .AddColumn("Published", column => column.WithDefault(true)) ); return 2; diff --git a/src/OrchardCore.Modules/OrchardCore.ArchiveLater/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.ArchiveLater/Migrations.cs index f62335d3a4c..4770fe4650a 100644 --- a/src/OrchardCore.Modules/OrchardCore.ArchiveLater/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.ArchiveLater/Migrations.cs @@ -25,7 +25,7 @@ await _contentDefinitionManager.AlterPartDefinitionAsync(nameof(ArchiveLaterPart .WithDescription("Adds the ability to schedule content items to be archived at a given future date and time.")); await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("ContentItemId") + .Column("ContentItemId", column => column.NotNull().WithLength(26)) .Column("ScheduledArchiveDateTimeUtc") .Column("Published") .Column("Latest") diff --git a/src/OrchardCore.Modules/OrchardCore.AuditTrail/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.AuditTrail/Migrations.cs index ab5423ac5fb..1cd8bcff8f5 100644 --- a/src/OrchardCore.Modules/OrchardCore.AuditTrail/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.AuditTrail/Migrations.cs @@ -12,11 +12,11 @@ public class Migrations : DataMigration public async Task CreateAsync() { await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column(nameof(AuditTrailEventIndex.EventId), column => column.WithLength(26)) + .Column(nameof(AuditTrailEventIndex.EventId), column => column.NotNull().WithLength(26)) .Column(nameof(AuditTrailEventIndex.Category), column => column.WithLength(64)) .Column(nameof(AuditTrailEventIndex.Name), column => column.WithLength(64)) - .Column(nameof(AuditTrailEventIndex.CorrelationId), column => column.WithLength(26)) - .Column(nameof(AuditTrailEventIndex.UserId), column => column.WithLength(26)) + .Column(nameof(AuditTrailEventIndex.CorrelationId), column => column.NotNull().WithLength(26)) + .Column(nameof(AuditTrailEventIndex.UserId), column => column.NotNull().WithLength(26)) .Column(nameof(AuditTrailEventIndex.NormalizedUserName), column => column.Nullable().WithLength(255)) .Column(nameof(AuditTrailEventIndex.CreatedUtc), column => column.Nullable()), collection: AuditTrailEvent.Collection); diff --git a/src/OrchardCore.Modules/OrchardCore.Autoroute/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Autoroute/Migrations.cs index 7db23059adf..a2623011f29 100644 --- a/src/OrchardCore.Modules/OrchardCore.Autoroute/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Autoroute/Migrations.cs @@ -24,10 +24,10 @@ await _contentDefinitionManager.AlterPartDefinitionAsync("AutoroutePart", builde .WithDescription("Provides a custom url for your content item.")); await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("ContentItemId", c => c.WithLength(26)) - .Column("ContainedContentItemId", c => c.WithLength(26)) - .Column("JsonPath", c => c.Unlimited()) - .Column("Path", col => col.WithLength(AutoroutePart.MaxPathLength)) + .Column("ContentItemId", column => column.NotNull().WithLength(26)) + .Column("ContainedContentItemId", column => column.NotNull().WithLength(26)) + .Column("JsonPath", column => column.Unlimited()) + .Column("Path", column => column.WithLength(AutoroutePart.MaxPathLength)) .Column("Published") .Column("Latest") ); @@ -57,15 +57,15 @@ public int UpdateFrom2() public async Task UpdateFrom3Async() { await SchemaBuilder.AlterIndexTableAsync(table => table - .AddColumn("ContainedContentItemId", c => c.WithLength(26)) + .AddColumn("ContainedContentItemId", column => column.NotNull().WithLength(26)) ); await SchemaBuilder.AlterIndexTableAsync(table => table - .AddColumn("JsonPath", c => c.Unlimited()) + .AddColumn("JsonPath", column => column.Unlimited()) ); await SchemaBuilder.AlterIndexTableAsync(table => table - .AddColumn("Latest", c => c.WithDefault(false)) + .AddColumn("Latest", column => column.WithDefault(false)) ); return 4; diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/Migrations.cs index a06d99c46b8..e6fac7786c6 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/Migrations.cs @@ -23,8 +23,8 @@ public async Task CreateAsync() // For existing SQL databases update the TextFieldIndex tables Text column length manually. // INFO: The Text Length is now of 766 chars, but this is only used on a new installation. await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("ContentItemId", column => column.WithLength(26)) - .Column("ContentItemVersionId", column => column.WithLength(26)) + .Column("ContentItemId", column => column.NotNull().WithLength(26)) + .Column("ContentItemVersionId", column => column.NotNull().WithLength(26)) .Column("ContentType", column => column.WithLength(ContentItemIndex.MaxContentTypeSize)) .Column("ContentPart", column => column.WithLength(ContentItemIndex.MaxContentPartSize)) .Column("ContentField", column => column.WithLength(ContentItemIndex.MaxContentFieldSize)) @@ -66,8 +66,8 @@ await SchemaBuilder.AlterIndexTableAsync(table => table ); await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("ContentItemId", column => column.WithLength(26)) - .Column("ContentItemVersionId", column => column.WithLength(26)) + .Column("ContentItemId", column => column.NotNull().WithLength(26)) + .Column("ContentItemVersionId", column => column.NotNull().WithLength(26)) .Column("ContentType", column => column.WithLength(ContentItemIndex.MaxContentTypeSize)) .Column("ContentPart", column => column.WithLength(ContentItemIndex.MaxContentPartSize)) .Column("ContentField", column => column.WithLength(ContentItemIndex.MaxContentFieldSize)) @@ -99,8 +99,8 @@ await SchemaBuilder.AlterIndexTableAsync(table => table ); await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("ContentItemId", column => column.WithLength(26)) - .Column("ContentItemVersionId", column => column.WithLength(26)) + .Column("ContentItemId", column => column.NotNull().WithLength(26)) + .Column("ContentItemVersionId", column => column.NotNull().WithLength(26)) .Column("ContentType", column => column.WithLength(ContentItemIndex.MaxContentTypeSize)) .Column("ContentPart", column => column.WithLength(ContentItemIndex.MaxContentPartSize)) .Column("ContentField", column => column.WithLength(ContentItemIndex.MaxContentFieldSize)) @@ -139,8 +139,8 @@ await SchemaBuilder.AlterIndexTableAsync(table => table ); await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("ContentItemId", column => column.WithLength(26)) - .Column("ContentItemVersionId", column => column.WithLength(26)) + .Column("ContentItemId", column => column.NotNull().WithLength(26)) + .Column("ContentItemVersionId", column => column.NotNull().WithLength(26)) .Column("ContentType", column => column.WithLength(ContentItemIndex.MaxContentTypeSize)) .Column("ContentPart", column => column.WithLength(ContentItemIndex.MaxContentPartSize)) .Column("ContentField", column => column.WithLength(ContentItemIndex.MaxContentFieldSize)) @@ -179,8 +179,8 @@ await SchemaBuilder.AlterIndexTableAsync(table => table ); await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("ContentItemId", column => column.WithLength(26)) - .Column("ContentItemVersionId", column => column.WithLength(26)) + .Column("ContentItemId", column => column.NotNull().WithLength(26)) + .Column("ContentItemVersionId", column => column.NotNull().WithLength(26)) .Column("ContentType", column => column.WithLength(ContentItemIndex.MaxContentTypeSize)) .Column("ContentPart", column => column.WithLength(ContentItemIndex.MaxContentPartSize)) .Column("ContentField", column => column.WithLength(ContentItemIndex.MaxContentFieldSize)) @@ -220,8 +220,8 @@ await SchemaBuilder.AlterIndexTableAsync(table => table ); await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("ContentItemId", column => column.WithLength(26)) - .Column("ContentItemVersionId", column => column.WithLength(26)) + .Column("ContentItemId", column => column.NotNull().WithLength(26)) + .Column("ContentItemVersionId", column => column.NotNull().WithLength(26)) .Column("ContentType", column => column.WithLength(ContentItemIndex.MaxContentTypeSize)) .Column("ContentPart", column => column.WithLength(ContentItemIndex.MaxContentPartSize)) .Column("ContentField", column => column.WithLength(ContentItemIndex.MaxContentFieldSize)) @@ -260,8 +260,8 @@ await SchemaBuilder.AlterIndexTableAsync(table => table ); await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("ContentItemId", column => column.WithLength(26)) - .Column("ContentItemVersionId", column => column.WithLength(26)) + .Column("ContentItemId", column => column.NotNull().WithLength(26)) + .Column("ContentItemVersionId", column => column.NotNull().WithLength(26)) .Column("ContentType", column => column.WithLength(ContentItemIndex.MaxContentTypeSize)) .Column("ContentPart", column => column.WithLength(ContentItemIndex.MaxContentPartSize)) .Column("ContentField", column => column.WithLength(ContentItemIndex.MaxContentFieldSize)) @@ -304,8 +304,8 @@ await SchemaBuilder.AlterIndexTableAsync(table => table // The BigText and BigUrl columns are new additions so will not be populated until the content item is republished. // INFO: The Url and Text Length is now of 766 chars, but this is only used on a new installation. await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("ContentItemId", column => column.WithLength(26)) - .Column("ContentItemVersionId", column => column.WithLength(26)) + .Column("ContentItemId", column => column.NotNull().WithLength(26)) + .Column("ContentItemVersionId", column => column.NotNull().WithLength(26)) .Column("ContentType", column => column.WithLength(ContentItemIndex.MaxContentTypeSize)) .Column("ContentPart", column => column.WithLength(ContentItemIndex.MaxContentPartSize)) .Column("ContentField", column => column.WithLength(ContentItemIndex.MaxContentFieldSize)) @@ -360,8 +360,8 @@ await SchemaBuilder.AlterIndexTableAsync(table => table ); await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("ContentItemId", column => column.WithLength(26)) - .Column("ContentItemVersionId", column => column.WithLength(26)) + .Column("ContentItemId", column => column.NotNull().WithLength(26)) + .Column("ContentItemVersionId", column => column.NotNull().WithLength(26)) .Column("ContentType", column => column.WithLength(ContentItemIndex.MaxContentTypeSize)) .Column("ContentPart", column => column.WithLength(ContentItemIndex.MaxContentPartSize)) .Column("ContentField", column => column.WithLength(ContentItemIndex.MaxContentFieldSize)) @@ -392,8 +392,8 @@ await SchemaBuilder.AlterIndexTableAsync(table => table ); await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("ContentItemId", column => column.WithLength(26)) - .Column("ContentItemVersionId", column => column.WithLength(26)) + .Column("ContentItemId", column => column.NotNull().WithLength(26)) + .Column("ContentItemVersionId", column => column.NotNull().WithLength(26)) .Column("ContentType", column => column.WithLength(ContentItemIndex.MaxContentTypeSize)) .Column("ContentPart", column => column.WithLength(ContentItemIndex.MaxContentPartSize)) .Column("ContentField", column => column.WithLength(ContentItemIndex.MaxContentFieldSize)) @@ -454,8 +454,8 @@ await SchemaBuilder.AlterIndexTableAsync(table => table public async Task UpdateFrom2Async() { await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("ContentItemId", column => column.WithLength(26)) - .Column("ContentItemVersionId", column => column.WithLength(26)) + .Column("ContentItemId", column => column.NotNull().WithLength(26)) + .Column("ContentItemVersionId", column => column.NotNull().WithLength(26)) .Column("ContentType", column => column.WithLength(ContentItemIndex.MaxContentTypeSize)) .Column("ContentPart", column => column.WithLength(ContentItemIndex.MaxContentPartSize)) .Column("ContentField", column => column.WithLength(ContentItemIndex.MaxContentFieldSize)) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/UserPickerMigrations.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/UserPickerMigrations.cs index 06fd0dac97d..ef64cb20098 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/UserPickerMigrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Indexing/SQL/UserPickerMigrations.cs @@ -12,8 +12,8 @@ public class UserPickerMigrations : DataMigration public async Task CreateAsync() { await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("ContentItemId", column => column.WithLength(26)) - .Column("ContentItemVersionId", column => column.WithLength(26)) + .Column("ContentItemId", column => column.NotNull().WithLength(26)) + .Column("ContentItemVersionId", column => column.NotNull().WithLength(26)) .Column("ContentType", column => column.WithLength(ContentItemIndex.MaxContentTypeSize)) .Column("ContentPart", column => column.WithLength(ContentItemIndex.MaxContentPartSize)) .Column("ContentField", column => column.WithLength(ContentItemIndex.MaxContentFieldSize)) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Migrations.cs index 0e1e20217fe..a2b1926982d 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Migrations.cs @@ -27,9 +27,9 @@ await _contentDefinitionManager.AlterPartDefinitionAsync(nameof(LocalizationPart .WithDescription("Provides a way to create localized version of content.")); await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("LocalizationSet", col => col.WithLength(26)) - .Column("Culture", col => col.WithLength(16)) - .Column("ContentItemId", c => c.WithLength(26)) + .Column("LocalizationSet", column => column.NotNull().WithLength(26)) + .Column("Culture", column => column.NotNull().WithLength(16)) + .Column("ContentItemId", column => column.NotNull().WithLength(26)) .Column("Published") .Column("Latest") ); diff --git a/src/OrchardCore.Modules/OrchardCore.Indexing/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Indexing/Migrations.cs index daa2af05675..4de39310ff0 100644 --- a/src/OrchardCore.Modules/OrchardCore.Indexing/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Indexing/Migrations.cs @@ -9,9 +9,9 @@ public class Migrations : DataMigration public async Task CreateAsync() { await SchemaBuilder.CreateTableAsync(nameof(IndexingTask), table => table - .Column("Id", col => col.PrimaryKey().Identity()) - .Column("ContentItemId", c => c.WithLength(26)) - .Column("CreatedUtc", col => col.NotNull()) + .Column("Id", column => column.PrimaryKey().Identity()) + .Column("ContentItemId", column => column.NotNull().WithLength(26)) + .Column("CreatedUtc", column => column.NotNull()) .Column("Type") ); diff --git a/src/OrchardCore.Modules/OrchardCore.Layers/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Layers/Migrations.cs index 141bbb9856e..19319dea109 100644 --- a/src/OrchardCore.Modules/OrchardCore.Layers/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Layers/Migrations.cs @@ -26,7 +26,7 @@ public Migrations( public async Task CreateAsync() { await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("Zone", c => c.WithLength(64)) + .Column("Zone", column => column.WithLength(64)) ); await SchemaBuilder.AlterIndexTableAsync(table => table diff --git a/src/OrchardCore.Modules/OrchardCore.Lists/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Lists/Migrations.cs index 038c58aec7c..a4556003796 100644 --- a/src/OrchardCore.Modules/OrchardCore.Lists/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Lists/Migrations.cs @@ -24,8 +24,8 @@ await _contentDefinitionManager.AlterPartDefinitionAsync("ListPart", builder => .WithDescription("Add a list behavior.")); await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("ContentItemId", column => column.WithLength(26)) - .Column("ListContentItemId", column => column.WithLength(26)) + .Column("ContentItemId", column => column.NotNull().WithLength(26)) + .Column("ListContentItemId", column => column.NotNull().WithLength(26)) .Column("DisplayText") .Column("Order") .Column("ListContentType") @@ -77,7 +77,7 @@ await SchemaBuilder.AlterIndexTableAsync(table => table public async Task UpdateFrom3Async() { await SchemaBuilder.AlterIndexTableAsync(table => table - .AddColumn("ContentItemId", column => column.WithLength(26)) + .AddColumn("ContentItemId", column => column.NotNull().WithLength(26)) ); await SchemaBuilder.AlterIndexTableAsync(table => table diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Migrations/NotificationMigrations.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Migrations/NotificationMigrations.cs index f8015b28709..54a5e470054 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Migrations/NotificationMigrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Migrations/NotificationMigrations.cs @@ -11,7 +11,7 @@ public class NotificationMigrations : DataMigration public async Task CreateAsync() { await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("NotificationId", column => column.WithLength(26)) + .Column("NotificationId", column => column.NotNull().WithLength(26)) .Column("UserId", column => column.WithLength(26)) .Column("IsRead") .Column("ReadAtUtc") diff --git a/src/OrchardCore.Modules/OrchardCore.PublishLater/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.PublishLater/Migrations.cs index 88a23193218..19f69eacc02 100644 --- a/src/OrchardCore.Modules/OrchardCore.PublishLater/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.PublishLater/Migrations.cs @@ -25,7 +25,7 @@ await _contentDefinitionManager.AlterPartDefinitionAsync("PublishLaterPart", bui .WithDescription("Adds the ability to schedule content items to be published at a given future date and time.")); await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("ContentItemId") + .Column("ContentItemId", column => column.NotNull().WithLength(26)) .Column("ScheduledPublishDateTimeUtc") .Column("Published") .Column("Latest") @@ -67,7 +67,7 @@ public async Task UpdateFrom2Async() { await SchemaBuilder.AlterIndexTableAsync(table => { - table.AddColumn("ContentItemId"); + table.AddColumn("ContentItemId", column => column.NotNull().WithLength(26)); table.AddColumn("Published"); table.AddColumn("Latest"); }); diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Migrations.cs index 15aa789f3b2..02c19561e7c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Migrations.cs @@ -44,14 +44,14 @@ await _contentDefinitionManager.AlterTypeDefinitionAsync("Taxonomy", taxonomy => ); await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("TaxonomyContentItemId", c => c.WithLength(26)) - .Column("ContentItemId", c => c.WithLength(26)) + .Column("TaxonomyContentItemId", column => column.NotNull().WithLength(26)) + .Column("ContentItemId", column => column.NotNull().WithLength(26)) .Column("ContentType", column => column.WithLength(ContentItemIndex.MaxContentTypeSize)) .Column("ContentPart", column => column.WithLength(ContentItemIndex.MaxContentPartSize)) .Column("ContentField", column => column.WithLength(ContentItemIndex.MaxContentFieldSize)) - .Column("TermContentItemId", column => column.WithLength(26)) - .Column("Published", c => c.WithDefault(true)) - .Column("Latest", c => c.WithDefault(false)) + .Column("TermContentItemId", column => column.NotNull().WithLength(26)) + .Column("Published", column => column.WithDefault(true)) + .Column("Latest", column => column.WithDefault(false)) ); await SchemaBuilder.AlterIndexTableAsync(table => table @@ -110,11 +110,11 @@ public async Task UpdateFrom3Async() { // This step has been updated to also add these new columns. await SchemaBuilder.AlterIndexTableAsync(table => table - .AddColumn("Published", c => c.WithDefault(true)) + .AddColumn("Published", column => column.WithDefault(true)) ); await SchemaBuilder.AlterIndexTableAsync(table => table - .AddColumn("Latest", c => c.WithDefault(false)) + .AddColumn("Latest", column => column.WithDefault(false)) ); // So that the new indexes can be fully created. @@ -150,11 +150,11 @@ public async Task UpdateFrom4Async() // This step run only if the previous one was executed before // it was updated, so here we also add the following columns. await SchemaBuilder.AlterIndexTableAsync(table => table - .AddColumn("Published", c => c.WithDefault(true)) + .AddColumn("Published", column => column.WithDefault(true)) ); await SchemaBuilder.AlterIndexTableAsync(table => table - .AddColumn("Latest", c => c.WithDefault(false)) + .AddColumn("Latest", column => column.WithDefault(false)) ); // But we create a separate index for these new columns. diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Users/Migrations.cs index 1b4c650a6c9..7da40812583 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Migrations.cs @@ -20,11 +20,11 @@ public async Task CreateAsync() await SchemaBuilder.CreateMapIndexTableAsync(table => table .Column("NormalizedUserName") // TODO These should have defaults. on SQL Server they will fall at 255. Exceptions are currently thrown if you go over that. .Column("NormalizedEmail") - .Column("IsEnabled", c => c.NotNull().WithDefault(true)) - .Column("IsLockoutEnabled", c => c.NotNull().WithDefault(false)) - .Column("LockoutEndUtc", c => c.Nullable()) - .Column("AccessFailedCount", c => c.NotNull().WithDefault(0)) - .Column("UserId") + .Column("IsEnabled", column => column.NotNull().WithDefault(true)) + .Column("IsLockoutEnabled", column => column.NotNull().WithDefault(false)) + .Column("LockoutEndUtc", column => column.Nullable()) + .Column("AccessFailedCount", column => column.NotNull().WithDefault(0)) + .Column("UserId", column => column.NotNull()) ); await SchemaBuilder.AlterIndexTableAsync(table => table @@ -108,7 +108,7 @@ await SchemaBuilder.CreateMapIndexTableAsync(table => table public async Task UpdateFrom3Async() { await SchemaBuilder.AlterIndexTableAsync(table => table - .AddColumn("IsEnabled", c => c.NotNull().WithDefault(true))); + .AddColumn("IsEnabled", column => column.NotNull().WithDefault(true))); return 4; } @@ -118,7 +118,7 @@ await SchemaBuilder.AlterIndexTableAsync(table => table public async Task UpdateFrom4Async() { await SchemaBuilder.AlterIndexTableAsync(table => table - .AddColumn("UserId")); + .AddColumn("UserId", column => column.NotNull())); return 5; } @@ -220,13 +220,13 @@ await SchemaBuilder.AlterIndexTableAsync(table => table public async Task UpdateFrom10Async() { await SchemaBuilder.AlterIndexTableAsync(table => table - .AddColumn("IsLockoutEnabled", c => c.NotNull().WithDefault(false))); + .AddColumn("IsLockoutEnabled", column => column.NotNull().WithDefault(false))); await SchemaBuilder.AlterIndexTableAsync(table => table - .AddColumn("LockoutEndUtc", c => c.Nullable())); + .AddColumn("LockoutEndUtc", column => column.Nullable())); await SchemaBuilder.AlterIndexTableAsync(table => table - .AddColumn("AccessFailedCount", c => c.NotNull().WithDefault(0))); + .AddColumn("AccessFailedCount", column => column.NotNull().WithDefault(0))); return 11; } diff --git a/src/OrchardCore.Modules/OrchardCore.Workflows/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Workflows/Migrations.cs index 78a9a89bbde..a15ab762d54 100644 --- a/src/OrchardCore.Modules/OrchardCore.Workflows/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Workflows/Migrations.cs @@ -11,7 +11,7 @@ public class Migrations : DataMigration public async Task CreateAsync() { await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("WorkflowTypeId", c => c.WithLength(26)) + .Column("WorkflowTypeId", column => column.NotNull().WithLength(26)) .Column("Name") .Column("IsEnabled") .Column("HasStart") @@ -27,10 +27,10 @@ await SchemaBuilder.AlterIndexTableAsync(table => table ); await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("WorkflowTypeId") + .Column("WorkflowTypeId", column => column.NotNull().WithLength(26)) .Column("Name") .Column("IsEnabled") - .Column("StartActivityId") + .Column("StartActivityId", column => column.NotNull().WithLength(26)) .Column("StartActivityName") ); @@ -44,9 +44,9 @@ await SchemaBuilder.AlterIndexTableAsync(table ); await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("WorkflowTypeId", c => c.WithLength(26)) - .Column("WorkflowId", c => c.WithLength(26)) - .Column("WorkflowStatus", c => c.WithLength(26)) + .Column("WorkflowTypeId", column => column.WithLength(26)) + .Column("WorkflowId", column => column.WithLength(26)) + .Column("WorkflowStatus", column => column.WithLength(26)) .Column("CreatedUtc") ); @@ -60,12 +60,12 @@ await SchemaBuilder.AlterIndexTableAsync(table => table ); await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("ActivityId") + .Column("ActivityId", column => column.NotNull().WithLength(26)) .Column("ActivityName") .Column("ActivityIsStart") - .Column("WorkflowTypeId") - .Column("WorkflowId") - .Column("WorkflowCorrelationId") + .Column("WorkflowTypeId", column => column.NotNull().WithLength(26)) + .Column("WorkflowId", column => column.NotNull().WithLength(26)) + .Column("WorkflowCorrelationId", column => column.NotNull().WithLength(26)) ); await SchemaBuilder.AlterIndexTableAsync(table => table diff --git a/src/OrchardCore/OrchardCore.ContentManagement/Records/Migrations.cs b/src/OrchardCore/OrchardCore.ContentManagement/Records/Migrations.cs index e8dde362866..a221e2d6386 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement/Records/Migrations.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement/Records/Migrations.cs @@ -18,8 +18,8 @@ public Migrations(IContentDefinitionManager contentDefinitionManager) public async Task CreateAsync() { await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("ContentItemId", c => c.WithLength(26)) - .Column("ContentItemVersionId", c => c.WithLength(26)) + .Column("ContentItemId", column => column.NotNull().WithLength(26)) + .Column("ContentItemVersionId", column => column.NotNull().WithLength(26)) .Column("Latest") .Column("Published") .Column("ContentType", column => column.WithLength(ContentItemIndex.MaxContentTypeSize)) @@ -82,7 +82,7 @@ await SchemaBuilder.AlterIndexTableAsync(table => table public async Task UpdateFrom1Async() { await SchemaBuilder.AlterIndexTableAsync(table => table - .AddColumn("ContentItemVersionId", c => c.WithLength(26)) + .AddColumn("ContentItemVersionId", column => column.NotNull().WithLength(26)) ); return 2; diff --git a/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Migrations/OpenIdMigrations.cs b/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Migrations/OpenIdMigrations.cs index afaf9d56254..7123fd3431e 100644 --- a/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Migrations/OpenIdMigrations.cs +++ b/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Migrations/OpenIdMigrations.cs @@ -25,7 +25,7 @@ public OpenIdMigrations(ISession session) public async Task CreateAsync() { await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("ApplicationId", column => column.WithLength(48)) + .Column("ApplicationId", column => column.NotNull().WithLength(48)) .Column("ClientId", column => column.Unique()), collection: OpenIdApplicationCollection); @@ -68,8 +68,8 @@ await SchemaBuilder.AlterIndexTableAsync(table => tabl ); await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("AuthorizationId", column => column.WithLength(48)) - .Column("ApplicationId", column => column.WithLength(48)) + .Column("AuthorizationId", column => column.NotNull().WithLength(48)) + .Column("ApplicationId", column => column.NotNull().WithLength(48)) .Column("Status") .Column("Subject") .Column("Type") @@ -97,7 +97,7 @@ await SchemaBuilder.AlterIndexTableAsync(table => tabl await SchemaBuilder.CreateMapIndexTableAsync(table => table .Column("Name", column => column.Unique()) - .Column("ScopeId", column => column.WithLength(48)), + .Column("ScopeId", column => column.NotNull().WithLength(48)), collection: OpenIdScopeCollection); await SchemaBuilder.AlterIndexTableAsync(table => table @@ -120,9 +120,9 @@ await SchemaBuilder.AlterIndexTableAsync(table => ta ); await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("TokenId", column => column.WithLength(48)) - .Column("ApplicationId", column => column.WithLength(48)) - .Column("AuthorizationId", column => column.WithLength(48)) + .Column("TokenId", column => column.NotNull().WithLength(48)) + .Column("ApplicationId", column => column.NotNull().WithLength(48)) + .Column("AuthorizationId", column => column.NotNull().WithLength(48)) .Column("ExpirationDate") .Column("ReferenceId") .Column("Status") @@ -299,9 +299,9 @@ public async Task UpdateFrom6Async() { // Create all index tables with the new collection value. await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("TokenId", column => column.WithLength(48)) - .Column("ApplicationId", column => column.WithLength(48)) - .Column("AuthorizationId", column => column.WithLength(48)) + .Column("TokenId", column => column.NotNull().WithLength(48)) + .Column("ApplicationId", column => column.NotNull().WithLength(48)) + .Column("AuthorizationId", column => column.NotNull().WithLength(48)) .Column("ExpirationDate") .Column("ReferenceId") .Column("Status") @@ -339,8 +339,8 @@ await SchemaBuilder.AlterIndexTableAsync(table => table ); await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("AuthorizationId", column => column.WithLength(48)) - .Column("ApplicationId", column => column.WithLength(48)) + .Column("AuthorizationId", column => column.NotNull().WithLength(48)) + .Column("ApplicationId", column => column.NotNull().WithLength(48)) .Column("Status") .Column("Subject") .Column("Type") @@ -402,9 +402,9 @@ await SchemaBuilder.AlterIndexTableAsync(table => tabl // This code can be removed in a later version. public async Task UpdateFrom7Async() { - // Create all index tables with the new collection value. + // Create all index tables with the new collection value. await SchemaBuilder.CreateMapIndexTableAsync(table => table - .Column("ApplicationId", column => column.WithLength(48)) + .Column("ApplicationId", column => column.NotNull().WithLength(48)) .Column("ClientId", column => column.Unique()), collection: OpenIdApplicationCollection); diff --git a/test/OrchardCore.Tests/Apis/GraphQL/ContentItemsFieldTypeTests.cs b/test/OrchardCore.Tests/Apis/GraphQL/ContentItemsFieldTypeTests.cs index bacf775167f..933e54b6f23 100644 --- a/test/OrchardCore.Tests/Apis/GraphQL/ContentItemsFieldTypeTests.cs +++ b/test/OrchardCore.Tests/Apis/GraphQL/ContentItemsFieldTypeTests.cs @@ -83,8 +83,8 @@ private static async Task CreateTablesAsync(IStore store) var builder = new SchemaBuilder(store.Configuration, await session.BeginTransactionAsync()); await builder.CreateMapIndexTableAsync(table => table - .Column("ContentItemId", c => c.WithLength(26)) - .Column("ContentItemVersionId", c => c.WithLength(26)) + .Column("ContentItemId", column => column.NotNull().WithLength(26)) + .Column("ContentItemVersionId", column => column.NotNull().WithLength(26)) .Column("Latest") .Column("Published") .Column("ContentType", column => column.WithLength(ContentItemIndex.MaxContentTypeSize)) From ef0316e77f8563c3ff6b3fb35045481949f8578d Mon Sep 17 00:00:00 2001 From: Jasmin Savard Date: Fri, 19 Jan 2024 14:54:36 -0500 Subject: [PATCH 02/11] Revert for ContainedContentItemId --- src/OrchardCore.Modules/OrchardCore.Autoroute/Migrations.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Autoroute/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Autoroute/Migrations.cs index a2623011f29..d4355ecc34a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Autoroute/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Autoroute/Migrations.cs @@ -25,7 +25,7 @@ await _contentDefinitionManager.AlterPartDefinitionAsync("AutoroutePart", builde await SchemaBuilder.CreateMapIndexTableAsync(table => table .Column("ContentItemId", column => column.NotNull().WithLength(26)) - .Column("ContainedContentItemId", column => column.NotNull().WithLength(26)) + .Column("ContainedContentItemId", column => column.WithLength(26)) // Cannot be non-null .Column("JsonPath", column => column.Unlimited()) .Column("Path", column => column.WithLength(AutoroutePart.MaxPathLength)) .Column("Published") @@ -57,7 +57,7 @@ public int UpdateFrom2() public async Task UpdateFrom3Async() { await SchemaBuilder.AlterIndexTableAsync(table => table - .AddColumn("ContainedContentItemId", column => column.NotNull().WithLength(26)) + .AddColumn("ContainedContentItemId", column => column.WithLength(26)) ); await SchemaBuilder.AlterIndexTableAsync(table => table From 30104c72b05a0c7d1217c2d9ead88f606c6f2c12 Mon Sep 17 00:00:00 2001 From: Jasmin Savard Date: Fri, 19 Jan 2024 16:44:52 -0500 Subject: [PATCH 03/11] Revert NotNull for ContentItemVersionId --- .../OrchardCore.ContentManagement/Records/Migrations.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OrchardCore/OrchardCore.ContentManagement/Records/Migrations.cs b/src/OrchardCore/OrchardCore.ContentManagement/Records/Migrations.cs index a221e2d6386..34c1db32d92 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement/Records/Migrations.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement/Records/Migrations.cs @@ -19,7 +19,7 @@ public async Task CreateAsync() { await SchemaBuilder.CreateMapIndexTableAsync(table => table .Column("ContentItemId", column => column.NotNull().WithLength(26)) - .Column("ContentItemVersionId", column => column.NotNull().WithLength(26)) + .Column("ContentItemVersionId", column => column.WithLength(26)) // Cannot be not null .Column("Latest") .Column("Published") .Column("ContentType", column => column.WithLength(ContentItemIndex.MaxContentTypeSize)) @@ -82,7 +82,7 @@ await SchemaBuilder.AlterIndexTableAsync(table => table public async Task UpdateFrom1Async() { await SchemaBuilder.AlterIndexTableAsync(table => table - .AddColumn("ContentItemVersionId", column => column.NotNull().WithLength(26)) + .AddColumn("ContentItemVersionId", column => column.WithLength(26)) ); return 2; From 58b5ec5f013cf6900fb9c2455ee4d7967d2b973d Mon Sep 17 00:00:00 2001 From: Jasmin Savard Date: Fri, 19 Jan 2024 22:07:27 -0500 Subject: [PATCH 04/11] Update based on Kevin recommendations --- .../YesSql/Migrations/OpenIdMigrations.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Migrations/OpenIdMigrations.cs b/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Migrations/OpenIdMigrations.cs index 7123fd3431e..ec0a0312114 100644 --- a/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Migrations/OpenIdMigrations.cs +++ b/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Migrations/OpenIdMigrations.cs @@ -69,7 +69,7 @@ await SchemaBuilder.AlterIndexTableAsync(table => tabl await SchemaBuilder.CreateMapIndexTableAsync(table => table .Column("AuthorizationId", column => column.NotNull().WithLength(48)) - .Column("ApplicationId", column => column.NotNull().WithLength(48)) + .Column("ApplicationId", column => column.WithLength(48)) .Column("Status") .Column("Subject") .Column("Type") @@ -121,8 +121,8 @@ await SchemaBuilder.AlterIndexTableAsync(table => ta await SchemaBuilder.CreateMapIndexTableAsync(table => table .Column("TokenId", column => column.NotNull().WithLength(48)) - .Column("ApplicationId", column => column.NotNull().WithLength(48)) - .Column("AuthorizationId", column => column.NotNull().WithLength(48)) + .Column("ApplicationId", column => column.WithLength(48)) + .Column("AuthorizationId", column => column.WithLength(48)) .Column("ExpirationDate") .Column("ReferenceId") .Column("Status") @@ -300,8 +300,8 @@ public async Task UpdateFrom6Async() // Create all index tables with the new collection value. await SchemaBuilder.CreateMapIndexTableAsync(table => table .Column("TokenId", column => column.NotNull().WithLength(48)) - .Column("ApplicationId", column => column.NotNull().WithLength(48)) - .Column("AuthorizationId", column => column.NotNull().WithLength(48)) + .Column("ApplicationId", column => column.WithLength(48)) + .Column("AuthorizationId", column => column.WithLength(48)) .Column("ExpirationDate") .Column("ReferenceId") .Column("Status") @@ -340,7 +340,7 @@ await SchemaBuilder.AlterIndexTableAsync(table => table await SchemaBuilder.CreateMapIndexTableAsync(table => table .Column("AuthorizationId", column => column.NotNull().WithLength(48)) - .Column("ApplicationId", column => column.NotNull().WithLength(48)) + .Column("ApplicationId", column => column.WithLength(48)) .Column("Status") .Column("Subject") .Column("Type") From 062d3150b35d0425aa8f2dde29dbf4f3717427bb Mon Sep 17 00:00:00 2001 From: Jasmin Savard Date: Tue, 30 Jan 2024 00:51:02 -0500 Subject: [PATCH 05/11] Fix ContentItemVersionId Null issues --- .../OrchardCore.ContentManagement/DefaultContentManager.cs | 6 +++--- .../OrchardCore.ContentManagement/Records/Migrations.cs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs b/src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs index 62c4a508de2..67c4c8b3260 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs @@ -69,6 +69,8 @@ public async Task NewAsync(string contentType) var context2 = new ActivatedContentContext(context.ContentItem); context2.ContentItem.ContentItemId = _idGenerator.GenerateUniqueId(context2.ContentItem); + context2.ContentItem.ContentItemVersionId = _idGenerator.GenerateUniqueId(context2.ContentItem); + context2.ContentItem.Latest = true; await ReversedHandlers.InvokeAsync((handler, context2) => handler.ActivatedAsync(context2), context2, _logger); @@ -596,11 +598,9 @@ protected async Task> BuildNewVersionsAsync(IEnumerable public async Task CreateAsync(ContentItem contentItem, VersionOptions options) { - if (string.IsNullOrEmpty(contentItem.ContentItemVersionId)) + if (contentItem.Latest) { - contentItem.ContentItemVersionId = _idGenerator.GenerateUniqueId(contentItem); contentItem.Published = true; - contentItem.Latest = true; } // Draft flag on create is required for explicitly-published content items diff --git a/src/OrchardCore/OrchardCore.ContentManagement/Records/Migrations.cs b/src/OrchardCore/OrchardCore.ContentManagement/Records/Migrations.cs index 34c1db32d92..4e46d7567f4 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement/Records/Migrations.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement/Records/Migrations.cs @@ -19,7 +19,7 @@ public async Task CreateAsync() { await SchemaBuilder.CreateMapIndexTableAsync(table => table .Column("ContentItemId", column => column.NotNull().WithLength(26)) - .Column("ContentItemVersionId", column => column.WithLength(26)) // Cannot be not null + .Column("ContentItemVersionId", column => column.NotNull().WithLength(26)) // Cannot be not null .Column("Latest") .Column("Published") .Column("ContentType", column => column.WithLength(ContentItemIndex.MaxContentTypeSize)) @@ -82,7 +82,7 @@ await SchemaBuilder.AlterIndexTableAsync(table => table public async Task UpdateFrom1Async() { await SchemaBuilder.AlterIndexTableAsync(table => table - .AddColumn("ContentItemVersionId", column => column.WithLength(26)) + .AddColumn("ContentItemVersionId", column => column.NotNull().WithLength(26)) ); return 2; From 8b54a4cb040eeb49eb83ea3e81f813b8628321c2 Mon Sep 17 00:00:00 2001 From: Jasmin Savard Date: Tue, 30 Jan 2024 01:00:10 -0500 Subject: [PATCH 06/11] Simplify --- .../DefaultContentManager.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs b/src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs index 67c4c8b3260..91a0a1f32dc 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs @@ -598,10 +598,7 @@ protected async Task> BuildNewVersionsAsync(IEnumerable public async Task CreateAsync(ContentItem contentItem, VersionOptions options) { - if (contentItem.Latest) - { - contentItem.Published = true; - } + contentItem.Published = true; // Draft flag on create is required for explicitly-published content items if (options.IsDraft) @@ -609,6 +606,11 @@ public async Task CreateAsync(ContentItem contentItem, VersionOptions options) contentItem.Published = false; } + if (string.IsNullOrEmpty(contentItem.ContentItemVersionId)) + { + contentItem.ContentItemVersionId = _idGenerator.GenerateUniqueId(contentItem); + } + // Build a context with the initialized instance to create var context = new CreateContentContext(contentItem); From a14b402e149d0fbc87db983fa570ebc1ea2a5880 Mon Sep 17 00:00:00 2001 From: Jasmin Savard Date: Tue, 30 Jan 2024 14:03:59 -0500 Subject: [PATCH 07/11] Remove NotNull on AlterIndexTableAsync --- src/OrchardCore.Modules/OrchardCore.Lists/Migrations.cs | 2 +- src/OrchardCore.Modules/OrchardCore.PublishLater/Migrations.cs | 2 +- src/OrchardCore.Modules/OrchardCore.Users/Migrations.cs | 2 +- .../OrchardCore.ContentManagement/Records/Migrations.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Lists/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Lists/Migrations.cs index a4556003796..96ebcba7d6f 100644 --- a/src/OrchardCore.Modules/OrchardCore.Lists/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Lists/Migrations.cs @@ -77,7 +77,7 @@ await SchemaBuilder.AlterIndexTableAsync(table => table public async Task UpdateFrom3Async() { await SchemaBuilder.AlterIndexTableAsync(table => table - .AddColumn("ContentItemId", column => column.NotNull().WithLength(26)) + .AddColumn("ContentItemId", column => column.WithLength(26)) ); await SchemaBuilder.AlterIndexTableAsync(table => table diff --git a/src/OrchardCore.Modules/OrchardCore.PublishLater/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.PublishLater/Migrations.cs index 19f69eacc02..192d6b24312 100644 --- a/src/OrchardCore.Modules/OrchardCore.PublishLater/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.PublishLater/Migrations.cs @@ -67,7 +67,7 @@ public async Task UpdateFrom2Async() { await SchemaBuilder.AlterIndexTableAsync(table => { - table.AddColumn("ContentItemId", column => column.NotNull().WithLength(26)); + table.AddColumn("ContentItemId", column => column.WithLength(26)); table.AddColumn("Published"); table.AddColumn("Latest"); }); diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Users/Migrations.cs index 7da40812583..8e9440bd5ed 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Migrations.cs @@ -118,7 +118,7 @@ await SchemaBuilder.AlterIndexTableAsync(table => table public async Task UpdateFrom4Async() { await SchemaBuilder.AlterIndexTableAsync(table => table - .AddColumn("UserId", column => column.NotNull())); + .AddColumn("UserId")); return 5; } diff --git a/src/OrchardCore/OrchardCore.ContentManagement/Records/Migrations.cs b/src/OrchardCore/OrchardCore.ContentManagement/Records/Migrations.cs index 4e46d7567f4..d82e006a7ae 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement/Records/Migrations.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement/Records/Migrations.cs @@ -82,7 +82,7 @@ await SchemaBuilder.AlterIndexTableAsync(table => table public async Task UpdateFrom1Async() { await SchemaBuilder.AlterIndexTableAsync(table => table - .AddColumn("ContentItemVersionId", column => column.NotNull().WithLength(26)) + .AddColumn("ContentItemVersionId", column => column.WithLength(26)) ); return 2; From 09f045d8bbcb8f341401bf90036acee5643ba175 Mon Sep 17 00:00:00 2001 From: Jasmin Savard Date: Tue, 30 Jan 2024 14:07:25 -0500 Subject: [PATCH 08/11] Revert change on AlterIndexTableAsync --- src/OrchardCore.Modules/OrchardCore.PublishLater/Migrations.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.PublishLater/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.PublishLater/Migrations.cs index 192d6b24312..f0357429b8f 100644 --- a/src/OrchardCore.Modules/OrchardCore.PublishLater/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.PublishLater/Migrations.cs @@ -67,7 +67,7 @@ public async Task UpdateFrom2Async() { await SchemaBuilder.AlterIndexTableAsync(table => { - table.AddColumn("ContentItemId", column => column.WithLength(26)); + table.AddColumn("ContentItemId"); table.AddColumn("Published"); table.AddColumn("Latest"); }); From 851d9456989e4540364c1415d6139ad3f1ea21bd Mon Sep 17 00:00:00 2001 From: Jasmin Savard Date: Tue, 30 Jan 2024 20:40:44 -0500 Subject: [PATCH 09/11] Fix restore --- .../OrchardCore.ContentManagement/DefaultContentManager.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs b/src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs index 91a0a1f32dc..3f057c6fea5 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs @@ -834,6 +834,8 @@ public async Task RestoreAsync(ContentItem contentItem) await _session.SaveAsync(latestVersion); } + contentItem.Latest = true; + await CreateAsync(contentItem, VersionOptions.Draft); await ReversedHandlers.InvokeAsync((handler, context) => handler.RestoredAsync(context), context, _logger); From c43e0f59f294bfee460266f6c36135928ca500de Mon Sep 17 00:00:00 2001 From: Jasmin Savard Date: Tue, 30 Jan 2024 20:43:50 -0500 Subject: [PATCH 10/11] Add comment --- .../OrchardCore.ContentManagement/DefaultContentManager.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs b/src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs index 3f057c6fea5..2ef1f8c2302 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs @@ -834,6 +834,7 @@ public async Task RestoreAsync(ContentItem contentItem) await _session.SaveAsync(latestVersion); } + // Restored contentItem should always be set to be a draft contentItem.Latest = true; await CreateAsync(contentItem, VersionOptions.Draft); From 85bea5762d8147351fd8db4f7ddc0f2a8febbee2 Mon Sep 17 00:00:00 2001 From: Jasmin Savard Date: Tue, 30 Jan 2024 20:47:05 -0500 Subject: [PATCH 11/11] Better implementation --- .../OrchardCore.ContentManagement/DefaultContentManager.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs b/src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs index 2ef1f8c2302..07efee14732 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs @@ -603,6 +603,7 @@ public async Task CreateAsync(ContentItem contentItem, VersionOptions options) // Draft flag on create is required for explicitly-published content items if (options.IsDraft) { + contentItem.Latest = true; contentItem.Published = false; } @@ -834,9 +835,6 @@ public async Task RestoreAsync(ContentItem contentItem) await _session.SaveAsync(latestVersion); } - // Restored contentItem should always be set to be a draft - contentItem.Latest = true; - await CreateAsync(contentItem, VersionOptions.Draft); await ReversedHandlers.InvokeAsync((handler, context) => handler.RestoredAsync(context), context, _logger);