Skip to content

Commit

Permalink
Fix MySQL index length (#14513)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek authored Oct 17, 2023
1 parent 7f51a1c commit 1e5bcb6
Show file tree
Hide file tree
Showing 17 changed files with 353 additions and 79 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public int Create()
);

// The index in MySQL can accommodate up to 768 characters or 3072 bytes.
// DocumentId (2) + ContentType (254) + ContentPart (254) + ContentField (254) + Published (1) + Latest (1) = 766 (less than 768)
// DocumentId (2) + ContentType (254) + ContentPart (254) + ContentField (254) + Published and Latest (1) = 765 (< 768).
SchemaBuilder.AlterIndexTable<UserPickerFieldIndex>(table => table
.CreateIndex("IDX_UserPickerFieldIndex_DocumentId_ContentType",
"DocumentId",
Expand Down Expand Up @@ -67,7 +67,7 @@ public int UpdateFrom1()
);

// The index in MySQL can accommodate up to 768 characters or 3072 bytes.
// DocumentId (2) + ContentType (254) + ContentPart (254) + ContentField (254) + Published (1) + Latest (1) = 766 (less than 768)
// DocumentId (2) + ContentType (254) + ContentPart (254) + ContentField (254) + Published and Latest (1) = 765 (< 768).
SchemaBuilder.AlterIndexTable<UserPickerFieldIndex>(table => table
.CreateIndex("IDX_UserPickerFieldIndex_DocumentId_ContentType",
"DocumentId",
Expand Down
8 changes: 4 additions & 4 deletions src/OrchardCore.Modules/OrchardCore.Indexing/Migrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ public class Migrations : DataMigration
public int Create()
{
SchemaBuilder.CreateTable(nameof(IndexingTask), table => table
.Column<int>(nameof(IndexingTask.Id), col => col.PrimaryKey().Identity())
.Column<string>(nameof(IndexingTask.ContentItemId), c => c.WithLength(26))
.Column<DateTime>(nameof(IndexingTask.CreatedUtc), col => col.NotNull())
.Column<int>(nameof(IndexingTask.Type))
.Column<int>("Id", col => col.PrimaryKey().Identity())
.Column<string>("ContentItemId", c => c.WithLength(26))
.Column<DateTime>("CreatedUtc", col => col.NotNull())
.Column<int>("Type")
);

SchemaBuilder.AlterTable(nameof(IndexingTask), table => table
Expand Down
11 changes: 7 additions & 4 deletions src/OrchardCore.Modules/OrchardCore.Layers/Migrations.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Threading.Tasks;
using OrchardCore.Data.Migration;
using OrchardCore.Layers.Indexes;
Expand Down Expand Up @@ -31,7 +30,9 @@ public int Create()
);

SchemaBuilder.AlterIndexTable<LayerMetadataIndex>(table => table
.CreateIndex("IDX_LayerMetadataIndex_DocumentId", "DocumentId", "Zone")
.CreateIndex("IDX_LayerMetadataIndex_DocumentId",
"DocumentId",
"Zone")
);

// Shortcut other migration steps on new content definition schemas.
Expand All @@ -42,7 +43,9 @@ public int Create()
public int UpdateFrom1()
{
SchemaBuilder.AlterIndexTable<LayerMetadataIndex>(table => table
.CreateIndex("IDX_LayerMetadataIndex_DocumentId", "DocumentId", "Zone")
.CreateIndex("IDX_LayerMetadataIndex_DocumentId",
"DocumentId",
"Zone")
);

return 2;
Expand All @@ -59,7 +62,7 @@ public async Task<int> UpdateFrom2Async()
#pragma warning disable 0618
_ruleMigrator.Migrate(layer.Rule, layer.LayerRule);

layer.Rule = String.Empty;
layer.Rule = string.Empty;
#pragma warning restore 0618
}

Expand Down
5 changes: 4 additions & 1 deletion src/OrchardCore.Modules/OrchardCore.Lists/Migrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ public int UpdateFrom1()
public int UpdateFrom2()
{
SchemaBuilder.AlterIndexTable<ContainedPartIndex>(table => table
.CreateIndex("IDX_ContainedPartIndex_DocumentId", "DocumentId", "ListContentItemId", "Order")
.CreateIndex("IDX_ContainedPartIndex_DocumentId",
"DocumentId",
"ListContentItemId",
"Order")
);

return 3;
Expand Down
16 changes: 10 additions & 6 deletions src/OrchardCore.Modules/OrchardCore.Taxonomies/Migrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ public int Create()
"Latest")
);

// The index in MySQL can accommodate up to 768 characters or 3072 bytes.
// DocumentId (2) + ContentType (254) + ContentPart (254) + ContentField (254) + Published and Latest (1) = 765 (< 768).
SchemaBuilder.AlterIndexTable<TaxonomyIndex>(table => table
.CreateIndex("IDX_TaxonomyIndex_DocumentId_ContentType",
"DocumentId",
"ContentType",
"ContentPart",
"ContentField",
"ContentType(254)",
"ContentPart(254)",
"ContentField(254)",
"Published",
"Latest")
);
Expand Down Expand Up @@ -125,12 +127,14 @@ public int UpdateFrom3()
"Latest")
);

// The index in MySQL can accommodate up to 768 characters or 3072 bytes.
// DocumentId (2) + ContentType (254) + ContentPart (254) + ContentField (254) + Published and Latest (1) = 765 (< 768).
SchemaBuilder.AlterIndexTable<TaxonomyIndex>(table => table
.CreateIndex("IDX_TaxonomyIndex_DocumentId_ContentType",
"DocumentId",
"ContentType",
"ContentPart",
"ContentField",
"ContentType(254)",
"ContentPart(254)",
"ContentField(254)",
"Published",
"Latest")
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public OpenIdMigrations(ISession session)
public int Create()
{
SchemaBuilder.CreateMapIndexTable<OpenIdApplicationIndex>(table => table
.Column<string>(nameof(OpenIdApplicationIndex.ApplicationId), column => column.WithLength(48))
.Column<string>(nameof(OpenIdApplicationIndex.ClientId), column => column.Unique()),
.Column<string>("ApplicationId", column => column.WithLength(48))
.Column<string>("ClientId", column => column.Unique()),
collection: OpenIdApplicationCollection);

SchemaBuilder.AlterIndexTable<OpenIdApplicationIndex>(table => table
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
{
"name": "Migrations",
"displayName": "Migrations",
"description": "Testing features having database migrations.",
"author": "The Orchard Core Team",
"website": "https://orchardcore.net",
"version": "1.0.0",
"issetuprecipe": true,
"categories": [ "tests" ],
"tags": [ "tests" ],

// The variables are evaluated the first time they are accessed, and reused across steps
"variables": {
"homeContentItemId": "[js:uuid()]",
},

"steps": [
{
"name": "feature",
"enable": [
// SaaS
"OrchardCore.HomeRoute",
"OrchardCore.Admin",
"OrchardCore.Diagnostics",
"OrchardCore.DynamicCache",
"OrchardCore.Features",
"OrchardCore.Navigation",
"OrchardCore.Recipes",
"OrchardCore.Resources",
"OrchardCore.Roles",
"OrchardCore.Security",
"OrchardCore.Settings",
"OrchardCore.Themes",
"OrchardCore.Users",

// Content Management including features having database migrations.
"OrchardCore.AdminDashboard",
"OrchardCore.AdminMenu",
"OrchardCore.Alias",
"OrchardCore.ArchiveLater",
"OrchardCore.AuditTrail",
"OrchardCore.Autoroute",
"OrchardCore.ContentFields",
"OrchardCore.ContentFields.Indexing.SQL",
"OrchardCore.ContentFields.Indexing.SQL.UserPicker",
"OrchardCore.ContentLocalization",
"OrchardCore.ContentPreview",
"OrchardCore.Contents",
"OrchardCore.ContentTypes",
"OrchardCore.CustomSettings",
"OrchardCore.Deployment",
"OrchardCore.Deployment.Remote",
"OrchardCore.Feeds",
"OrchardCore.Flows",
"OrchardCore.Html",
"OrchardCore.Indexing",
"OrchardCore.Layers",
"OrchardCore.Lists",
"OrchardCore.Media",
"OrchardCore.Menu",
"OrchardCore.Markdown",
"OrchardCore.Notifications",
"OrchardCore.OpenId",
"OrchardCore.Placements",
"OrchardCore.PublishLater",
"OrchardCore.Queries",
"OrchardCore.Queries.Sql",
"OrchardCore.Rules",
"OrchardCore.Shortcodes.Templates",
"OrchardCore.Taxonomies",
"OrchardCore.Templates",
"OrchardCore.Title",
"OrchardCore.Widgets",
"OrchardCore.Workflows",

// Themes
"TheBlogTheme",
"TheAdmin",
"SafeMode"
]
},
{
"name": "themes",
"admin": "TheAdmin",
"site": "TheBlogTheme"
},
{
"name": "Roles",
"Roles": [
{
"Name": "Administrator",
"Description": "Administrator",
"Permissions": []
},
{
"Name": "Authenticated",
"Description": "Authenticated",
"Permissions": []
},
{
"Name": "Anonymous",
"Description": "Anonymous",
"Permissions": []
}
]
},
{
"name": "settings",
"HomeRoute": {
"Action": "Display",
"Controller": "Item",
"Area": "OrchardCore.Contents",
"ContentItemId": "[js: variables('homeContentItemId')]"
},
"LayerSettings": {
"Zones": [ "Content", "Footer" ]
}
},
{
"name": "ContentDefinition",
"ContentTypes": [
{
"Name": "Article",
"DisplayName": "Article",
"Hidden": false,
"Settings": {
"ContentTypeSettings": {
"Creatable": true,
"Draftable": true,
"Versionable": true,
"Listable": true
}
},
"ContentTypePartDefinitionRecords": [
{
"PartName": "Article",
"Name": "Article",
"Settings": {
"ContentTypePartSettings": {
"Position": "3"
}
}
},
{
"PartName": "AutoroutePart",
"Name": "AutoroutePart",
"Settings": {
"AutoroutePartSettings": {
"AllowCustomPath": true,
"Pattern": "{{ Model.ContentItem | display_text | slugify }}",
"ShowHomepageOption": true
},
"ContentTypePartSettings": {
"Position": "1"
}
}
},
{
"PartName": "HtmlBodyPart",
"Name": "HtmlBodyPart",
"Settings": {
"ContentTypePartSettings": {
"Editor": "Wysiwyg",
"Position": "2"
}
}
},
{
"PartName": "TitlePart",
"Name": "TitlePart",
"Settings": {
"ContentTypePartSettings": {
"Position": "0"
}
}
}
]
}
],
"ContentParts": [
{
"Name": "Article",
"Settings": {}
}
]
},
{
"name": "content",
"Data": [
{
"ContentItemId": "[js: variables('homeContentItemId')]",
"ContentType": "Article",
"DisplayText": "Home",
"Latest": true,
"Published": true,
"Owner": "[js: parameters('AdminUserId')]",
"Author": "[js: parameters('AdminUsername')]",
"AutoroutePart": {
"Path": "about",
"SetHomepage": false
},
"HtmlBodyPart": {
"Html": "<p>Testing features having database migrations.</p>"
},
"TitlePart": {
"Title": "Testing Migrations"
}
}
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const sassSite = {
setupRecipe: "SaaS",
}


describe('Setup SaaS', function () {
it('Successfully setup the SaaS default tenant', function () {
cy.visit('/');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ describe('Agency Tests', function () {
it('Agency admin login should work', function(){
cy.login(tenant);
cy.visit(`${tenant.prefix}/Admin`);
cy.get('.ta-content').should('contain.text', 'Welcome to Orchard')
cy.get('.menu-admin').should('have.id', 'adminMenu')
})


});
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ describe('Blog Tests', function () {
it('Blog admin login should work', function(){
cy.login(tenant);
cy.visit(`${tenant.prefix}/Admin`);
cy.get('.ta-content').should('contain.text', 'Welcome to Orchard');
cy.get('.menu-admin').should('have.id', 'adminMenu')
})
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ describe('ComingSoon Recipe test', function () {
it('ComingSoon admin login should work', function(){
cy.login(tenant);
cy.visit(`${tenant.prefix}/Admin`);
cy.get('.ta-content').should('contain.text', 'Welcome to Orchard')
cy.get('.menu-admin').should('have.id', 'adminMenu')
})
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ describe('Headless Recipe test', function () {
it('Headless admin login should work', function(){
cy.login(tenant);
cy.visit(`${tenant.prefix}/Admin`);
cy.get('.ta-content').should('contain.text', 'Welcome to Orchard')
cy.get('.menu-admin').should('have.id', 'adminMenu')
})
});
Loading

0 comments on commit 1e5bcb6

Please sign in to comment.