Skip to content

Commit

Permalink
Set index length limit for MySQL
Browse files Browse the repository at this point in the history
Fix #14338
  • Loading branch information
MikeAlhayek committed Oct 12, 2023
1 parent 600d214 commit d1e60dc
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 68 deletions.
7 changes: 3 additions & 4 deletions src/OrchardCore.Modules/OrchardCore.Alias/Migrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,19 @@ public int Create()
.Attachable()
.WithDescription("Provides a way to define custom aliases for content items."));

// NOTE: The Alias Length has been upgraded from 64 characters to 767.
// For existing SQL databases update the AliasPartIndex tables Alias column length manually.
// INFO: The Alias Length is now of 735 chars, but this is only used on a new installation.
SchemaBuilder.CreateMapIndexTable<AliasPartIndex>(table => table
.Column<string>("Alias", col => col.WithLength(AliasPart.MaxAliasLength))
.Column<string>("ContentItemId", c => c.WithLength(26))
.Column<bool>("Latest", c => c.WithDefault(false))
.Column<bool>("Published", c => c.WithDefault(true))
);

// The index in MySQL can accommodate up to 768 characters or 3072 bytes.
// DocumentId (26) + Alias (714) + ContentItemId (26) + Published (1) + Latest (1) = 768
SchemaBuilder.AlterIndexTable<AliasPartIndex>(table => table
.CreateIndex("IDX_AliasPartIndex_DocumentId",
"DocumentId",
"Alias",
"Alias(714)",
"ContentItemId",
"Published",
"Latest")
Expand Down
4 changes: 0 additions & 4 deletions src/OrchardCore.Modules/OrchardCore.Alias/Models/AliasPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ namespace OrchardCore.Alias.Models
{
public class AliasPart : ContentPart
{
// Maximum length that MySql can support in an index under utf8mb4 collation is 768,
// minus 2 for the `DocumentId` integer (bigint size = 8 bytes = 2 character size),
// minus 26 for the `ContentItemId` and 1 for the 'Published' and 'Latest' bools.
// minus 4 to allow at least to add a new integer column.
public const int MaxAliasLength = 735;

public string Alias { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ public int Create()
"Latest")
);

// The index in MySQL can accommodate up to 768 characters or 3072 bytes.
// DocumentId (26) + ContentType (246) + ContentPart (246) + ContentField (246) + Published (1) + Latest (1) = 766 (less than 768)
SchemaBuilder.AlterIndexTable<TextFieldIndex>(table => table
.CreateIndex("IDX_TextFieldIndex_DocumentId_ContentType",
"DocumentId",
"ContentType",
"ContentPart",
"ContentField",
"ContentType(246)",
"ContentPart(246)",
"ContentField(246)",
"Published",
"Latest")
);
Expand Down Expand Up @@ -80,12 +82,14 @@ public int Create()
"Latest")
);

// The index in MySQL can accommodate up to 768 characters or 3072 bytes.
// DocumentId (26) + ContentType (246) + ContentPart (246) + ContentField (246) + Boolean (1) + Published (1) + Latest (1) = 767 (less than 768)
SchemaBuilder.AlterIndexTable<BooleanFieldIndex>(table => table
.CreateIndex("IDX_BooleanFieldIndex_DocumentId_ContentType",
"DocumentId",
"ContentType",
"ContentPart",
"ContentField",
"ContentType(246)",
"ContentPart(246)",
"ContentField(246)",
"Boolean",
"Published",
"Latest")
Expand All @@ -111,12 +115,14 @@ public int Create()
"Latest")
);

// The index in MySQL can accommodate up to 768 characters or 3072 bytes.
// DocumentId (26) + ContentType (246) + ContentPart (246) + ContentField (246) + Published (1) + Latest (1) = 766 (less than 768)
SchemaBuilder.AlterIndexTable<NumericFieldIndex>(table => table
.CreateIndex("IDX_NumericFieldIndex_DocumentId_ContentType",
"DocumentId",
"ContentType",
"ContentPart",
"ContentField",
"ContentType(246)",
"ContentPart(246)",
"ContentField(246)",
"Published",
"Latest")
);
Expand Down Expand Up @@ -149,12 +155,14 @@ public int Create()
"Latest")
);

