using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace DodoSSH.Infrastructure;
///
/// Maps PostgreSQL's xmin system column as an optimistic concurrency token.
///
///
///
/// Npgsql's UseXminAsConcurrencyToken helper no longer exists in EF 10, so the shadow
/// property is configured directly here rather than repeated in every entity configuration.
///
///
/// xmin is a system column that PostgreSQL maintains, so it must never appear in a
/// CREATE TABLE. That is what
/// combined with ValueGeneratedOnAddOrUpdate achieves; an
/// Infrastructure test asserts the generated DDL does not declare it.
///
///
/// This token is strictly internal. It is never exposed to clients: xmin is not stable
/// across VACUUM FREEZE, so using it as a sync cursor would silently break. Client-visible
/// versioning is the separate monotonic Version column on item rows.
///
///
public static class XminConcurrency
{
/// Name of the shadow property and of the PostgreSQL system column.
public const string PropertyName = "xmin";
/// Configures xmin as this entity's concurrency token.
public static EntityTypeBuilder UseXminConcurrencyToken(
this EntityTypeBuilder builder)
where TEntity : class
{
ArgumentNullException.ThrowIfNull(builder);
builder.Property(PropertyName)
.HasColumnName(PropertyName)
.HasColumnType("xid")
.ValueGeneratedOnAddOrUpdate()
.IsConcurrencyToken();
return builder;
}
}