Skip to content

Commit

Permalink
Added database migration to support version cleanup feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Johnson committed Oct 26, 2021
1 parent 9773726 commit d865448
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Umbraco.Core/Migrations/Install/DatabaseSchemaCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public DatabaseSchemaCreator(IUmbracoDatabase database, ILogger logger)
typeof (AuditEntryDto),
typeof (ContentVersionCultureVariationDto),
typeof (DocumentCultureVariationDto),
typeof (ContentScheduleDto)
typeof (ContentScheduleDto),
typeof (ContentVersionCleanupPolicyDto)
};

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Umbraco.Core/Migrations/Upgrade/UmbracoPlan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Umbraco.Core.Migrations.Upgrade.V_8_10_0;
using Umbraco.Core.Migrations.Upgrade.V_8_15_0;
using Umbraco.Core.Migrations.Upgrade.V_8_17_0;
using Umbraco.Core.Migrations.Upgrade.V_8_18_0;

namespace Umbraco.Core.Migrations.Upgrade
{
Expand Down Expand Up @@ -211,6 +212,7 @@ protected void DefinePlan()
To<AddPropertyTypeGroupColumns>("{153865E9-7332-4C2A-9F9D-F20AEE078EC7}");

//FINAL
To<AddContentVersionCleanupFeature>("{8BAF5E6C-DCB7-41AE-824F-4215AE4F1F98}");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Linq;
using Umbraco.Core.Persistence.Dtos;

namespace Umbraco.Core.Migrations.Upgrade.V_8_18_0
{
class AddContentVersionCleanupFeature : MigrationBase
{
public AddContentVersionCleanupFeature(IMigrationContext context)
: base(context) { }

public override void Migrate()
{
Create.Table<ContentVersionCleanupPolicyDto>().Do();

// What's this about, we worry someone else edited table with same change?
var columns = SqlSyntax.GetColumnsInSchema(Context.Database).ToList();
AddColumnIfNotExists<ContentVersionDto>(columns, "preventCleanup");
}
}
}
2 changes: 2 additions & 0 deletions src/Umbraco.Core/Persistence/Constants-DatabaseSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public static class Tables
public const string Content = TableNamePrefix + "Content";
public const string ContentVersion = TableNamePrefix + "ContentVersion";
public const string ContentVersionCultureVariation = TableNamePrefix + "ContentVersionCultureVariation";
public const string ContentVersionCleanupPolicy = TableNamePrefix + "ContentVersionCleanupPolicy";

public const string Document = TableNamePrefix + "Document";
public const string DocumentCultureVariation = TableNamePrefix + "DocumentCultureVariation";
public const string DocumentVersion = TableNamePrefix + "DocumentVersion";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Data;
using NPoco;
using Umbraco.Core.Persistence.DatabaseAnnotations;

namespace Umbraco.Core.Persistence.Dtos
{
[TableName(TableName)]
[PrimaryKey("contentTypeId")]
[ExplicitColumns]
internal class ContentVersionCleanupPolicyDto
{
public const string TableName = Constants.DatabaseSchema.Tables.ContentVersionCleanupPolicy;

[Column("contentTypeId")]
[PrimaryKeyColumn(AutoIncrement = false)]
[ForeignKey(typeof(ContentTypeDto), Column = "nodeId", OnDelete = Rule.Cascade)]
public int ContentTypeId { get; set; }

[Column("keepAllVersionsNewerThanDays")]
[NullSetting(NullSetting = NullSettings.Null)]
public int? KeepAllVersionsNewerThanDays { get; set; }

[Column("keepLatestVersionPerDayForDays")]
[NullSetting(NullSetting = NullSettings.Null)]
public int? KeepLatestVersionPerDayForDays { get; set; }

[Column("preventCleanup")]
public bool PreventCleanup { get; set; }

[Column("updated")]
public DateTime Updated { get; set; }
}
}
4 changes: 4 additions & 0 deletions src/Umbraco.Core/Persistence/Dtos/ContentVersionDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,9 @@ internal class ContentVersionDto
[ResultColumn]
[Reference(ReferenceType.OneToOne, ColumnName = "NodeId", ReferenceMemberName = "NodeId")]
public ContentDto ContentDto { get; set; }

[Column("preventCleanup")]
[Constraint(Default = "0")]
public bool PreventCleanup { get; set; }
}
}
2 changes: 2 additions & 0 deletions src/Umbraco.Core/Umbraco.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
<Compile Include="Migrations\Upgrade\V_8_15_0\UpgradedIncludeIndexes.cs" />
<Compile Include="Migrations\Upgrade\V_8_10_0\AddPropertyTypeLabelOnTopColumn.cs" />
<Compile Include="Migrations\Upgrade\V_8_17_0\AddPropertyTypeGroupColumns.cs" />
<Compile Include="Migrations\Upgrade\V_8_18_0\AddContentVersionCleanupFeature.cs" />
<Compile Include="Migrations\Upgrade\V_8_9_0\ExternalLoginTableUserData.cs" />
<Compile Include="Models\Blocks\BlockEditorDataConverter.cs" />
<Compile Include="Models\Blocks\BlockEditorData.cs" />
Expand All @@ -174,6 +175,7 @@
<Compile Include="Persistence\Dtos\ColumnInSchemaDto.cs" />
<Compile Include="Persistence\Dtos\ConstraintPerColumnDto.cs" />
<Compile Include="Persistence\Dtos\ConstraintPerTableDto.cs" />
<Compile Include="Persistence\Dtos\ContentVersionCleanupPolicyDto.cs" />
<Compile Include="Persistence\Dtos\DefaultConstraintPerColumnDto.cs" />
<Compile Include="Persistence\Dtos\UserNotificationDto.cs" />
<Compile Include="Persistence\Repositories\IInstallationRepository.cs" />
Expand Down

0 comments on commit d865448

Please sign in to comment.