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.
This commit is contained in:
Arthur Bassi 2026-07-17 11:10:59 -03:00
parent a930d75ce0
commit 4e32c487d2
6 changed files with 354 additions and 131 deletions

View file

@ -49,10 +49,18 @@ namespace Data.SeaHavenIndustries
.Property(w => w.RowVersion) .Property(w => w.RowVersion)
.IsRowVersion(); .IsRowVersion();
builder.Entity<WorkOrder>()
.Property(w => w.SiteCode)
.HasMaxLength(450);
builder.Entity<WorkOrder>() builder.Entity<WorkOrder>()
.HasIndex(w => w.SiteCode) .HasIndex(w => w.SiteCode)
.HasFilter("[istemplate] = 0"); .HasFilter("[istemplate] = 0");
builder.Entity<WorkOrder>()
.Property(w => w.InternalWONumber)
.HasMaxLength(450);
builder.Entity<WorkOrder>() builder.Entity<WorkOrder>()
.HasIndex(w => w.InternalWONumber) .HasIndex(w => w.InternalWONumber)
.HasFilter("[istemplate] = 0"); .HasFilter("[istemplate] = 0");
@ -61,6 +69,23 @@ namespace Data.SeaHavenIndustries
.HasIndex(w => new { w.LifecycleStatus, w.ScheduledDate }) .HasIndex(w => new { w.LifecycleStatus, w.ScheduledDate })
.HasFilter("[istemplate] = 0"); .HasFilter("[istemplate] = 0");
// Phase 1 board indexes (must stay in model to match snapshot / existing DBs).
builder.Entity<WorkOrder>()
.HasIndex(w => w.AssignTo);
builder.Entity<WorkOrder>()
.HasIndex(w => w.ScheduledDate);
builder.Entity<WorkOrder>()
.HasIndex(w => new { w.AssignTo, w.ScheduledDate });
builder.Entity<WorkOrder>()
.HasIndex(w => w.WorkOrderType);
builder.Entity<WorkOrder>()
.Property(w => w.Service)
.HasMaxLength(128);
builder.Entity<WorkOrder>() builder.Entity<WorkOrder>()
.Property(w => w.ExternalWorkOrderId) .Property(w => w.ExternalWorkOrderId)
.HasMaxLength(450); .HasMaxLength(450);

View file

@ -10,6 +10,27 @@ namespace Data.SeaHavenIndustries.Migrations
/// <inheritdoc /> /// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
{ {
// nvarchar(max) cannot be an index key; shrink before indexing.
migrationBuilder.AlterColumn<string>(
name: "SiteCode",
table: "workOrders",
type: "nvarchar(450)",
maxLength: 450,
nullable: true,
oldClrType: typeof(string),
oldType: "nvarchar(max)",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "InternalWONumber",
table: "workOrders",
type: "nvarchar(450)",
maxLength: 450,
nullable: true,
oldClrType: typeof(string),
oldType: "nvarchar(max)",
oldNullable: true);
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_workOrders_SiteCode", name: "IX_workOrders_SiteCode",
table: "workOrders", table: "workOrders",
@ -43,6 +64,26 @@ namespace Data.SeaHavenIndustries.Migrations
migrationBuilder.DropIndex( migrationBuilder.DropIndex(
name: "IX_workOrders_LifecycleStatus_ScheduledDate", name: "IX_workOrders_LifecycleStatus_ScheduledDate",
table: "workOrders"); table: "workOrders");
migrationBuilder.AlterColumn<string>(
name: "SiteCode",
table: "workOrders",
type: "nvarchar(max)",
nullable: true,
oldClrType: typeof(string),
oldType: "nvarchar(450)",
oldMaxLength: 450,
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "InternalWONumber",
table: "workOrders",
type: "nvarchar(max)",
nullable: true,
oldClrType: typeof(string),
oldType: "nvarchar(450)",
oldMaxLength: 450,
oldNullable: true);
} }
} }
} }

