Skip to content

Commit 9f7424b

Browse files
committed
RE1-T117 Fixing migration issue
1 parent abcfac1 commit 9f7424b

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

Providers/Resgrid.Providers.Migrations/Migrations/M0073_AddingReportingIndexes.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using FluentMigrator;
2+
using FluentMigrator.SqlServer;
23

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

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

4854
if (!Schema.Table("Calls").Index("IX_Calls_DepartmentId_Priority").Exists())
4955
Create.Index("IX_Calls_DepartmentId_Priority").OnTable("Calls")

Providers/Resgrid.Providers.MigrationsPg/Migrations/M0073_AddingReportingIndexesPg.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using FluentMigrator;
2+
using FluentMigrator.Postgres;
23

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

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

4752
if (!Schema.Table("Calls".ToLower()).Index("IX_Calls_DepartmentId_Priority".ToLower()).Exists())
4853
Create.Index("IX_Calls_DepartmentId_Priority".ToLower()).OnTable("Calls".ToLower())

0 commit comments

Comments
 (0)