Merge pull request #7494 from liamlaverty/add-missing-fk-index

Add missing fk index
This commit is contained in:
Shannon Deminick
2020-02-03 14:26:47 +11:00
committed by GitHub
4 changed files with 40 additions and 1 deletions
@@ -190,6 +190,9 @@ namespace Umbraco.Core.Migrations.Upgrade
To<MissingContentVersionsIndexes>("{EE288A91-531B-4995-8179-1D62D9AA3E2E}");
To<AddMainDomLock>("{2AB29964-02A1-474D-BD6B-72148D2A53A2}");
To<AddDatabaseIndexesMissingOnForeignKeys>("{a78e3369-8ea3-40ec-ad3f-5f76929d2b20}");
//FINAL
}
}
@@ -0,0 +1,33 @@
using Umbraco.Core.Persistence.Dtos;
namespace Umbraco.Core.Migrations.Upgrade.V_8_6_0
{
public class AddDatabaseIndexesMissingOnForeignKeys : MigrationBase
{
public AddDatabaseIndexesMissingOnForeignKeys(IMigrationContext context)
: base(context)
{
}
/// <summary>
/// Adds an index to the foreign key column <c>parent</c> on <c>DictionaryDto</c>'s table
/// if it doesn't already exist
/// </summary>
public override void Migrate()
{
var indexName = "IX_" + DictionaryDto.TableName + "_Parent";
if (IndexExists(indexName) == false)
{
Create
.Index(indexName)
.OnTable(DictionaryDto.TableName)
.OnColumn("parent")
.Ascending()
.WithOptions().NonClustered()
.Do();
}
}
}
}
@@ -5,11 +5,12 @@ using Umbraco.Core.Persistence.DatabaseAnnotations;
namespace Umbraco.Core.Persistence.Dtos
{
[TableName(Constants.DatabaseSchema.Tables.DictionaryEntry)]
[TableName(TableName)]
[PrimaryKey("pk")]
[ExplicitColumns]
internal class DictionaryDto
{
public const string TableName = Constants.DatabaseSchema.Tables.DictionaryEntry;
[Column("pk")]
[PrimaryKeyColumn]
public int PrimaryKey { get; set; }
@@ -21,6 +22,7 @@ namespace Umbraco.Core.Persistence.Dtos
[Column("parent")]
[NullSetting(NullSetting = NullSettings.Null)]
[ForeignKey(typeof(DictionaryDto), Column = "id")]
[Index(IndexTypes.NonClustered, Name = "IX_" + TableName + "_Parent")]
public Guid? Parent { get; set; }
[Column("key")]
+1
View File
@@ -133,6 +133,7 @@
<Compile Include="Runtime\MainDomSemaphoreLock.cs" />
<Compile Include="Runtime\SqlMainDomLock.cs" />
<Compile Include="Migrations\Upgrade\V_8_6_0\MissingContentVersionsIndexes.cs" />
<Compile Include="Migrations\Upgrade\V_8_6_0\AddDatabaseIndexesMissingOnForeignKeys.cs" />
<Compile Include="SystemLock.cs" />
<Compile Include="Attempt.cs" />
<Compile Include="AttemptOfTResult.cs" />