Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FluentMigrator;
using FluentMigrator.SqlServer;

namespace Resgrid.Providers.Migrations.Migrations
{
Expand Down Expand Up @@ -41,9 +42,14 @@ public override void Up()
.OnColumn("LoggedOn").Ascending();

if (!Schema.Table("Calls").Index("IX_Calls_DepartmentId_Type").Exists())
// Calls.Type is nvarchar(max), which SQL Server cannot use as an index key column
// (error 1919), and existing data reaches ~1189 chars so it cannot be narrowed to a
// keyable width without truncation. Key on DepartmentId and carry Type as an INCLUDE
// (non-key) column -- LOB columns are allowed there -- which still covers the
// dashboard's per-department GROUP BY Type aggregation.
Create.Index("IX_Calls_DepartmentId_Type").OnTable("Calls")
.OnColumn("DepartmentId").Ascending()
.OnColumn("Type").Ascending();
.Include("Type");

if (!Schema.Table("Calls").Index("IX_Calls_DepartmentId_Priority").Exists())
Create.Index("IX_Calls_DepartmentId_Priority").OnTable("Calls")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FluentMigrator;
using FluentMigrator.Postgres;

namespace Resgrid.Providers.MigrationsPg.Migrations
{
Expand Down Expand Up @@ -40,9 +41,13 @@ public override void Up()
.OnColumn("LoggedOn".ToLower()).Ascending();

if (!Schema.Table("Calls".ToLower()).Index("IX_Calls_DepartmentId_Type".ToLower()).Exists())
// Mirrors the SQL Server variant: carry Type as an INCLUDE (non-key) column instead
// of an index key, keeping the index shape symmetric across dialects and avoiding a
// key on a free-form text column whose values reach ~1189 chars. Still covers the
// dashboard's per-department GROUP BY Type aggregation.
Create.Index("IX_Calls_DepartmentId_Type".ToLower()).OnTable("Calls".ToLower())
.OnColumn("DepartmentId".ToLower()).Ascending()
.OnColumn("Type".ToLower()).Ascending();
.Include("Type".ToLower());

if (!Schema.Table("Calls".ToLower()).Index("IX_Calls_DepartmentId_Priority".ToLower()).Exists())
Create.Index("IX_Calls_DepartmentId_Priority".ToLower()).OnTable("Calls".ToLower())
Expand Down
Loading