From 4e32c487d20f8c7973c18d695a80fcb08d762c3f Mon Sep 17 00:00:00 2001 From: Arthur Bassi Date: Fri, 17 Jul 2026 11:10:59 -0300 Subject: [PATCH] fix(migrations): discover Phase7, harden Phase4 indexes, align WO model Make Phase7 EF-discoverable with idempotent DDL, shrink SiteCode and InternalWONumber before Phase4 search indexes on this branch, align MaxLength/Fluent indexes with the snapshot, and add the missing Events calendar table migration so the model has no pending changes. --- .../Auth/ApplicationDbContext.cs | 25 ++ .../20260624200000_Phase4_SearchIndexes.cs | 41 +++ ...120000_Phase7_ExternalWorkOrderIdUnique.cs | 68 +++-- .../20260717140000_AddEventsCalendarTable.cs | 58 ++++ .../ApplicationDbContextModelSnapshot.cs | 289 +++++++++++------- Data.SeaHavenIndustries/Models/WorkerOrder.cs | 4 + 6 files changed, 354 insertions(+), 131 deletions(-) create mode 100644 Data.SeaHavenIndustries/Migrations/20260717140000_AddEventsCalendarTable.cs diff --git a/Data.SeaHavenIndustries/Auth/ApplicationDbContext.cs b/Data.SeaHavenIndustries/Auth/ApplicationDbContext.cs index 1cea35d..9216004 100644 --- a/Data.SeaHavenIndustries/Auth/ApplicationDbContext.cs +++ b/Data.SeaHavenIndustries/Auth/ApplicationDbContext.cs @@ -49,10 +49,18 @@ namespace Data.SeaHavenIndustries .Property(w => w.RowVersion) .IsRowVersion(); + builder.Entity() + .Property(w => w.SiteCode) + .HasMaxLength(450); + builder.Entity() .HasIndex(w => w.SiteCode) .HasFilter("[istemplate] = 0"); + builder.Entity() + .Property(w => w.InternalWONumber) + .HasMaxLength(450); + builder.Entity() .HasIndex(w => w.InternalWONumber) .HasFilter("[istemplate] = 0"); @@ -61,6 +69,23 @@ namespace Data.SeaHavenIndustries .HasIndex(w => new { w.LifecycleStatus, w.ScheduledDate }) .HasFilter("[istemplate] = 0"); + // Phase 1 board indexes (must stay in model to match snapshot / existing DBs). + builder.Entity() + .HasIndex(w => w.AssignTo); + + builder.Entity() + .HasIndex(w => w.ScheduledDate); + + builder.Entity() + .HasIndex(w => new { w.AssignTo, w.ScheduledDate }); + + builder.Entity() + .HasIndex(w => w.WorkOrderType); + + builder.Entity() + .Property(w => w.Service) + .HasMaxLength(128); + builder.Entity() .Property(w => w.ExternalWorkOrderId) .HasMaxLength(450); 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); } } } diff --git a/Data.SeaHavenIndustries/Migrations/20260713120000_Phase7_ExternalWorkOrderIdUnique.cs b/Data.SeaHavenIndustries/Migrations/20260713120000_Phase7_ExternalWorkOrderIdUnique.cs index 291a952..2958307 100644 --- a/Data.SeaHavenIndustries/Migrations/20260713120000_Phase7_ExternalWorkOrderIdUnique.cs +++ b/Data.SeaHavenIndustries/Migrations/20260713120000_Phase7_ExternalWorkOrderIdUnique.cs @@ -1,3 +1,5 @@ +using Data.SeaHavenIndustries; +using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable @@ -5,45 +7,57 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace Data.SeaHavenIndustries.Migrations { /// + [DbContext(typeof(ApplicationDbContext))] + [Migration("20260713120000_Phase7_ExternalWorkOrderIdUnique")] public partial class Phase7_ExternalWorkOrderIdUnique : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { - migrationBuilder.AlterColumn( - name: "ExternalWorkOrderId", - table: "workOrders", - type: "nvarchar(450)", - maxLength: 450, - nullable: true, - oldClrType: typeof(string), - oldType: "nvarchar(max)", - oldNullable: true); + // Idempotent: column may already be nvarchar(450) in some environments. + migrationBuilder.Sql(@" + IF COL_LENGTH('workOrders', 'ExternalWorkOrderId') IS NOT NULL + AND EXISTS ( + SELECT 1 + FROM sys.columns c + INNER JOIN sys.types t ON c.user_type_id = t.user_type_id + WHERE c.object_id = OBJECT_ID(N'dbo.workOrders') + AND c.name = N'ExternalWorkOrderId' + AND t.name = N'nvarchar' + AND c.max_length = -1) + BEGIN + ALTER TABLE workOrders ALTER COLUMN ExternalWorkOrderId nvarchar(450) NULL; + END + "); - migrationBuilder.CreateIndex( - name: "IX_workOrders_ExternalWorkOrderId", - table: "workOrders", - column: "ExternalWorkOrderId", - unique: true, - filter: "[ExternalWorkOrderId] IS NOT NULL AND [ExternalWorkOrderId] <> ''"); + migrationBuilder.Sql(@" + IF NOT EXISTS ( + SELECT 1 FROM sys.indexes + WHERE name = N'IX_workOrders_ExternalWorkOrderId' + AND object_id = OBJECT_ID(N'dbo.workOrders')) + BEGIN + CREATE UNIQUE INDEX IX_workOrders_ExternalWorkOrderId + ON workOrders (ExternalWorkOrderId) + WHERE [ExternalWorkOrderId] IS NOT NULL AND [ExternalWorkOrderId] <> ''; + END + "); } /// protected override void Down(MigrationBuilder migrationBuilder) { - migrationBuilder.DropIndex( - name: "IX_workOrders_ExternalWorkOrderId", - table: "workOrders"); + migrationBuilder.Sql(@" + IF EXISTS ( + SELECT 1 FROM sys.indexes + WHERE name = N'IX_workOrders_ExternalWorkOrderId' + AND object_id = OBJECT_ID(N'dbo.workOrders')) + DROP INDEX IX_workOrders_ExternalWorkOrderId ON workOrders; + "); - migrationBuilder.AlterColumn( - name: "ExternalWorkOrderId", - table: "workOrders", - type: "nvarchar(max)", - nullable: true, - oldClrType: typeof(string), - oldType: "nvarchar(450)", - oldMaxLength: 450, - oldNullable: true); + migrationBuilder.Sql(@" + IF COL_LENGTH('workOrders', 'ExternalWorkOrderId') IS NOT NULL + ALTER TABLE workOrders ALTER COLUMN ExternalWorkOrderId nvarchar(max) NULL; + "); } } } diff --git a/Data.SeaHavenIndustries/Migrations/20260717140000_AddEventsCalendarTable.cs b/Data.SeaHavenIndustries/Migrations/20260717140000_AddEventsCalendarTable.cs new file mode 100644 index 0000000..6dcb796 --- /dev/null +++ b/Data.SeaHavenIndustries/Migrations/20260717140000_AddEventsCalendarTable.cs @@ -0,0 +1,58 @@ +using Data.SeaHavenIndustries; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Data.SeaHavenIndustries.Migrations +{ + /// + [DbContext(typeof(ApplicationDbContext))] + [Migration("20260717140000_AddEventsCalendarTable")] + public partial class AddEventsCalendarTable : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + // Events entity existed in the model/DbSet without a discoverable migration. + migrationBuilder.Sql(@" + IF OBJECT_ID(N'dbo.Events', N'U') IS NULL + BEGIN + CREATE TABLE Events ( + Id int NOT NULL IDENTITY(1,1), + Title nvarchar(100) NOT NULL, + Description nvarchar(max) NULL, + Location nvarchar(150) NULL, + RecordID int NULL, + RecordName nvarchar(max) NULL, + RecordTargetType nvarchar(max) NULL, + ReminderMinutes int NOT NULL, + EventColor nvarchar(20) NOT NULL, + StartDate datetime2 NOT NULL, + StartTime nvarchar(10) NULL, + EndDate datetime2 NOT NULL, + EndTime nvarchar(10) NULL, + AllDay bit NOT NULL, + IsDeleted bit NULL, + createdby nvarchar(max) NULL, + DeleterUserId nvarchar(max) NULL, + DeletionTime datetime2 NULL, + CreatedDate datetime2 NULL, + LastModificationTime datetime2 NULL, + LastModifierUserId int NULL, + CONSTRAINT PK_Events PRIMARY KEY (Id) + ); + END + "); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.Sql(@" + IF OBJECT_ID(N'dbo.Events', N'U') IS NOT NULL + DROP TABLE Events; + "); + } + } +} diff --git a/Data.SeaHavenIndustries/Migrations/ApplicationDbContextModelSnapshot.cs b/Data.SeaHavenIndustries/Migrations/ApplicationDbContextModelSnapshot.cs index 608754d..4ff0be1 100644 --- a/Data.SeaHavenIndustries/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/Data.SeaHavenIndustries/Migrations/ApplicationDbContextModelSnapshot.cs @@ -107,7 +107,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasKey("Id"); - b.ToTable("Accounts", (string)null); + b.ToTable("Accounts"); }); modelBuilder.Entity("Data.SeaHavenIndustries.Addresses", b => @@ -175,7 +175,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasIndex("ContactId"); - b.ToTable("Addresses", (string)null); + b.ToTable("Addresses"); }); modelBuilder.Entity("Data.SeaHavenIndustries.ApplicationUser", b => @@ -334,7 +334,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasIndex("LocationId"); - b.ToTable("Assets", (string)null); + b.ToTable("Assets"); }); modelBuilder.Entity("Data.SeaHavenIndustries.Category", b => @@ -371,62 +371,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasKey("Id"); - b.ToTable("Categories", (string)null); - }); - - modelBuilder.Entity("Data.SeaHavenIndustries.CompletionDocTemplate", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("CreatedDate") - .HasColumnType("datetime2"); - - b.Property("DeleterUserId") - .HasColumnType("nvarchar(max)"); - - b.Property("DeletionTime") - .HasColumnType("datetime2"); - - b.Property("IsActive") - .HasColumnType("bit"); - - b.Property("IsDeleted") - .HasColumnType("bit"); - - b.Property("LastModificationTime") - .HasColumnType("datetime2"); - - b.Property("LastModifierUserId") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("ServiceKey") - .IsRequired() - .HasColumnType("nvarchar(450)"); - - b.Property("TemplateUrl") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("WorkOrderType") - .HasColumnType("int"); - - b.Property("createdby") - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.HasIndex("ServiceKey", "IsActive") - .HasDatabaseName("IX_CompletionDocTemplates_ServiceKey_IsActive"); - - b.ToTable("CompletionDocTemplates", (string)null); + b.ToTable("Categories"); }); modelBuilder.Entity("Data.SeaHavenIndustries.Comments", b => @@ -493,7 +438,61 @@ namespace Data.SeaHavenIndustries.Migrations b.HasIndex("WorkerOrderId"); - b.ToTable("Comments", (string)null); + b.ToTable("Comments"); + }); + + modelBuilder.Entity("Data.SeaHavenIndustries.CompletionDocTemplate", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedDate") + .HasColumnType("datetime2"); + + b.Property("DeleterUserId") + .HasColumnType("nvarchar(max)"); + + b.Property("DeletionTime") + .HasColumnType("datetime2"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("LastModificationTime") + .HasColumnType("datetime2"); + + b.Property("LastModifierUserId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ServiceKey") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("TemplateUrl") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("WorkOrderType") + .HasColumnType("int"); + + b.Property("createdby") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("ServiceKey", "IsActive"); + + b.ToTable("CompletionDocTemplates"); }); modelBuilder.Entity("Data.SeaHavenIndustries.ContactDetails", b => @@ -559,7 +558,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasIndex("ContactId"); - b.ToTable("ContactDetails", (string)null); + b.ToTable("ContactDetails"); }); modelBuilder.Entity("Data.SeaHavenIndustries.Contacts", b => @@ -651,7 +650,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasIndex("LocationId"); - b.ToTable("Contacts", (string)null); + b.ToTable("Contacts"); }); modelBuilder.Entity("Data.SeaHavenIndustries.Department", b => @@ -669,7 +668,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasKey("Id"); - b.ToTable("Departments", (string)null); + b.ToTable("Departments"); }); modelBuilder.Entity("Data.SeaHavenIndustries.Dispatch", b => @@ -768,7 +767,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasIndex("WorkOrderId"); - b.ToTable("Dispatches", (string)null); + b.ToTable("Dispatches"); }); modelBuilder.Entity("Data.SeaHavenIndustries.DispatchChecklistItem", b => @@ -827,7 +826,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasIndex("WorkOrderId"); - b.ToTable("DispatchChecklistItems", (string)null); + b.ToTable("DispatchChecklistItems"); }); modelBuilder.Entity("Data.SeaHavenIndustries.DispatchSignoff", b => @@ -881,7 +880,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasIndex("DispatchId"); - b.ToTable("DispatchSignoffs", (string)null); + b.ToTable("DispatchSignoffs"); }); modelBuilder.Entity("Data.SeaHavenIndustries.DispatchUpliftRequest", b => @@ -951,7 +950,7 @@ namespace Data.SeaHavenIndustries.Migrations .IsUnique() .HasFilter("[Status] = 'Pending'"); - b.ToTable("DispatchUpliftRequests", (string)null); + b.ToTable("DispatchUpliftRequests"); }); modelBuilder.Entity("Data.SeaHavenIndustries.DispatchWorkOrder", b => @@ -974,7 +973,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasIndex("WorkOrderId"); - b.ToTable("DispatchWorkOrders", (string)null); + b.ToTable("DispatchWorkOrders"); }); modelBuilder.Entity("Data.SeaHavenIndustries.DropdownOption", b => @@ -1004,7 +1003,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasKey("Id"); - b.ToTable("DropdownOptions", (string)null); + b.ToTable("DropdownOptions"); }); modelBuilder.Entity("Data.SeaHavenIndustries.Employee", b => @@ -1109,7 +1108,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasIndex("RegionId"); - b.ToTable("Employees", (string)null); + b.ToTable("Employees"); }); modelBuilder.Entity("Data.SeaHavenIndustries.EmployeeAddress", b => @@ -1149,7 +1148,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasIndex("EmployeeId") .IsUnique(); - b.ToTable("EmployeeAddresses", (string)null); + b.ToTable("EmployeeAddresses"); }); modelBuilder.Entity("Data.SeaHavenIndustries.EmployeeEmail", b => @@ -1177,7 +1176,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasIndex("EmployeeId"); - b.ToTable("EmployeeEmails", (string)null); + b.ToTable("EmployeeEmails"); }); modelBuilder.Entity("Data.SeaHavenIndustries.EmployeePhone", b => @@ -1207,7 +1206,87 @@ namespace Data.SeaHavenIndustries.Migrations b.HasIndex("EmployeeId"); - b.ToTable("EmployeePhones", (string)null); + b.ToTable("EmployeePhones"); + }); + + modelBuilder.Entity("Data.SeaHavenIndustries.Events", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AllDay") + .HasColumnType("bit"); + + b.Property("CreatedDate") + .HasColumnType("datetime2"); + + b.Property("DeleterUserId") + .HasColumnType("nvarchar(max)"); + + b.Property("DeletionTime") + .HasColumnType("datetime2"); + + b.Property("Description") + .HasColumnType("nvarchar(max)"); + + b.Property("EndDate") + .HasColumnType("datetime2"); + + b.Property("EndTime") + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + + b.Property("EventColor") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("LastModificationTime") + .HasColumnType("datetime2"); + + b.Property("LastModifierUserId") + .HasColumnType("int"); + + b.Property("Location") + .HasMaxLength(150) + .HasColumnType("nvarchar(150)"); + + b.Property("RecordID") + .HasColumnType("int"); + + b.Property("RecordName") + .HasColumnType("nvarchar(max)"); + + b.Property("RecordTargetType") + .HasColumnType("nvarchar(max)"); + + b.Property("ReminderMinutes") + .HasColumnType("int"); + + b.Property("StartDate") + .HasColumnType("datetime2"); + + b.Property("StartTime") + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("createdby") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Events"); }); modelBuilder.Entity("Data.SeaHavenIndustries.FollowUps", b => @@ -1275,7 +1354,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasIndex("WorkOrderId"); - b.ToTable("FollowUps", (string)null); + b.ToTable("FollowUps"); }); modelBuilder.Entity("Data.SeaHavenIndustries.ForgetPasswordCode", b => @@ -1300,7 +1379,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasKey("Id"); - b.ToTable("ForgetPasswordCodes", (string)null); + b.ToTable("ForgetPasswordCodes"); }); modelBuilder.Entity("Data.SeaHavenIndustries.JobTitle", b => @@ -1318,7 +1397,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasKey("Id"); - b.ToTable("JobTitles", (string)null); + b.ToTable("JobTitles"); }); modelBuilder.Entity("Data.SeaHavenIndustries.Locations", b => @@ -1388,7 +1467,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasKey("Id"); - b.ToTable("Locations", (string)null); + b.ToTable("Locations"); }); modelBuilder.Entity("Data.SeaHavenIndustries.PMSchedules", b => @@ -1446,7 +1525,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasIndex("LocationId"); - b.ToTable("PMSchedules", (string)null); + b.ToTable("PMSchedules"); }); modelBuilder.Entity("Data.SeaHavenIndustries.Quotes", b => @@ -1520,7 +1599,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasIndex("WorkorderId"); - b.ToTable("Quotes", (string)null); + b.ToTable("Quotes"); }); modelBuilder.Entity("Data.SeaHavenIndustries.QuotesLineItems", b => @@ -1568,7 +1647,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasIndex("QuoteId"); - b.ToTable("QuotesLines", (string)null); + b.ToTable("QuotesLines"); }); modelBuilder.Entity("Data.SeaHavenIndustries.Region", b => @@ -1586,7 +1665,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasKey("Id"); - b.ToTable("Regions", (string)null); + b.ToTable("Regions"); }); modelBuilder.Entity("Data.SeaHavenIndustries.TaskListTemplate", b => @@ -1629,7 +1708,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasKey("Id"); - b.ToTable("TaskListTemplates", (string)null); + b.ToTable("TaskListTemplates"); }); modelBuilder.Entity("Data.SeaHavenIndustries.TaskListTemplateItem", b => @@ -1674,7 +1753,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasIndex("TaskListTemplateId"); - b.ToTable("TaskListTemplateItems", (string)null); + b.ToTable("TaskListTemplateItems"); }); modelBuilder.Entity("Data.SeaHavenIndustries.Template", b => @@ -1776,7 +1855,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasIndex("LocationId"); - b.ToTable("Templates", (string)null); + b.ToTable("Templates"); }); modelBuilder.Entity("Data.SeaHavenIndustries.Vendor", b => @@ -1840,7 +1919,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasKey("Id"); - b.ToTable("Vendors", (string)null); + b.ToTable("Vendors"); }); modelBuilder.Entity("Data.SeaHavenIndustries.VendorAccessToken", b => @@ -1899,7 +1978,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasIndex("VendorId"); - b.ToTable("VendorAccessTokens", (string)null); + b.ToTable("VendorAccessTokens"); }); modelBuilder.Entity("Data.SeaHavenIndustries.WorkOrder", b => @@ -1980,7 +2059,8 @@ namespace Data.SeaHavenIndustries.Migrations .HasColumnType("nvarchar(7)"); b.Property("InternalWONumber") - .HasColumnType("nvarchar(max)"); + .HasMaxLength(450) + .HasColumnType("nvarchar(450)"); b.Property("IsDeleted") .HasColumnType("bit"); @@ -2074,7 +2154,8 @@ namespace Data.SeaHavenIndustries.Migrations .HasColumnType("nvarchar(max)"); b.Property("SiteCode") - .HasColumnType("nvarchar(max)"); + .HasMaxLength(450) + .HasColumnType("nvarchar(450)"); b.Property("Source") .HasColumnType("nvarchar(max)"); @@ -2127,8 +2208,6 @@ namespace Data.SeaHavenIndustries.Migrations b.HasIndex("AssignTo"); - b.HasIndex("AssignTo", "ScheduledDate"); - b.HasIndex("ExternalWorkOrderId") .IsUnique() .HasFilter("[ExternalWorkOrderId] IS NOT NULL AND [ExternalWorkOrderId] <> ''"); @@ -2136,9 +2215,6 @@ namespace Data.SeaHavenIndustries.Migrations b.HasIndex("InternalWONumber") .HasFilter("[istemplate] = 0"); - b.HasIndex("LifecycleStatus", "ScheduledDate") - .HasFilter("[istemplate] = 0"); - b.HasIndex("LocationId"); b.HasIndex("PrimaryDispatchId"); @@ -2150,7 +2226,12 @@ namespace Data.SeaHavenIndustries.Migrations b.HasIndex("WorkOrderType"); - b.ToTable("workOrders", (string)null); + b.HasIndex("AssignTo", "ScheduledDate"); + + b.HasIndex("LifecycleStatus", "ScheduledDate") + .HasFilter("[istemplate] = 0"); + + b.ToTable("workOrders"); }); modelBuilder.Entity("Data.SeaHavenIndustries.WorkOrderAttachments", b => @@ -2195,7 +2276,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasIndex("WorkorderId"); - b.ToTable("workOrderAttachments", (string)null); + b.ToTable("workOrderAttachments"); }); modelBuilder.Entity("Data.SeaHavenIndustries.WorkOrderAuditLog", b => @@ -2245,7 +2326,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasIndex("WorkOrderId"); - b.ToTable("WorkOrderAuditLogs", (string)null); + b.ToTable("WorkOrderAuditLogs"); }); modelBuilder.Entity("Data.SeaHavenIndustries.WorkOrderCategories", b => @@ -2289,7 +2370,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasIndex("WorkorderId"); - b.ToTable("workOrderCategories", (string)null); + b.ToTable("workOrderCategories"); }); modelBuilder.Entity("Data.SeaHavenIndustries.WorkOrderContacts", b => @@ -2336,7 +2417,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasIndex("WorkorderId"); - b.ToTable("WorkOrderContacts", (string)null); + b.ToTable("WorkOrderContacts"); }); modelBuilder.Entity("Data.SeaHavenIndustries.WorkOrderFieldLock", b => @@ -2365,7 +2446,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasIndex("WorkOrderId", "FieldName") .IsUnique(); - b.ToTable("WorkOrderFieldLocks", (string)null); + b.ToTable("WorkOrderFieldLocks"); }); modelBuilder.Entity("Data.SeaHavenIndustries.WorkOrderWeekRolledLedger", b => @@ -2394,7 +2475,7 @@ namespace Data.SeaHavenIndustries.Migrations b.HasIndex("WorkOrderId", "SourceWeekStart") .IsUnique(); - b.ToTable("WorkOrderWeekRolledLedgers", (string)null); + b.ToTable("WorkOrderWeekRolledLedgers"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => @@ -2963,10 +3044,10 @@ namespace Data.SeaHavenIndustries.Migrations b.Navigation("WorkOrder"); }); - modelBuilder.Entity("Data.SeaHavenIndustries.WorkOrderWeekRolledLedger", b => + modelBuilder.Entity("Data.SeaHavenIndustries.WorkOrderFieldLock", b => { b.HasOne("Data.SeaHavenIndustries.WorkOrder", "WorkOrder") - .WithMany() + .WithMany("FieldLocks") .HasForeignKey("WorkOrderId") .OnDelete(DeleteBehavior.Restrict) .IsRequired(); @@ -2974,10 +3055,10 @@ namespace Data.SeaHavenIndustries.Migrations b.Navigation("WorkOrder"); }); - modelBuilder.Entity("Data.SeaHavenIndustries.WorkOrderFieldLock", b => + modelBuilder.Entity("Data.SeaHavenIndustries.WorkOrderWeekRolledLedger", b => { b.HasOne("Data.SeaHavenIndustries.WorkOrder", "WorkOrder") - .WithMany("FieldLocks") + .WithMany() .HasForeignKey("WorkOrderId") .OnDelete(DeleteBehavior.Restrict) .IsRequired(); diff --git a/Data.SeaHavenIndustries/Models/WorkerOrder.cs b/Data.SeaHavenIndustries/Models/WorkerOrder.cs index 052c2d3..15b5222 100644 --- a/Data.SeaHavenIndustries/Models/WorkerOrder.cs +++ b/Data.SeaHavenIndustries/Models/WorkerOrder.cs @@ -7,12 +7,15 @@ namespace Data.SeaHavenIndustries public class WorkOrder : FullAuditEntity { // --- Core slice --- + [MaxLength(450)] public string? InternalWONumber { get; set; } + [MaxLength(450)] public string? ExternalWorkOrderId { get; set; } public string? WorkerOrderNumber { get; set; } public string? WorkerOrderTitle { get; set; } public string? Description { get; set; } public string? Customer { get; set; } + [MaxLength(450)] public string? SiteCode { get; set; } public string? Building { get; set; } public string? Severity { get; set; } @@ -27,6 +30,7 @@ namespace Data.SeaHavenIndustries public string? LegacyStatus { get; set; } public WorkOrderType? WorkOrderType { get; set; } /// SHOC board "Service" column (PM type label). Not Trade/Problem. + [MaxLength(128)] public string? Service { get; set; } public int? PrimaryDispatchId { get; set; } [ForeignKey(nameof(PrimaryDispatchId))]