View file

@ -1,3 +1,5 @@
using Data.SeaHavenIndustries;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable #nullable disable
@ -5,45 +7,57 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace Data.SeaHavenIndustries.Migrations namespace Data.SeaHavenIndustries.Migrations
{ {
/// <inheritdoc /> /// <inheritdoc />
[DbContext(typeof(ApplicationDbContext))]
[Migration("20260713120000_Phase7_ExternalWorkOrderIdUnique")]
public partial class Phase7_ExternalWorkOrderIdUnique : Migration public partial class Phase7_ExternalWorkOrderIdUnique : Migration
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
{ {
migrationBuilder.AlterColumn<string>( // Idempotent: column may already be nvarchar(450) in some environments.
name: "ExternalWorkOrderId", migrationBuilder.Sql(@"
table: "workOrders", IF COL_LENGTH('workOrders', 'ExternalWorkOrderId') IS NOT NULL
type: "nvarchar(450)", AND EXISTS (
maxLength: 450, SELECT 1
nullable: true, FROM sys.columns c
oldClrType: typeof(string), INNER JOIN sys.types t ON c.user_type_id = t.user_type_id
oldType: "nvarchar(max)", WHERE c.object_id = OBJECT_ID(N'dbo.workOrders')
oldNullable: true); 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( migrationBuilder.Sql(@"
name: "IX_workOrders_ExternalWorkOrderId", IF NOT EXISTS (
table: "workOrders", SELECT 1 FROM sys.indexes
column: "ExternalWorkOrderId", WHERE name = N'IX_workOrders_ExternalWorkOrderId'
unique: true, AND object_id = OBJECT_ID(N'dbo.workOrders'))
filter: "[ExternalWorkOrderId] IS NOT NULL AND [ExternalWorkOrderId] <> ''"); BEGIN
CREATE UNIQUE INDEX IX_workOrders_ExternalWorkOrderId
ON workOrders (ExternalWorkOrderId)
WHERE [ExternalWorkOrderId] IS NOT NULL AND [ExternalWorkOrderId] <> '';
END
");
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder) protected override void Down(MigrationBuilder migrationBuilder)
{ {
migrationBuilder.DropIndex( migrationBuilder.Sql(@"
name: "IX_workOrders_ExternalWorkOrderId", IF EXISTS (
table: "workOrders"); 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<string>( migrationBuilder.Sql(@"
name: "ExternalWorkOrderId", IF COL_LENGTH('workOrders', 'ExternalWorkOrderId') IS NOT NULL
table: "workOrders", ALTER TABLE workOrders ALTER COLUMN ExternalWorkOrderId nvarchar(max) NULL;
type: "nvarchar(max)", ");
nullable: true,
oldClrType: typeof(string),
oldType: "nvarchar(450)",
oldMaxLength: 450,
oldNullable: true);
} }
} }
} }

View file

@ -0,0 +1,58 @@
using Data.SeaHavenIndustries;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Data.SeaHavenIndustries.Migrations
{
/// <inheritdoc />
[DbContext(typeof(ApplicationDbContext))]
[Migration("20260717140000_AddEventsCalendarTable")]
public partial class AddEventsCalendarTable : Migration
{
/// <inheritdoc />
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
");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql(@"
IF OBJECT_ID(N'dbo.Events', N'U') IS NOT NULL
DROP TABLE Events;
");
}
}
}

View file

@ -107,7 +107,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.ToTable("Accounts", (string)null); b.ToTable("Accounts");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.Addresses", b => modelBuilder.Entity("Data.SeaHavenIndustries.Addresses", b =>
@ -175,7 +175,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasIndex("ContactId"); b.HasIndex("ContactId");
b.ToTable("Addresses", (string)null); b.ToTable("Addresses");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.ApplicationUser", b => modelBuilder.Entity("Data.SeaHavenIndustries.ApplicationUser", b =>
@ -334,7 +334,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasIndex("LocationId"); b.HasIndex("LocationId");
b.ToTable("Assets", (string)null); b.ToTable("Assets");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.Category", b => modelBuilder.Entity("Data.SeaHavenIndustries.Category", b =>
@ -371,62 +371,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.ToTable("Categories", (string)null); b.ToTable("Categories");
});
modelBuilder.Entity("Data.SeaHavenIndustries.CompletionDocTemplate", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime?>("CreatedDate")
.HasColumnType("datetime2");
b.Property<string>("DeleterUserId")
.HasColumnType("nvarchar(max)");
b.Property<DateTime?>("DeletionTime")
.HasColumnType("datetime2");
b.Property<bool>("IsActive")
.HasColumnType("bit");
b.Property<bool?>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime?>("LastModificationTime")
.HasColumnType("datetime2");
b.Property<int?>("LastModifierUserId")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("ServiceKey")
.IsRequired()
.HasColumnType("nvarchar(450)");
b.Property<string>("TemplateUrl")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int?>("WorkOrderType")
.HasColumnType("int");
b.Property<string>("createdby")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("ServiceKey", "IsActive")
.HasDatabaseName("IX_CompletionDocTemplates_ServiceKey_IsActive");
b.ToTable("CompletionDocTemplates", (string)null);
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.Comments", b => modelBuilder.Entity("Data.SeaHavenIndustries.Comments", b =>
@ -493,7 +438,61 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasIndex("WorkerOrderId"); b.HasIndex("WorkerOrderId");
b.ToTable("Comments", (string)null); b.ToTable("Comments");
});
modelBuilder.Entity("Data.SeaHavenIndustries.CompletionDocTemplate", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime?>("CreatedDate")
.HasColumnType("datetime2");
b.Property<string>("DeleterUserId")
.HasColumnType("nvarchar(max)");
b.Property<DateTime?>("DeletionTime")
.HasColumnType("datetime2");
b.Property<bool>("IsActive")
.HasColumnType("bit");
b.Property<bool?>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime?>("LastModificationTime")
.HasColumnType("datetime2");
b.Property<int?>("LastModifierUserId")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("ServiceKey")
.IsRequired()
.HasColumnType("nvarchar(450)");
b.Property<string>("TemplateUrl")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int?>("WorkOrderType")
.HasColumnType("int");
b.Property<string>("createdby")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("ServiceKey", "IsActive");
b.ToTable("CompletionDocTemplates");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.ContactDetails", b => modelBuilder.Entity("Data.SeaHavenIndustries.ContactDetails", b =>
@ -559,7 +558,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasIndex("ContactId"); b.HasIndex("ContactId");
b.ToTable("ContactDetails", (string)null); b.ToTable("ContactDetails");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.Contacts", b => modelBuilder.Entity("Data.SeaHavenIndustries.Contacts", b =>
@ -651,7 +650,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasIndex("LocationId"); b.HasIndex("LocationId");
b.ToTable("Contacts", (string)null); b.ToTable("Contacts");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.Department", b => modelBuilder.Entity("Data.SeaHavenIndustries.Department", b =>
@ -669,7 +668,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.ToTable("Departments", (string)null); b.ToTable("Departments");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.Dispatch", b => modelBuilder.Entity("Data.SeaHavenIndustries.Dispatch", b =>
@ -768,7 +767,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasIndex("WorkOrderId"); b.HasIndex("WorkOrderId");
b.ToTable("Dispatches", (string)null); b.ToTable("Dispatches");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.DispatchChecklistItem", b => modelBuilder.Entity("Data.SeaHavenIndustries.DispatchChecklistItem", b =>
@ -827,7 +826,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasIndex("WorkOrderId"); b.HasIndex("WorkOrderId");
b.ToTable("DispatchChecklistItems", (string)null); b.ToTable("DispatchChecklistItems");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.DispatchSignoff", b => modelBuilder.Entity("Data.SeaHavenIndustries.DispatchSignoff", b =>
@ -881,7 +880,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasIndex("DispatchId"); b.HasIndex("DispatchId");
b.ToTable("DispatchSignoffs", (string)null); b.ToTable("DispatchSignoffs");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.DispatchUpliftRequest", b => modelBuilder.Entity("Data.SeaHavenIndustries.DispatchUpliftRequest", b =>
@ -951,7 +950,7 @@ namespace Data.SeaHavenIndustries.Migrations
.IsUnique() .IsUnique()
.HasFilter("[Status] = 'Pending'"); .HasFilter("[Status] = 'Pending'");
b.ToTable("DispatchUpliftRequests", (string)null); b.ToTable("DispatchUpliftRequests");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.DispatchWorkOrder", b => modelBuilder.Entity("Data.SeaHavenIndustries.DispatchWorkOrder", b =>
@ -974,7 +973,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasIndex("WorkOrderId"); b.HasIndex("WorkOrderId");
b.ToTable("DispatchWorkOrders", (string)null); b.ToTable("DispatchWorkOrders");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.DropdownOption", b => modelBuilder.Entity("Data.SeaHavenIndustries.DropdownOption", b =>
@ -1004,7 +1003,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.ToTable("DropdownOptions", (string)null); b.ToTable("DropdownOptions");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.Employee", b => modelBuilder.Entity("Data.SeaHavenIndustries.Employee", b =>
@ -1109,7 +1108,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasIndex("RegionId"); b.HasIndex("RegionId");
b.ToTable("Employees", (string)null); b.ToTable("Employees");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.EmployeeAddress", b => modelBuilder.Entity("Data.SeaHavenIndustries.EmployeeAddress", b =>
@ -1149,7 +1148,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasIndex("EmployeeId") b.HasIndex("EmployeeId")
.IsUnique(); .IsUnique();
b.ToTable("EmployeeAddresses", (string)null); b.ToTable("EmployeeAddresses");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.EmployeeEmail", b => modelBuilder.Entity("Data.SeaHavenIndustries.EmployeeEmail", b =>
@ -1177,7 +1176,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasIndex("EmployeeId"); b.HasIndex("EmployeeId");
b.ToTable("EmployeeEmails", (string)null); b.ToTable("EmployeeEmails");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.EmployeePhone", b => modelBuilder.Entity("Data.SeaHavenIndustries.EmployeePhone", b =>
@ -1207,7 +1206,87 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasIndex("EmployeeId"); b.HasIndex("EmployeeId");
b.ToTable("EmployeePhones", (string)null); b.ToTable("EmployeePhones");
});
modelBuilder.Entity("Data.SeaHavenIndustries.Events", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<bool>("AllDay")
.HasColumnType("bit");
b.Property<DateTime?>("CreatedDate")
.HasColumnType("datetime2");
b.Property<string>("DeleterUserId")
.HasColumnType("nvarchar(max)");
b.Property<DateTime?>("DeletionTime")
.HasColumnType("datetime2");
b.Property<string>("Description")
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("EndDate")
.HasColumnType("datetime2");
b.Property<string>("EndTime")
.HasMaxLength(10)
.HasColumnType("nvarchar(10)");
b.Property<string>("EventColor")
.IsRequired()
.HasMaxLength(20)
.HasColumnType("nvarchar(20)");
b.Property<bool?>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime?>("LastModificationTime")
.HasColumnType("datetime2");
b.Property<int?>("LastModifierUserId")
.HasColumnType("int");
b.Property<string>("Location")
.HasMaxLength(150)
.HasColumnType("nvarchar(150)");
b.Property<int?>("RecordID")
.HasColumnType("int");
b.Property<string>("RecordName")
.HasColumnType("nvarchar(max)");
b.Property<string>("RecordTargetType")
.HasColumnType("nvarchar(max)");
b.Property<int>("ReminderMinutes")
.HasColumnType("int");
b.Property<DateTime>("StartDate")
.HasColumnType("datetime2");
b.Property<string>("StartTime")
.HasMaxLength(10)
.HasColumnType("nvarchar(10)");
b.Property<string>("Title")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("nvarchar(100)");
b.Property<string>("createdby")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Events");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.FollowUps", b => modelBuilder.Entity("Data.SeaHavenIndustries.FollowUps", b =>
@ -1275,7 +1354,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasIndex("WorkOrderId"); b.HasIndex("WorkOrderId");
b.ToTable("FollowUps", (string)null); b.ToTable("FollowUps");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.ForgetPasswordCode", b => modelBuilder.Entity("Data.SeaHavenIndustries.ForgetPasswordCode", b =>
@ -1300,7 +1379,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.ToTable("ForgetPasswordCodes", (string)null); b.ToTable("ForgetPasswordCodes");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.JobTitle", b => modelBuilder.Entity("Data.SeaHavenIndustries.JobTitle", b =>
@ -1318,7 +1397,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.ToTable("JobTitles", (string)null); b.ToTable("JobTitles");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.Locations", b => modelBuilder.Entity("Data.SeaHavenIndustries.Locations", b =>
@ -1388,7 +1467,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.ToTable("Locations", (string)null); b.ToTable("Locations");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.PMSchedules", b => modelBuilder.Entity("Data.SeaHavenIndustries.PMSchedules", b =>
@ -1446,7 +1525,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasIndex("LocationId"); b.HasIndex("LocationId");
b.ToTable("PMSchedules", (string)null); b.ToTable("PMSchedules");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.Quotes", b => modelBuilder.Entity("Data.SeaHavenIndustries.Quotes", b =>
@ -1520,7 +1599,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasIndex("WorkorderId"); b.HasIndex("WorkorderId");
b.ToTable("Quotes", (string)null); b.ToTable("Quotes");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.QuotesLineItems", b => modelBuilder.Entity("Data.SeaHavenIndustries.QuotesLineItems", b =>
@ -1568,7 +1647,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasIndex("QuoteId"); b.HasIndex("QuoteId");
b.ToTable("QuotesLines", (string)null); b.ToTable("QuotesLines");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.Region", b => modelBuilder.Entity("Data.SeaHavenIndustries.Region", b =>
@ -1586,7 +1665,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.ToTable("Regions", (string)null); b.ToTable("Regions");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.TaskListTemplate", b => modelBuilder.Entity("Data.SeaHavenIndustries.TaskListTemplate", b =>
@ -1629,7 +1708,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.ToTable("TaskListTemplates", (string)null); b.ToTable("TaskListTemplates");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.TaskListTemplateItem", b => modelBuilder.Entity("Data.SeaHavenIndustries.TaskListTemplateItem", b =>
@ -1674,7 +1753,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasIndex("TaskListTemplateId"); b.HasIndex("TaskListTemplateId");
b.ToTable("TaskListTemplateItems", (string)null); b.ToTable("TaskListTemplateItems");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.Template", b => modelBuilder.Entity("Data.SeaHavenIndustries.Template", b =>
@ -1776,7 +1855,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasIndex("LocationId"); b.HasIndex("LocationId");
b.ToTable("Templates", (string)null); b.ToTable("Templates");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.Vendor", b => modelBuilder.Entity("Data.SeaHavenIndustries.Vendor", b =>
@ -1840,7 +1919,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.ToTable("Vendors", (string)null); b.ToTable("Vendors");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.VendorAccessToken", b => modelBuilder.Entity("Data.SeaHavenIndustries.VendorAccessToken", b =>
@ -1899,7 +1978,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasIndex("VendorId"); b.HasIndex("VendorId");
b.ToTable("VendorAccessTokens", (string)null); b.ToTable("VendorAccessTokens");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.WorkOrder", b => modelBuilder.Entity("Data.SeaHavenIndustries.WorkOrder", b =>
@ -1980,7 +2059,8 @@ namespace Data.SeaHavenIndustries.Migrations
.HasColumnType("nvarchar(7)"); .HasColumnType("nvarchar(7)");
b.Property<string>("InternalWONumber") b.Property<string>("InternalWONumber")
.HasColumnType("nvarchar(max)"); .HasMaxLength(450)
.HasColumnType("nvarchar(450)");
b.Property<bool?>("IsDeleted") b.Property<bool?>("IsDeleted")
.HasColumnType("bit"); .HasColumnType("bit");
@ -2074,7 +2154,8 @@ namespace Data.SeaHavenIndustries.Migrations
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.Property<string>("SiteCode") b.Property<string>("SiteCode")
.HasColumnType("nvarchar(max)"); .HasMaxLength(450)
.HasColumnType("nvarchar(450)");
b.Property<string>("Source") b.Property<string>("Source")
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
@ -2127,8 +2208,6 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasIndex("AssignTo"); b.HasIndex("AssignTo");
b.HasIndex("AssignTo", "ScheduledDate");
b.HasIndex("ExternalWorkOrderId") b.HasIndex("ExternalWorkOrderId")
.IsUnique() .IsUnique()
.HasFilter("[ExternalWorkOrderId] IS NOT NULL AND [ExternalWorkOrderId] <> ''"); .HasFilter("[ExternalWorkOrderId] IS NOT NULL AND [ExternalWorkOrderId] <> ''");
@ -2136,9 +2215,6 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasIndex("InternalWONumber") b.HasIndex("InternalWONumber")
.HasFilter("[istemplate] = 0"); .HasFilter("[istemplate] = 0");
b.HasIndex("LifecycleStatus", "ScheduledDate")
.HasFilter("[istemplate] = 0");
b.HasIndex("LocationId"); b.HasIndex("LocationId");
b.HasIndex("PrimaryDispatchId"); b.HasIndex("PrimaryDispatchId");
@ -2150,7 +2226,12 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasIndex("WorkOrderType"); 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 => modelBuilder.Entity("Data.SeaHavenIndustries.WorkOrderAttachments", b =>
@ -2195,7 +2276,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasIndex("WorkorderId"); b.HasIndex("WorkorderId");
b.ToTable("workOrderAttachments", (string)null); b.ToTable("workOrderAttachments");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.WorkOrderAuditLog", b => modelBuilder.Entity("Data.SeaHavenIndustries.WorkOrderAuditLog", b =>
@ -2245,7 +2326,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasIndex("WorkOrderId"); b.HasIndex("WorkOrderId");
b.ToTable("WorkOrderAuditLogs", (string)null); b.ToTable("WorkOrderAuditLogs");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.WorkOrderCategories", b => modelBuilder.Entity("Data.SeaHavenIndustries.WorkOrderCategories", b =>
@ -2289,7 +2370,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasIndex("WorkorderId"); b.HasIndex("WorkorderId");
b.ToTable("workOrderCategories", (string)null); b.ToTable("workOrderCategories");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.WorkOrderContacts", b => modelBuilder.Entity("Data.SeaHavenIndustries.WorkOrderContacts", b =>
@ -2336,7 +2417,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasIndex("WorkorderId"); b.HasIndex("WorkorderId");
b.ToTable("WorkOrderContacts", (string)null); b.ToTable("WorkOrderContacts");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.WorkOrderFieldLock", b => modelBuilder.Entity("Data.SeaHavenIndustries.WorkOrderFieldLock", b =>
@ -2365,7 +2446,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasIndex("WorkOrderId", "FieldName") b.HasIndex("WorkOrderId", "FieldName")
.IsUnique(); .IsUnique();
b.ToTable("WorkOrderFieldLocks", (string)null); b.ToTable("WorkOrderFieldLocks");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.WorkOrderWeekRolledLedger", b => modelBuilder.Entity("Data.SeaHavenIndustries.WorkOrderWeekRolledLedger", b =>
@ -2394,7 +2475,7 @@ namespace Data.SeaHavenIndustries.Migrations
b.HasIndex("WorkOrderId", "SourceWeekStart") b.HasIndex("WorkOrderId", "SourceWeekStart")
.IsUnique(); .IsUnique();
b.ToTable("WorkOrderWeekRolledLedgers", (string)null); b.ToTable("WorkOrderWeekRolledLedgers");
}); });
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
@ -2963,10 +3044,10 @@ namespace Data.SeaHavenIndustries.Migrations
b.Navigation("WorkOrder"); b.Navigation("WorkOrder");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.WorkOrderWeekRolledLedger", b => modelBuilder.Entity("Data.SeaHavenIndustries.WorkOrderFieldLock", b =>
{ {
b.HasOne("Data.SeaHavenIndustries.WorkOrder", "WorkOrder") b.HasOne("Data.SeaHavenIndustries.WorkOrder", "WorkOrder")
.WithMany() .WithMany("FieldLocks")
.HasForeignKey("WorkOrderId") .HasForeignKey("WorkOrderId")
.OnDelete(DeleteBehavior.Restrict) .OnDelete(DeleteBehavior.Restrict)
.IsRequired(); .IsRequired();
@ -2974,10 +3055,10 @@ namespace Data.SeaHavenIndustries.Migrations
b.Navigation("WorkOrder"); b.Navigation("WorkOrder");
}); });
modelBuilder.Entity("Data.SeaHavenIndustries.WorkOrderFieldLock", b => modelBuilder.Entity("Data.SeaHavenIndustries.WorkOrderWeekRolledLedger", b =>
{ {
b.HasOne("Data.SeaHavenIndustries.WorkOrder", "WorkOrder") b.HasOne("Data.SeaHavenIndustries.WorkOrder", "WorkOrder")
.WithMany("FieldLocks") .WithMany()
.HasForeignKey("WorkOrderId") .HasForeignKey("WorkOrderId")
.OnDelete(DeleteBehavior.Restrict) .OnDelete(DeleteBehavior.Restrict)
.IsRequired(); .IsRequired();

View file

@ -7,12 +7,15 @@ namespace Data.SeaHavenIndustries
public class WorkOrder : FullAuditEntity public class WorkOrder : FullAuditEntity
{ {
// --- Core slice --- // --- Core slice ---
[MaxLength(450)]
public string? InternalWONumber { get; set; } public string? InternalWONumber { get; set; }
[MaxLength(450)]
public string? ExternalWorkOrderId { get; set; } public string? ExternalWorkOrderId { get; set; }
public string? WorkerOrderNumber { get; set; } public string? WorkerOrderNumber { get; set; }
public string? WorkerOrderTitle { get; set; } public string? WorkerOrderTitle { get; set; }
public string? Description { get; set; } public string? Description { get; set; }
public string? Customer { get; set; } public string? Customer { get; set; }
[MaxLength(450)]
public string? SiteCode { get; set; } public string? SiteCode { get; set; }
public string? Building { get; set; } public string? Building { get; set; }
public string? Severity { get; set; } public string? Severity { get; set; }
@ -27,6 +30,7 @@ namespace Data.SeaHavenIndustries
public string? LegacyStatus { get; set; } public string? LegacyStatus { get; set; }
public WorkOrderType? WorkOrderType { get; set; } public WorkOrderType? WorkOrderType { get; set; }
/// <summary>SHOC board "Service" column (PM type label). Not Trade/Problem.</summary> /// <summary>SHOC board "Service" column (PM type label). Not Trade/Problem.</summary>
[MaxLength(128)]
public string? Service { get; set; } public string? Service { get; set; }
public int? PrimaryDispatchId { get; set; } public int? PrimaryDispatchId { get; set; }
[ForeignKey(nameof(PrimaryDispatchId))] [ForeignKey(nameof(PrimaryDispatchId))]