using DeepDrftModels.Entities; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace DeepDrftData.Data.Configurations; /// /// EF configuration for the play_counter rollup (Phase 16 §4.1 / D6). One row per track, unique /// on track_id so the incremental-on-write bump is an upsert against a single row. TotalPlays is /// a computed C# property (sum of the three bucket columns) and is not mapped — it is derived on read. /// public class PlayCounterConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.ToTable("play_counter"); builder.HasKey(e => e.Id); builder.Property(e => e.Id).HasColumnName("id"); builder.Property(e => e.TrackId) .IsRequired() .HasColumnName("track_id"); builder.Property(e => e.PartialCount) .IsRequired() .HasDefaultValue(0L) .HasColumnName("partial_count"); builder.Property(e => e.SampledCount) .IsRequired() .HasDefaultValue(0L) .HasColumnName("sampled_count"); builder.Property(e => e.CompleteCount) .IsRequired() .HasDefaultValue(0L) .HasColumnName("complete_count"); // Derived headline figure — never a column. builder.Ignore(e => e.TotalPlays); builder.HasIndex(e => e.TrackId) .IsUnique() .HasDatabaseName("IX_play_counter_track_id"); } }