Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding missing database indices (ORCH-26) #7744

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
66 changes: 39 additions & 27 deletions src/Orchard.Web/Core/Common/Migrations.cs
Expand Up @@ -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("BodyPartRecord", table => table
.ContentPartVersionRecord()
.Column<string>("Text", column => column.Unlimited())
.Column<string>("Format"));

SchemaBuilder.CreateTable("CommonPartRecord",
table => table
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()
Expand All @@ -67,15 +68,14 @@ public class Migrations : DataMigrationImpl {
.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;
Expand Down Expand Up @@ -103,8 +103,10 @@ public class Migrations : DataMigrationImpl {
}
}

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);
Expand All @@ -116,8 +118,11 @@ public class Migrations : DataMigrationImpl {

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;
}

Expand All @@ -136,5 +141,12 @@ public class Migrations : DataMigrationImpl {

return 6;
}

public int UpdateFrom6() {
SchemaBuilder.AlterTable(nameof(IdentityPartRecord), table => table
.CreateIndex($"IDX_{nameof(IdentityPartRecord)}_{nameof(IdentityPartRecord.Identifier)}", nameof(IdentityPartRecord.Identifier)));

return 7;
}
}
}
41 changes: 23 additions & 18 deletions src/Orchard.Web/Modules/Orchard.Users/Migrations.cs
Expand Up @@ -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")
Expand All @@ -23,12 +23,13 @@ public class UsersDataMigration : DataMigrationImpl {
.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() {
Expand All @@ -38,31 +39,35 @@ public class UsersDataMigration : DataMigrationImpl {
}

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;
}
}
}