diff --git a/Data.SeaHavenIndustries/Auth/ApplicationDbContext.cs b/Data.SeaHavenIndustries/Auth/ApplicationDbContext.cs index 7c45127..1cea35d 100644 --- a/Data.SeaHavenIndustries/Auth/ApplicationDbContext.cs +++ b/Data.SeaHavenIndustries/Auth/ApplicationDbContext.cs @@ -61,6 +61,15 @@ namespace Data.SeaHavenIndustries .HasIndex(w => new { w.LifecycleStatus, w.ScheduledDate }) .HasFilter("[istemplate] = 0"); + builder.Entity() + .Property(w => w.ExternalWorkOrderId) + .HasMaxLength(450); + + builder.Entity() + .HasIndex(w => w.ExternalWorkOrderId) + .IsUnique() + .HasFilter("[ExternalWorkOrderId] IS NOT NULL AND [ExternalWorkOrderId] <> ''"); + builder.Entity() .Property(d => d.RowVersion) .IsRowVersion(); diff --git a/Data.SeaHavenIndustries/Migrations/20260713120000_Phase7_ExternalWorkOrderIdUnique.cs b/Data.SeaHavenIndustries/Migrations/20260713120000_Phase7_ExternalWorkOrderIdUnique.cs new file mode 100644 index 0000000..291a952 --- /dev/null +++ b/Data.SeaHavenIndustries/Migrations/20260713120000_Phase7_ExternalWorkOrderIdUnique.cs @@ -0,0 +1,49 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Data.SeaHavenIndustries.Migrations +{ + /// + 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); + + migrationBuilder.CreateIndex( + name: "IX_workOrders_ExternalWorkOrderId", + table: "workOrders", + column: "ExternalWorkOrderId", + unique: true, + filter: "[ExternalWorkOrderId] IS NOT NULL AND [ExternalWorkOrderId] <> ''"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "IX_workOrders_ExternalWorkOrderId", + table: "workOrders"); + + migrationBuilder.AlterColumn( + name: "ExternalWorkOrderId", + table: "workOrders", + type: "nvarchar(max)", + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(450)", + oldMaxLength: 450, + oldNullable: true); + } + } +} diff --git a/Data.SeaHavenIndustries/Migrations/ApplicationDbContextModelSnapshot.cs b/Data.SeaHavenIndustries/Migrations/ApplicationDbContextModelSnapshot.cs index 2245ad2..d97ab9b 100644 --- a/Data.SeaHavenIndustries/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/Data.SeaHavenIndustries/Migrations/ApplicationDbContextModelSnapshot.cs @@ -1960,7 +1960,8 @@ namespace Data.SeaHavenIndustries.Migrations .HasColumnType("datetime2"); b.Property("ExternalWorkOrderId") - .HasColumnType("nvarchar(max)"); + .HasMaxLength(450) + .HasColumnType("nvarchar(450)"); b.Property("InternalWONumber") .HasColumnType("nvarchar(max)"); @@ -2088,6 +2089,10 @@ namespace Data.SeaHavenIndustries.Migrations b.HasIndex("AssignTo", "ScheduledDate"); + b.HasIndex("ExternalWorkOrderId") + .IsUnique() + .HasFilter("[ExternalWorkOrderId] IS NOT NULL AND [ExternalWorkOrderId] <> ''"); + b.HasIndex("InternalWONumber") .HasFilter("[istemplate] = 0");