From 54cd24acf426f86948ccd21788b11506a190bf6b Mon Sep 17 00:00:00 2001 From: Arthur Bassi Date: Fri, 17 Jul 2026 10:36:31 -0300 Subject: [PATCH] fix(migrations): shrink SiteCode and InternalWONumber before Phase4 search indexes SQL Server cannot index nvarchar(max). Alter columns to nvarchar(450) before creating Phase 4 search indexes. --- .../20260624200000_Phase4_SearchIndexes.cs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/Data.SeaHavenIndustries/Migrations/20260624200000_Phase4_SearchIndexes.cs b/Data.SeaHavenIndustries/Migrations/20260624200000_Phase4_SearchIndexes.cs index 427b6cf..51795a3 100644 --- a/Data.SeaHavenIndustries/Migrations/20260624200000_Phase4_SearchIndexes.cs +++ b/Data.SeaHavenIndustries/Migrations/20260624200000_Phase4_SearchIndexes.cs @@ -10,6 +10,27 @@ namespace Data.SeaHavenIndustries.Migrations /// protected override void Up(MigrationBuilder migrationBuilder) { + // nvarchar(max) cannot be an index key; shrink before indexing. + migrationBuilder.AlterColumn( + name: "SiteCode", + table: "workOrders", + type: "nvarchar(450)", + maxLength: 450, + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "InternalWONumber", + table: "workOrders", + type: "nvarchar(450)", + maxLength: 450, + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldNullable: true); + migrationBuilder.CreateIndex( name: "IX_workOrders_SiteCode", table: "workOrders", @@ -43,6 +64,26 @@ namespace Data.SeaHavenIndustries.Migrations migrationBuilder.DropIndex( name: "IX_workOrders_LifecycleStatus_ScheduledDate", table: "workOrders"); + + migrationBuilder.AlterColumn( + name: "SiteCode", + table: "workOrders", + type: "nvarchar(max)", + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(450)", + oldMaxLength: 450, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "InternalWONumber", + table: "workOrders", + type: "nvarchar(max)", + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(450)", + oldMaxLength: 450, + oldNullable: true); } } }