Core/Common and Users: Adding indices to IdentityPartRecord.Identifier and UserPartRecord.NormalizedUserName (#8269)

Lombiq Technologies: ORCH-26
This commit is contained in:
Benedek Farkas 2019-08-26 20:16:30 +02:00 committed by GitHub
parent 2db5255467
commit a3602ce7b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 63 additions and 46 deletions

View File

@ -10,50 +10,51 @@ 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
.ContentPartVersionRecord()
.Column<string>("Text", column => column.Unlimited())
.Column<string>("Format")
);
SchemaBuilder.CreateTable("CommonPartRecord",
table => table
public int Create() {
SchemaBuilder.CreateTable("BodyPartRecord", table => table
.ContentPartVersionRecord()
.Column<string>("Text", column => column.Unlimited())
.Column<string>("Format"));
SchemaBuilder
.CreateTable("CommonPartRecord", table => table
.ContentPartRecord()
.Column<int>("OwnerId")
.Column<DateTime>("CreatedUtc")
.Column<DateTime>("PublishedUtc")
.Column<DateTime>("ModifiedUtc")
.Column<int>("Container_id")
).AlterTable(nameof(CommonPartRecord), table => {
.Column<int>("Container_id"))
.AlterTable(nameof(CommonPartRecord), table => {
table.CreateIndex($"IDX_{nameof(CommonPartRecord)}_{nameof(CommonPartRecord.CreatedUtc)}", nameof(CommonPartRecord.CreatedUtc));
table.CreateIndex($"IDX_{nameof(CommonPartRecord)}_{nameof(CommonPartRecord.ModifiedUtc)}", nameof(CommonPartRecord.ModifiedUtc));
table.CreateIndex($"IDX_{nameof(CommonPartRecord)}_{nameof(CommonPartRecord.PublishedUtc)}", nameof(CommonPartRecord.PublishedUtc));
});
SchemaBuilder.CreateTable("CommonPartVersionRecord",
table => table
SchemaBuilder
.CreateTable("CommonPartVersionRecord", table => table
.ContentPartVersionRecord()
.Column<DateTime>("CreatedUtc")
.Column<DateTime>("PublishedUtc")
.Column<DateTime>("ModifiedUtc")
.Column<string>("ModifiedBy")
).AlterTable(nameof(CommonPartVersionRecord), table => {
.Column<string>("ModifiedBy"))
.AlterTable(nameof(CommonPartVersionRecord), table => {
table.CreateIndex($"IDX_{nameof(CommonPartVersionRecord)}_{nameof(CommonPartVersionRecord.CreatedUtc)}", nameof(CommonPartVersionRecord.CreatedUtc));
table.CreateIndex($"IDX_{nameof(CommonPartVersionRecord)}_{nameof(CommonPartVersionRecord.ModifiedUtc)}", nameof(CommonPartVersionRecord.ModifiedUtc));
table.CreateIndex($"IDX_{nameof(CommonPartVersionRecord)}_{nameof(CommonPartVersionRecord.PublishedUtc)}", nameof(CommonPartVersionRecord.PublishedUtc));
});
SchemaBuilder.CreateTable("IdentityPartRecord",
table => table
SchemaBuilder
.CreateTable(nameof(IdentityPartRecord), table => table
.ContentPartRecord()
.Column<string>("Identifier", column => column.WithLength(255))
);
.Column<string>("Identifier", column => column.WithLength(255)))
.AlterTable(nameof(IdentityPartRecord), table => table
.CreateIndex($"IDX_{nameof(IdentityPartRecord)}_{nameof(IdentityPartRecord.Identifier)}", nameof(IdentityPartRecord.Identifier)));
ContentDefinitionManager.AlterPartDefinition("BodyPart", builder => builder
.Attachable()
@ -67,15 +68,14 @@ 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 6;
return 7;
}
public int UpdateFrom1() {
SchemaBuilder.CreateTable("IdentityPartRecord",
table => table
.ContentPartRecord()
.Column<string>("Identifier", column => column.Unlimited())
);
SchemaBuilder.CreateTable("IdentityPartRecord", table => table
.ContentPartRecord()
.Column<string>("Identifier", column => column.Unlimited()));
ContentDefinitionManager.AlterPartDefinition("IdentityPart", builder => builder.Attachable());
return 2;
@ -103,8 +103,10 @@ namespace Orchard.Core.Common {
}
}
SchemaBuilder.AlterTable("IdentityPartRecord", table => table.DropColumn("Identifier"));
SchemaBuilder.AlterTable("IdentityPartRecord", table => table.AddColumn<string>("Identifier", command => command.WithLength(255)));
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);
@ -116,8 +118,11 @@ namespace Orchard.Core.Common {
return 4;
}
public int UpdateFrom4() {
SchemaBuilder.AlterTable("CommonPartVersionRecord", table => table.AddColumn<string>("ModifiedBy", command => command.Nullable()));
SchemaBuilder.AlterTable("CommonPartVersionRecord", table => table
.AddColumn<string>("ModifiedBy", command => command.Nullable()));
return 5;
}
@ -136,5 +141,12 @@ namespace Orchard.Core.Common {
return 6;
}
public int UpdateFrom6() {
SchemaBuilder.AlterTable(nameof(IdentityPartRecord), table => table
.CreateIndex($"IDX_{nameof(IdentityPartRecord)}_{nameof(IdentityPartRecord.Identifier)}", nameof(IdentityPartRecord.Identifier)));
return 7;
}
}
}

View File

@ -7,8 +7,8 @@ namespace Orchard.Users {
public class UsersDataMigration : DataMigrationImpl {
public int Create() {
SchemaBuilder.CreateTable("UserPartRecord",
table => table
SchemaBuilder
.CreateTable("UserPartRecord", table => table
.ContentPartRecord()
.Column<string>("UserName")
.Column<string>("Email")
@ -23,12 +23,13 @@ namespace Orchard.Users {
.Column<DateTime>("CreatedUtc")
.Column<DateTime>("LastLoginUtc")
.Column<DateTime>("LastLogoutUtc")
.Column<DateTime>("LastPasswordChangeUtc", c => c.WithDefault(new DateTime(1990, 1, 1)))
);
.Column<DateTime>("LastPasswordChangeUtc", c => c.WithDefault(new DateTime(1990, 1, 1))))
.AlterTable("UserPartRecord", table => table
.CreateIndex("IDX_UserPartRecord_NormalizedUserName", "NormalizedUserName"));
ContentDefinitionManager.AlterTypeDefinition("User", cfg => cfg.Creatable(false));
return 5;
return 6;
}
public int UpdateFrom1() {
@ -38,31 +39,35 @@ namespace Orchard.Users {
}
public int UpdateFrom2() {
SchemaBuilder.AlterTable("UserPartRecord",
table => {
table.AddColumn<DateTime>("CreatedUtc");
table.AddColumn<DateTime>("LastLoginUtc");
});
SchemaBuilder.AlterTable("UserPartRecord", table => {
table.AddColumn<DateTime>("CreatedUtc");
table.AddColumn<DateTime>("LastLoginUtc");
});
return 3;
}
public int UpdateFrom3() {
SchemaBuilder.AlterTable("UserPartRecord",
table => {
table.AddColumn<DateTime>("LastLogoutUtc");
});
SchemaBuilder.AlterTable("UserPartRecord", table => {
table.AddColumn<DateTime>("LastLogoutUtc");
});
return 4;
}
public int UpdateFrom4() {
SchemaBuilder.AlterTable("UserPartRecord",
table => {
table.AddColumn<DateTime>("LastPasswordChangeUtc", c => c.WithDefault(new DateTime(1990, 1, 1)));
});
SchemaBuilder.AlterTable("UserPartRecord", table => {
table.AddColumn<DateTime>("LastPasswordChangeUtc", c => c.WithDefault(new DateTime(1990, 1, 1)));
});
return 5;
}
public int UpdateFrom5() {
SchemaBuilder.AlterTable("UserPartRecord", table => table
.CreateIndex("IDX_UserPartRecord_NormalizedUserName", "NormalizedUserName"));
return 6;
}
}
}