using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace DataServer.Data; public sealed class Session { public ulong Id { get; set; } public ulong AccountId { get; set; } public string TokenHash { get; set; } = ""; // 64-char base64url/hex public DateTime ExpiresAt { get; set; } public DateTime CreatedAt { get; set; } public string? CreatedIp { get; set; } public string? UserAgent { get; set; } public Account? Account { get; set; } public DateTime? RevokedAt { get; set; } } public sealed class SessionConfig : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder e) { e.ToTable("sessions"); e.HasKey(x => x.Id); e.Property(x => x.Id).ValueGeneratedOnAdd(); e.Property(x => x.TokenHash).HasMaxLength(128).IsRequired(); e.Property(x => x.CreatedIp).HasMaxLength(64); e.Property(x => x.UserAgent).HasMaxLength(256); e.Property(x => x.CreatedAt).HasDefaultValueSql("CURRENT_TIMESTAMP(6)"); e.Property("RevokedAt"); e.HasIndex(x => x.AccountId); e.HasIndex(x => x.TokenHash).IsUnique(); e.HasOne(x => x.Account) .WithMany(a => a.Sessions) .HasForeignKey(x => x.AccountId) .OnDelete(DeleteBehavior.Cascade); } }