GuestDocument Versions - Part 1:

- Changed GuestDocument PK from `DocumentType`+`DocumentNumber` to to `ID`+`Version` for future versioning.
- Added DB field "IsLastVersion" to simplify queries where only last/current version is allowed.
- Updated GuestDocument DB fields type for `CreateTime` & `UpdateTime` to add precision.
- Updated usages of GuestDocument PK to new PK.
- Limit delete of a GuestDocument when it's currently used in a StayEntry.

Note: DB changes require recreating db tables, so all data is lost and migration "rollback" is not allowed.
This commit is contained in:
2026-09-01 15:04:38 +02:00
parent a01eed82e1
commit 887c3d787a
21 changed files with 525 additions and 93 deletions
@@ -10,6 +10,8 @@ public class GuestDocFilterDTO
public string? PhoneNumber { get; set; }
public bool OnlyLastVersion { get; set; }
public bool IsEmpty => string.IsNullOrEmpty(DocumentType)
&& string.IsNullOrEmpty(DocumentNumber)
@@ -2,6 +2,9 @@ namespace Somnia.GuestLog.Models.DTOs;
public class GuestDocumentDTO
{
public long? Id { get; set; }
public int? Version { get; set; }
public string? DocumentType { get; set; }
public string? DocumentNum { get; set; }
@@ -33,5 +36,6 @@ public class GuestDocumentDTO
public DateTime? UpdateTime { get; set; }
public string FullKey => $"{DocumentType}-{DocumentNum}";
public string FullKey => $"{Id}-{Version}";
public string FullDocument => $"{DocumentType ?? "???"}-{DocumentNum ?? "???"}";
}
@@ -2,6 +2,9 @@ namespace Somnia.GuestLog.Models.Entities;
public class GuestDocument : BaseEntity
{
public long Id { get; set; }
public int Version { get; set; }
public required string DocumentType { get; set; }
public required string DocumentNum { get; set; }
@@ -26,6 +29,8 @@ public class GuestDocument : BaseEntity
public required DateTime CreateTime { get; set; }
public required DateTime UpdateTime { get; set; }
public required bool IsLastVersion { get; set; }
public override string GetFullKey() => $"{DocumentType}-{DocumentNum}";
public override string GetFullKey() => $"{Id}-{Version}";
}
@@ -10,6 +10,8 @@ internal static class EntityMapping
{
return new()
{
Id = entity.Id,
Version = entity.Version,
DocumentType = entity.DocumentType,
DocumentNum = entity.DocumentNum,
IssueDate = entity.IssueDate.ToDateTime(TimeOnly.MinValue),