Skip to content

Commit d865448

Browse files
author
Paul Johnson
committed
Added database migration to support version cleanup feature
1 parent 9773726 commit d865448

File tree

7 files changed

+66
-1
lines changed

7 files changed

+66
-1
lines changed

src/Umbraco.Core/Migrations/Install/DatabaseSchemaCreator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ public DatabaseSchemaCreator(IUmbracoDatabase database, ILogger logger)
8585
typeof (AuditEntryDto),
8686
typeof (ContentVersionCultureVariationDto),
8787
typeof (DocumentCultureVariationDto),
88-
typeof (ContentScheduleDto)
88+
typeof (ContentScheduleDto),
89+
typeof (ContentVersionCleanupPolicyDto)
8990
};
9091

9192
/// <summary>

src/Umbraco.Core/Migrations/Upgrade/UmbracoPlan.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Umbraco.Core.Migrations.Upgrade.V_8_10_0;
1212
using Umbraco.Core.Migrations.Upgrade.V_8_15_0;
1313
using Umbraco.Core.Migrations.Upgrade.V_8_17_0;
14+
using Umbraco.Core.Migrations.Upgrade.V_8_18_0;
1415

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

213214
//FINAL
215+
To<AddContentVersionCleanupFeature>("{8BAF5E6C-DCB7-41AE-824F-4215AE4F1F98}");
214216
}
215217
}
216218
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Linq;
2+
using Umbraco.Core.Persistence.Dtos;
3+
4+
namespace Umbraco.Core.Migrations.Upgrade.V_8_18_0
5+
{
6+
class AddContentVersionCleanupFeature : MigrationBase
7+
{
8+
public AddContentVersionCleanupFeature(IMigrationContext context)
9+
: base(context) { }
10+
11+
public override void Migrate()
12+
{
13+
Create.Table<ContentVersionCleanupPolicyDto>().Do();
14+
15+
// What's this about, we worry someone else edited table with same change?
16+
var columns = SqlSyntax.GetColumnsInSchema(Context.Database).ToList();
17+
AddColumnIfNotExists<ContentVersionDto>(columns, "preventCleanup");
18+
}
19+
}
20+
}

src/Umbraco.Core/Persistence/Constants-DatabaseSchema.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public static class Tables
2626
public const string Content = TableNamePrefix + "Content";
2727
public const string ContentVersion = TableNamePrefix + "ContentVersion";
2828
public const string ContentVersionCultureVariation = TableNamePrefix + "ContentVersionCultureVariation";
29+
public const string ContentVersionCleanupPolicy = TableNamePrefix + "ContentVersionCleanupPolicy";
30+
2931
public const string Document = TableNamePrefix + "Document";
3032
public const string DocumentCultureVariation = TableNamePrefix + "DocumentCultureVariation";
3133
public const string DocumentVersion = TableNamePrefix + "DocumentVersion";
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using System.Data;
3+
using NPoco;
4+
using Umbraco.Core.Persistence.DatabaseAnnotations;
5+
6+
namespace Umbraco.Core.Persistence.Dtos
7+
{
8+
[TableName(TableName)]
9+
[PrimaryKey("contentTypeId")]
10+
[ExplicitColumns]
11+
internal class ContentVersionCleanupPolicyDto
12+
{
13+
public const string TableName = Constants.DatabaseSchema.Tables.ContentVersionCleanupPolicy;
14+
15+
[Column("contentTypeId")]
16+
[PrimaryKeyColumn(AutoIncrement = false)]
17+
[ForeignKey(typeof(ContentTypeDto), Column = "nodeId", OnDelete = Rule.Cascade)]
18+
public int ContentTypeId { get; set; }
19+
20+
[Column("keepAllVersionsNewerThanDays")]
21+
[NullSetting(NullSetting = NullSettings.Null)]
22+
public int? KeepAllVersionsNewerThanDays { get; set; }
23+
24+
[Column("keepLatestVersionPerDayForDays")]
25+
[NullSetting(NullSetting = NullSettings.Null)]
26+
public int? KeepLatestVersionPerDayForDays { get; set; }
27+
28+
[Column("preventCleanup")]
29+
public bool PreventCleanup { get; set; }
30+
31+
[Column("updated")]
32+
public DateTime Updated { get; set; }
33+
}
34+
}

src/Umbraco.Core/Persistence/Dtos/ContentVersionDto.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,9 @@ internal class ContentVersionDto
4949
[ResultColumn]
5050
[Reference(ReferenceType.OneToOne, ColumnName = "NodeId", ReferenceMemberName = "NodeId")]
5151
public ContentDto ContentDto { get; set; }
52+
53+
[Column("preventCleanup")]
54+
[Constraint(Default = "0")]
55+
public bool PreventCleanup { get; set; }
5256
}
5357
}

src/Umbraco.Core/Umbraco.Core.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
<Compile Include="Migrations\Upgrade\V_8_15_0\UpgradedIncludeIndexes.cs" />
149149
<Compile Include="Migrations\Upgrade\V_8_10_0\AddPropertyTypeLabelOnTopColumn.cs" />
150150
<Compile Include="Migrations\Upgrade\V_8_17_0\AddPropertyTypeGroupColumns.cs" />
151+
<Compile Include="Migrations\Upgrade\V_8_18_0\AddContentVersionCleanupFeature.cs" />
151152
<Compile Include="Migrations\Upgrade\V_8_9_0\ExternalLoginTableUserData.cs" />
152153
<Compile Include="Models\Blocks\BlockEditorDataConverter.cs" />
153154
<Compile Include="Models\Blocks\BlockEditorData.cs" />
@@ -174,6 +175,7 @@
174175
<Compile Include="Persistence\Dtos\ColumnInSchemaDto.cs" />
175176
<Compile Include="Persistence\Dtos\ConstraintPerColumnDto.cs" />
176177
<Compile Include="Persistence\Dtos\ConstraintPerTableDto.cs" />
178+
<Compile Include="Persistence\Dtos\ContentVersionCleanupPolicyDto.cs" />
177179
<Compile Include="Persistence\Dtos\DefaultConstraintPerColumnDto.cs" />
178180
<Compile Include="Persistence\Dtos\UserNotificationDto.cs" />
179181
<Compile Include="Persistence\Repositories\IInstallationRepository.cs" />

0 commit comments

Comments
 (0)