Add primary key column attribute to ContentVersionCleanupPolicyDto.cs (#12684)
* Add primary key column attribute to ContentVersionCleanupPolicyDto.cs * Test pipelines * Revert "Test pipelines" This reverts commit a8f654ebb7279de9ed83cf99108cb67cb292cbb2. * test commit for pipelines * Revert "test commit for pipelines" This reverts commit ab03f977f4726f2ca40d075877749f4482244604. * Dont cascade delete Signed-off-by: Zeegaan <nge@umbraco.dk> * Remove unneccesary delete clause Signed-off-by: Zeegaan <nge@umbraco.dk> * Remove added whitespace Signed-off-by: Zeegaan <nge@umbraco.dk> * Revert "Remove unneccesary delete clause" This reverts commit 4b2b665169c318a0cd4650c3d6bb13c304d11a4b. * Disable identity for PK * Add PK migration * formatting * Keep latest entry Signed-off-by: Zeegaan <nge@umbraco.dk> Co-authored-by: Zeegaan <nge@umbraco.dk>
This commit is contained in:
@@ -5,6 +5,7 @@ using Umbraco.Cms.Core.Semver;
|
||||
using Umbraco.Cms.Infrastructure.Migrations.Upgrade.Common;
|
||||
using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_10_0_0;
|
||||
using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_10_2_0;
|
||||
using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_10_5_0;
|
||||
using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_0;
|
||||
using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_0_1;
|
||||
using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_8_1_0;
|
||||
@@ -299,5 +300,8 @@ public class UmbracoPlan : MigrationPlan
|
||||
|
||||
// To 10.4.0
|
||||
To<V_10_4_0.AddBlockGridPartialViews>("{3F5D492A-A3DB-43F9-A73E-9FEE3B180E6C}");
|
||||
|
||||
// to 10.5.0
|
||||
To<AddPrimaryKeyConstrainToContentVersionCleanupDtos>("{83AF7945-DADE-4A02-9041-F3F6EBFAC319}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
using Umbraco.Cms.Infrastructure.Persistence.Dtos;
|
||||
|
||||
namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_10_5_0;
|
||||
|
||||
public class AddPrimaryKeyConstrainToContentVersionCleanupDtos : MigrationBase
|
||||
{
|
||||
public AddPrimaryKeyConstrainToContentVersionCleanupDtos(IMigrationContext context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Migrate()
|
||||
{
|
||||
IEnumerable<ContentVersionCleanupPolicyDto> contentVersionCleanupPolicyDtos =
|
||||
Database
|
||||
.Fetch<ContentVersionCleanupPolicyDto>()
|
||||
.OrderByDescending(x => x.Updated)
|
||||
.DistinctBy(x => x.ContentTypeId);
|
||||
|
||||
if (TableExists(ContentVersionCleanupPolicyDto.TableName))
|
||||
{
|
||||
Delete.Table(ContentVersionCleanupPolicyDto.TableName).Do();
|
||||
}
|
||||
|
||||
Create.Table<ContentVersionCleanupPolicyDto>().Do();
|
||||
Database.InsertBatch(contentVersionCleanupPolicyDtos);
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,8 @@ internal class ContentVersionCleanupPolicyDto
|
||||
public const string TableName = Constants.DatabaseSchema.Tables.ContentVersionCleanupPolicy;
|
||||
|
||||
[Column("contentTypeId")]
|
||||
[ForeignKey(typeof(ContentTypeDto), Column = "nodeId", OnDelete = Rule.Cascade)]
|
||||
[PrimaryKeyColumn(AutoIncrement = false)]
|
||||
[ForeignKey(typeof(ContentTypeDto), Column = "nodeId")]
|
||||
public int ContentTypeId { get; set; }
|
||||
|
||||
[Column("preventCleanup")]
|
||||
|
||||
@@ -180,6 +180,7 @@ internal class ContentTypeRepository : ContentTypeRepositoryBase<IContentType>,
|
||||
protected override IEnumerable<string> GetDeleteClauses()
|
||||
{
|
||||
var l = (List<string>)base.GetDeleteClauses(); // we know it's a list
|
||||
l.Add("DELETE FROM umbracoContentVersionCleanupPolicy WHERE contentTypeId = @id");
|
||||
l.Add("DELETE FROM cmsDocumentType WHERE contentTypeNodeId = @id");
|
||||
l.Add("DELETE FROM cmsContentType WHERE nodeId = @id");
|
||||
l.Add("DELETE FROM umbracoNode WHERE id = @id");
|
||||
|
||||
Reference in New Issue
Block a user