// The index in MySQL can accommodate up to 768 characters or 3072 bytes.
// DocumentId (26) + ContentType (246) + ContentPart (246) + ContentField (246) + Published (1) + Latest (1) = 766 (less than 768)
SchemaBuilder.AlterIndexTable<DateTimeFieldIndex>(table => table
.CreateIndex("IDX_DateTimeFieldIndex_DocumentId_ContentType",
"DocumentId",
"ContentType",
"ContentPart",
"ContentField",
"ContentType(246)",
"ContentPart(246)",
"ContentField(246)",
"Published",
"Latest")
);
Expand Down Expand Up @@ -187,12 +195,14 @@ public int Create()
"Latest")
);

// The index in MySQL can accommodate up to 768 characters or 3072 bytes.
// DocumentId (26) + ContentType (246) + ContentPart (246) + ContentField (246) + Published (1) + Latest (1) = 766 (less than 768)
SchemaBuilder.AlterIndexTable<DateFieldIndex>(table => table
.CreateIndex("IDX_DateFieldIndex_DocumentId_ContentType",
"DocumentId",
"ContentType",
"ContentPart",
"ContentField",
"ContentType(246)",
"ContentPart(246)",
"ContentField(246)",
"Published",
"Latest")
);
Expand Down Expand Up @@ -226,12 +236,14 @@ public int Create()
"Latest")
);

// The index in MySQL can accommodate up to 768 characters or 3072 bytes.
// DocumentId (26) + ContentType (246) + ContentPart (246) + ContentField (246) + Published (1) + Latest (1) = 766 (less than 768)
SchemaBuilder.AlterIndexTable<ContentPickerFieldIndex>(table => table
.CreateIndex("IDX_ContentPickerFieldIndex_DocumentId_ContentType",
"DocumentId",
"ContentType",
"ContentPart",
"ContentField",
"ContentType(246)",
"ContentPart(246)",
"ContentField(246)",
"Published",
"Latest")
);
Expand Down Expand Up @@ -264,12 +276,14 @@ public int Create()
"Latest")
);

// The index in MySQL can accommodate up to 768 characters or 3072 bytes.
// DocumentId (26) + ContentType (246) + ContentPart (246) + ContentField (246) + Published (1) + Latest (1) = 766 (less than 768)
SchemaBuilder.AlterIndexTable<TimeFieldIndex>(table => table
.CreateIndex("IDX_TimeFieldIndex_DocumentId_ContentType",
"DocumentId",
"ContentType",
"ContentPart",
"ContentField",
"ContentType(246)",
"ContentPart(246)",
"ContentField(246)",
"Published",
"Latest")
);
Expand Down Expand Up @@ -309,12 +323,15 @@ public int Create()
"Latest")
);


// The index in MySQL can accommodate up to 768 characters or 3072 bytes.
// DocumentId (26) + ContentType (246) + ContentPart (246) + ContentField (246) + Published (1) + Latest (1) = 766 (less than 768)
SchemaBuilder.AlterIndexTable<LinkFieldIndex>(table => table
.CreateIndex("IDX_LinkFieldIndex_DocumentId_ContentType",
"DocumentId",
"ContentType",
"ContentPart",
"ContentField",
"ContentType(246)",
"ContentPart(246)",
"ContentField(246)",
"Published",
"Latest")
);
Expand Down Expand Up @@ -355,12 +372,14 @@ public int Create()
"Latest")
);

// The index in MySQL can accommodate up to 768 characters or 3072 bytes.
// DocumentId (26) + ContentType (246) + ContentPart (246) + ContentField (246) + Published (1) + Latest (1) = 766 (less than 768)
SchemaBuilder.AlterIndexTable<HtmlFieldIndex>(table => table
.CreateIndex("IDX_HtmlFieldIndex_DocumentId_ContentType",
"DocumentId",
"ContentType",
"ContentPart",
"ContentField",
"ContentType(246)",
"ContentPart(246)",
"ContentField(246)",
"Published",
"Latest")
);
Expand All @@ -386,12 +405,14 @@ public int Create()
"Latest")
);

