#19665: Changing IdentityPart column size to 255

History:
* Removing reference to System.Data
* Limiting IdentityPartRecord's Identifier column to 255
* Correct migration to IdentityPartRecord's Identifier column
* Performing migration through IRepository

Work Item: 19665

--HG--
branch : 1.x
extra : rebase_source : 71e396d703d3d6cd4226bcc8b6f081a01df07e54
This commit is contained in:
StanleyGoldman
2013-05-01 13:59:19 -04:00
parent 453286e347
commit 81ffec71b9

View File

@@ -1,10 +1,19 @@
using System;
using System.Linq;
using Orchard.ContentManagement.MetaData;
using Orchard.Core.Common.Models;
using Orchard.Core.Contents.Extensions;
using Orchard.Data;
using Orchard.Data.Migration;
namespace Orchard.Core.Common {
public class Migrations : DataMigrationImpl {
private readonly IRepository<IdentityPartRecord> _identityPartRepository;
public Migrations(IRepository<IdentityPartRecord> identityPartRepository) {
_identityPartRepository = identityPartRepository;
}
public int Create() {
SchemaBuilder.CreateTable("BodyPartRecord",
table => table
@@ -34,7 +43,7 @@ namespace Orchard.Core.Common {
SchemaBuilder.CreateTable("IdentityPartRecord",
table => table
.ContentPartRecord()
.Column<string>("Identifier", column => column.Unlimited())
.Column<string>("Identifier", column => column.WithLength(255))
);
ContentDefinitionManager.AlterPartDefinition("BodyPart", builder => builder
@@ -49,7 +58,7 @@ namespace Orchard.Core.Common {
.Attachable()
.WithDescription("Automatically generates a unique identity for the content item, which is required in import/export scenarios where one content item references another."));
return 3;
return 4;
}
public int UpdateFrom1() {
@@ -75,5 +84,28 @@ namespace Orchard.Core.Common {
return 3;
}
public int UpdateFrom3() {
var existingIdentityParts = _identityPartRepository.Table.ToArray();
foreach (var existingIdentityPart in existingIdentityParts) {
if (existingIdentityPart.Identifier.Length > 255) {
throw new ArgumentException("Identifier '" + existingIdentityPart + "' is over 255 characters");
}
}
SchemaBuilder.AlterTable("IdentityPartRecord", table => table.DropColumn("Identifier"));
SchemaBuilder.AlterTable("IdentityPartRecord", table => table.AddColumn<string>("Identifier", command => command.WithLength(255)));
foreach (var existingIdentityPart in existingIdentityParts) {
var updateIdentityPartRecord = _identityPartRepository.Get(existingIdentityPart.Id);
updateIdentityPartRecord.Identifier = existingIdentityPart.Identifier;
_identityPartRepository.Update(updateIdentityPartRecord);
}
return 4;
}
}
}