Skip to content

Commit

Permalink
Fixing that Projection Migrations created indexes with the same name …
Browse files Browse the repository at this point in the history
…in different tables, which is not supported by PostgreSQL
  • Loading branch information
BenedekFarkas committed Nov 26, 2024
1 parent 289a0ba commit 4b21f0e
Showing 1 changed file with 46 additions and 24 deletions.
70 changes: 46 additions & 24 deletions src/Orchard.Web/Modules/Orchard.Projections/Migrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,7 @@ public int Create() {
SchemaBuilder.CreateTable("FieldIndexPartRecord", table => table.ContentPartRecord());

//Adds indexes for better performances in queries
SchemaBuilder.AlterTable("StringFieldIndexRecord", table => table.CreateIndex("IX_PropertyName", new string[] { "PropertyName" }));
SchemaBuilder.AlterTable("StringFieldIndexRecord", table => table.CreateIndex("IX_FieldIndexPartRecord_Id", new string[] { "FieldIndexPartRecord_Id" }));

SchemaBuilder.AlterTable("IntegerFieldIndexRecord", table => table.CreateIndex("IX_PropertyName", new string[] { "PropertyName" }));
SchemaBuilder.AlterTable("IntegerFieldIndexRecord", table => table.CreateIndex("IX_FieldIndexPartRecord_Id", new string[] { "FieldIndexPartRecord_Id" }));

SchemaBuilder.AlterTable("DoubleFieldIndexRecord", table => table.CreateIndex("IX_PropertyName", new string[] { "PropertyName" }));
SchemaBuilder.AlterTable("DoubleFieldIndexRecord", table => table.CreateIndex("IX_FieldIndexPartRecord_Id", new string[] { "FieldIndexPartRecord_Id" }));

SchemaBuilder.AlterTable("DecimalFieldIndexRecord", table => table.CreateIndex("IX_PropertyName", new string[] { "PropertyName" }));
SchemaBuilder.AlterTable("DecimalFieldIndexRecord", table => table.CreateIndex("IX_FieldIndexPartRecord_Id", new string[] { "FieldIndexPartRecord_Id" }));
AddPropertyNameAndFieldIndexPartRecordIdIndexes();

// Query

Expand Down Expand Up @@ -287,7 +277,7 @@ public int Create() {
Description = T("The text from the Body part").Text
});

return 6;
return 8;
}

public int UpdateFrom1() {
Expand Down Expand Up @@ -343,17 +333,7 @@ public int UpdateFrom4() {
.AddColumn<decimal>("LatestValue"));

//Adds indexes for better performances in queries
SchemaBuilder.AlterTable("StringFieldIndexRecord", table => table.CreateIndex("IX_PropertyName", new string[] { "PropertyName" }));
SchemaBuilder.AlterTable("StringFieldIndexRecord", table => table.CreateIndex("IX_FieldIndexPartRecord_Id", new string[] { "FieldIndexPartRecord_Id" }));

SchemaBuilder.AlterTable("IntegerFieldIndexRecord", table => table.CreateIndex("IX_PropertyName", new string[] { "PropertyName" }));
SchemaBuilder.AlterTable("IntegerFieldIndexRecord", table => table.CreateIndex("IX_FieldIndexPartRecord_Id", new string[] { "FieldIndexPartRecord_Id" }));

SchemaBuilder.AlterTable("DoubleFieldIndexRecord", table => table.CreateIndex("IX_PropertyName", new string[] { "PropertyName" }));
SchemaBuilder.AlterTable("DoubleFieldIndexRecord", table => table.CreateIndex("IX_FieldIndexPartRecord_Id", new string[] { "FieldIndexPartRecord_Id" }));

SchemaBuilder.AlterTable("DecimalFieldIndexRecord", table => table.CreateIndex("IX_PropertyName", new string[] { "PropertyName" }));
SchemaBuilder.AlterTable("DecimalFieldIndexRecord", table => table.CreateIndex("IX_FieldIndexPartRecord_Id", new string[] { "FieldIndexPartRecord_Id" }));
AddPropertyNameAndFieldIndexPartRecordIdIndexes();

SchemaBuilder.AlterTable("QueryPartRecord", table => table
.AddColumn<string>("VersionScope", c => c.WithLength(15)));
Expand Down Expand Up @@ -386,5 +366,47 @@ public int UpdateFrom6() {

return 7;
}

public int UpdateFrom7() {
SchemaBuilder.AlterTable("StringFieldIndexRecord", table => {
table.DropIndex("IX_PropertyName");
table.DropIndex("IX_FieldIndexPartRecord_Id");
});
SchemaBuilder.AlterTable("IntegerFieldIndexRecord", table => {
table.DropIndex("IX_PropertyName");
table.DropIndex("IX_FieldIndexPartRecord_Id");
});
SchemaBuilder.AlterTable("DoubleFieldIndexRecord", table => {
table.DropIndex("IX_PropertyName");
table.DropIndex("IX_FieldIndexPartRecord_Id");
});
SchemaBuilder.AlterTable("DecimalFieldIndexRecord", table => {
table.DropIndex("IX_PropertyName");
table.DropIndex("IX_FieldIndexPartRecord_Id");
});

AddPropertyNameAndFieldIndexPartRecordIdIndexes();

return 8;
}

private void AddPropertyNameAndFieldIndexPartRecordIdIndexes() {
SchemaBuilder.AlterTable("StringFieldIndexRecord", table => {
table.CreateIndex("IDX_StringFieldIndexRecord_PropertyName", "PropertyName");
table.CreateIndex("IDX_StringFieldIndexRecord_FieldIndexPartRecord_Id", "FieldIndexPartRecord_Id");
});
SchemaBuilder.AlterTable("IntegerFieldIndexRecord", table => {
table.CreateIndex("IDX_IntegerFieldIndexRecord_PropertyName", "PropertyName");
table.CreateIndex("IDX_IntegerFieldIndexRecord_FieldIndexPartRecord_Id", "FieldIndexPartRecord_Id");
});
SchemaBuilder.AlterTable("DoubleFieldIndexRecord", table => {
table.CreateIndex("IDX_DoubleFieldIndexRecord_PropertyName", "PropertyName");
table.CreateIndex("IDX_DoubleFieldIndexRecord_FieldIndexPartRecord_Id", "FieldIndexPartRecord_Id");
});
SchemaBuilder.AlterTable("DecimalFieldIndexRecord", table => {
table.CreateIndex("IDX_DecimalFieldIndexRecord_PropertyName", "PropertyName");
table.CreateIndex("IDX_DecimalFieldIndexRecord_FieldIndexPartRecord_Id", "FieldIndexPartRecord_Id");
});
}
}
}
}

0 comments on commit 4b21f0e

Please sign in to comment.