From 44c31acbf01a0c6487b3ff8e91ee5c50147be352 Mon Sep 17 00:00:00 2001 From: Ian Nelson Date: Thu, 12 Jun 2025 13:49:47 +0100 Subject: [PATCH] fix: rename column --- .../NbssAppointmentEvents/StagingPersister.cs | 2 +- .../20250612124923_RenameProperty.Designer.cs | 225 ++++++++++++++++++ .../20250612124923_RenameProperty.cs | 28 +++ .../ServiceLayerDbContextModelSnapshot.cs | 8 +- .../Data/Models/NbssAppointmentEvent.cs | 2 +- .../StagingPersisterTests.cs | 2 +- 6 files changed, 260 insertions(+), 7 deletions(-) create mode 100644 src/ServiceLayer.Shared/Data/Migrations/20250612124923_RenameProperty.Designer.cs create mode 100644 src/ServiceLayer.Shared/Data/Migrations/20250612124923_RenameProperty.cs diff --git a/src/ServiceLayer.Mesh/FileTypes/NbssAppointmentEvents/StagingPersister.cs b/src/ServiceLayer.Mesh/FileTypes/NbssAppointmentEvents/StagingPersister.cs index 650c9aa9..e197f105 100644 --- a/src/ServiceLayer.Mesh/FileTypes/NbssAppointmentEvents/StagingPersister.cs +++ b/src/ServiceLayer.Mesh/FileTypes/NbssAppointmentEvents/StagingPersister.cs @@ -28,7 +28,7 @@ private static List MapFileDataRecordsToNbssAppointmentEve HoldingClinic = NullIfWhiteSpace(record.Fields["Holding Clinic"]), Status = record.Fields["Status"], AttendedNotScreened = NullIfWhiteSpace(record.Fields["Attended Not Scr"]), - AppointmenId = record.Fields["Appointment ID"], + AppointmentId = record.Fields["Appointment ID"], NhsNumber = record.Fields["NHS Num"], EpisodeType = record.Fields["Episode Type"], EpisodeStart = DateOnly.ParseExact(record.Fields["Episode Start"], "yyyyMMdd", CultureInfo.InvariantCulture), diff --git a/src/ServiceLayer.Shared/Data/Migrations/20250612124923_RenameProperty.Designer.cs b/src/ServiceLayer.Shared/Data/Migrations/20250612124923_RenameProperty.Designer.cs new file mode 100644 index 00000000..476dd308 --- /dev/null +++ b/src/ServiceLayer.Shared/Data/Migrations/20250612124923_RenameProperty.Designer.cs @@ -0,0 +1,225 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using ServiceLayer.Data; + +#nullable disable + +namespace ServiceLayer.Mesh.Migrations +{ + [DbContext(typeof(ServiceLayerDbContext))] + [Migration("20250612124923_RenameProperty")] + partial class RenameProperty + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.5") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("ServiceLayer.Data.Models.MeshFile", b => + { + b.Property("FileId") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("BlobPath") + .HasMaxLength(1024) + .HasColumnType("nvarchar(1024)"); + + b.Property("FileType") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("FirstSeenUtc") + .HasColumnType("datetime2"); + + b.Property("LastUpdatedUtc") + .HasColumnType("datetime2"); + + b.Property("MailboxId") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Status") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.Property("ValidationErrors") + .HasColumnType("nvarchar(max)"); + + b.HasKey("FileId"); + + b.ToTable("MeshFiles"); + }); + + modelBuilder.Entity("ServiceLayer.Data.Models.NbssAppointmentEvent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Action") + .IsRequired() + .HasMaxLength(1) + .HasColumnType("char(1)"); + + b.Property("ActionTimestamp") + .HasColumnType("datetime2(0)"); + + b.Property("AppointmentDateTime") + .HasColumnType("datetime2(0)"); + + b.Property("AppointmentId") + .IsRequired() + .HasMaxLength(27) + .HasColumnType("varchar(27)"); + + b.Property("AppointmentType") + .IsRequired() + .HasMaxLength(1) + .HasColumnType("char(1)"); + + b.Property("AttendedNotScreened") + .HasMaxLength(1) + .HasColumnType("char(1)"); + + b.Property("BSO") + .IsRequired() + .HasMaxLength(3) + .HasColumnType("char(3)"); + + b.Property("BatchId") + .IsRequired() + .HasMaxLength(9) + .HasColumnType("varchar(9)"); + + b.Property("BookedBy") + .IsRequired() + .HasMaxLength(1) + .HasColumnType("char(1)"); + + b.Property("CancelledBy") + .HasMaxLength(1) + .HasColumnType("char(1)"); + + b.Property("ClinicAddressLine1") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("varchar(30)"); + + b.Property("ClinicAddressLine2") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("varchar(30)"); + + b.Property("ClinicAddressLine3") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("varchar(30)"); + + b.Property("ClinicAddressLine4") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("varchar(30)"); + + b.Property("ClinicAddressLine5") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("varchar(30)"); + + b.Property("ClinicCode") + .IsRequired() + .HasMaxLength(5) + .HasColumnType("varchar(5)"); + + b.Property("ClinicName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)"); + + b.Property("ClinicNameOnLetters") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("ClinicPostcode") + .IsRequired() + .HasMaxLength(8) + .HasColumnType("varchar(8)"); + + b.Property("EpisodeStart") + .HasColumnType("date"); + + b.Property("EpisodeType") + .IsRequired() + .HasMaxLength(1) + .HasColumnType("char(1)"); + + b.Property("ExtractId") + .IsRequired() + .HasMaxLength(8) + .HasColumnType("char(8)"); + + b.Property("HoldingClinic") + .HasMaxLength(1) + .HasColumnType("char(1)"); + + b.Property("Location") + .IsRequired() + .HasMaxLength(5) + .HasColumnType("varchar(5)"); + + b.Property("MeshFileId") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("NhsNumber") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("char(10)"); + + b.Property("ScreeningAppointmentNumber") + .HasColumnType("tinyint"); + + b.Property("Sequence") + .IsRequired() + .HasMaxLength(6) + .HasColumnType("char(6)"); + + b.Property("Status") + .IsRequired() + .HasMaxLength(1) + .HasColumnType("char(1)"); + + b.HasKey("Id"); + + b.HasIndex("MeshFileId"); + + b.ToTable("NbssAppointmentEvents"); + }); + + modelBuilder.Entity("ServiceLayer.Data.Models.NbssAppointmentEvent", b => + { + b.HasOne("ServiceLayer.Data.Models.MeshFile", null) + .WithMany() + .HasForeignKey("MeshFileId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/ServiceLayer.Shared/Data/Migrations/20250612124923_RenameProperty.cs b/src/ServiceLayer.Shared/Data/Migrations/20250612124923_RenameProperty.cs new file mode 100644 index 00000000..5affd9e6 --- /dev/null +++ b/src/ServiceLayer.Shared/Data/Migrations/20250612124923_RenameProperty.cs @@ -0,0 +1,28 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ServiceLayer.Mesh.Migrations +{ + /// + public partial class RenameProperty : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameColumn( + name: "AppointmenId", + table: "NbssAppointmentEvents", + newName: "AppointmentId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameColumn( + name: "AppointmentId", + table: "NbssAppointmentEvents", + newName: "AppointmenId"); + } + } +} diff --git a/src/ServiceLayer.Shared/Data/Migrations/ServiceLayerDbContextModelSnapshot.cs b/src/ServiceLayer.Shared/Data/Migrations/ServiceLayerDbContextModelSnapshot.cs index 6a7f1176..ec54481e 100644 --- a/src/ServiceLayer.Shared/Data/Migrations/ServiceLayerDbContextModelSnapshot.cs +++ b/src/ServiceLayer.Shared/Data/Migrations/ServiceLayerDbContextModelSnapshot.cs @@ -75,14 +75,14 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("ActionTimestamp") .HasColumnType("datetime2(0)"); - b.Property("AppointmenId") + b.Property("AppointmentDateTime") + .HasColumnType("datetime2(0)"); + + b.Property("AppointmentId") .IsRequired() .HasMaxLength(27) .HasColumnType("varchar(27)"); - b.Property("AppointmentDateTime") - .HasColumnType("datetime2(0)"); - b.Property("AppointmentType") .IsRequired() .HasMaxLength(1) diff --git a/src/ServiceLayer.Shared/Data/Models/NbssAppointmentEvent.cs b/src/ServiceLayer.Shared/Data/Models/NbssAppointmentEvent.cs index 7a687603..a28b5b7c 100644 --- a/src/ServiceLayer.Shared/Data/Models/NbssAppointmentEvent.cs +++ b/src/ServiceLayer.Shared/Data/Models/NbssAppointmentEvent.cs @@ -34,7 +34,7 @@ public class NbssAppointmentEvent public string? AttendedNotScreened { get; set; } [StringLength(27)] [Column(TypeName = "varchar(27)")] - public required string AppointmenId { get; set; } + public required string AppointmentId { get; set; } [StringLength(10, MinimumLength = 10)] [Column(TypeName = "char(10)")] public required string NhsNumber { get; set; } diff --git a/tests/ServiceLayer.Mesh.Tests/FileTypes/NbssAppointmentEvents/StagingPersisterTests.cs b/tests/ServiceLayer.Mesh.Tests/FileTypes/NbssAppointmentEvents/StagingPersisterTests.cs index 2b775ecb..6b8f778b 100644 --- a/tests/ServiceLayer.Mesh.Tests/FileTypes/NbssAppointmentEvents/StagingPersisterTests.cs +++ b/tests/ServiceLayer.Mesh.Tests/FileTypes/NbssAppointmentEvents/StagingPersisterTests.cs @@ -54,7 +54,7 @@ public async Task WriteStagedData_WhenFileValid_MapsFieldsAndSavesToDb() Assert.Equal(firstRecord["Holding Clinic"], nbssAppointmentEvent.HoldingClinic); Assert.Equal(firstRecord["Status"], nbssAppointmentEvent.Status); Assert.Equal(firstRecord["Attended Not Scr"], nbssAppointmentEvent.AttendedNotScreened); - Assert.Equal(firstRecord["Appointment ID"], nbssAppointmentEvent.AppointmenId); + Assert.Equal(firstRecord["Appointment ID"], nbssAppointmentEvent.AppointmentId); Assert.Equal(firstRecord["NHS Num"], nbssAppointmentEvent.NhsNumber); Assert.Equal(firstRecord["Episode Type"], nbssAppointmentEvent.EpisodeType); Assert.Equal(DateOnly.ParseExact(firstRecord.Fields["Episode Start"], "yyyyMMdd"), nbssAppointmentEvent.EpisodeStart);