// The index in MySQL can accommodate up to 768 characters or 3072 bytes.
// DocumentId (26) + ContentType (246) + ContentPart (246) + ContentField (246) + Published (1) + Latest (1) = 766 (less than 768)
SchemaBuilder.AlterIndexTable<MultiTextFieldIndex>(table => table
.CreateIndex("IDX_MultiTextFieldIndex_DocumentId_ContentType",
"DocumentId",
"ContentType",
"ContentPart",
"ContentField",
"ContentType(246)",
"ContentPart(246)",
"ContentField(246)",
"Published",
"Latest")
);
Expand Down Expand Up @@ -453,9 +474,9 @@ public int UpdateFrom3()
SchemaBuilder.AlterIndexTable<TextFieldIndex>(table => table
.CreateIndex("IDX_TextFieldIndex_DocumentId_ContentType",
"DocumentId",
"ContentType",
"ContentPart",
"ContentField",
"ContentType(246)",
"ContentPart(246)",
"ContentField(246)",
"Published",
"Latest")
);
Expand All @@ -481,9 +502,9 @@ public int UpdateFrom3()
SchemaBuilder.AlterIndexTable<BooleanFieldIndex>(table => table
.CreateIndex("IDX_BooleanFieldIndex_DocumentId_ContentType",
"DocumentId",
"ContentType",
"ContentPart",
"ContentField",
"ContentType(246)",
"ContentPart(246)",
"ContentField(246)",
"Boolean",
"Published",
"Latest")
Expand All @@ -501,9 +522,9 @@ public int UpdateFrom3()
SchemaBuilder.AlterIndexTable<NumericFieldIndex>(table => table
.CreateIndex("IDX_NumericFieldIndex_DocumentId_ContentType",
"DocumentId",
"ContentType",
"ContentPart",
"ContentField",
"ContentType(246)",
"ContentPart(246)",
"ContentField(246)",
"Published",
"Latest")
);
Expand All @@ -528,9 +549,9 @@ public int UpdateFrom3()
SchemaBuilder.AlterIndexTable<DateTimeFieldIndex>(table => table
.CreateIndex("IDX_DateTimeFieldIndex_DocumentId_ContentType",
"DocumentId",
"ContentType",
"ContentPart",
"ContentField",
"ContentType(246)",
"ContentPart(246)",
"ContentField(246)",
"Published",
"Latest")
);
Expand All @@ -555,9 +576,9 @@ public int UpdateFrom3()
SchemaBuilder.AlterIndexTable<DateFieldIndex>(table => table
.CreateIndex("IDX_DateFieldIndex_DocumentId_ContentType",
"DocumentId",
"ContentType",
"ContentPart",
"ContentField",
"ContentType(246)",
"ContentPart(246)",
"ContentField(246)",
"Published",
"Latest")
);
Expand All @@ -582,9 +603,9 @@ public int UpdateFrom3()
SchemaBuilder.AlterIndexTable<ContentPickerFieldIndex>(table => table
.CreateIndex("IDX_ContentPickerFieldIndex_DocumentId_ContentType",
"DocumentId",
"ContentType",
"ContentPart",
"ContentField",
"ContentType(246)",
"ContentPart(246)",
"ContentField(246)",
"Published",
"Latest")
);
Expand All @@ -609,9 +630,9 @@ public int UpdateFrom3()
SchemaBuilder.AlterIndexTable<TimeFieldIndex>(table => table
.CreateIndex("IDX_TimeFieldIndex_DocumentId_ContentType",
"DocumentId",
"ContentType",
"ContentPart",
"ContentField",
"ContentType(246)",
"ContentPart(246)",
"ContentField(246)",
"Published",
"Latest")
);
Expand All @@ -636,9 +657,9 @@ public int UpdateFrom3()
SchemaBuilder.AlterIndexTable<LinkFieldIndex>(table => table
.CreateIndex("IDX_LinkFieldIndex_DocumentId_ContentType",
"DocumentId",
"ContentType",
"ContentPart",
"ContentField",
"ContentType(246)",
"ContentPart(246)",
"ContentField(246)",
"Published",
"Latest")
);
Expand Down Expand Up @@ -673,9 +694,9 @@ public int UpdateFrom3()
SchemaBuilder.AlterIndexTable<HtmlFieldIndex>(table => table
.CreateIndex("IDX_HtmlFieldIndex_DocumentId_ContentType",
"DocumentId",
"ContentType",
"ContentPart",
"ContentField",
"ContentType(246)",
"ContentPart(246)",
"ContentField(246)",
"Published",
"Latest")
);
Expand All @@ -692,9 +713,9 @@ public int UpdateFrom3()
SchemaBuilder.AlterIndexTable<MultiTextFieldIndex>(table => table
.CreateIndex("IDX_MultiTextFieldIndex_DocumentId_ContentType",
"DocumentId",
"ContentType",
"ContentPart",
"ContentField",
"ContentType(246)",
"ContentPart(246)",
"ContentField(246)",
"Published",
"Latest")
);
Expand Down

0 comments on commit d1e60dc

Please sign in to comment.