using Data.Data.Configurations; using DeepDrftModels.Entities; using DeepDrftModels.Enums; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace DeepDrftData.Data.Configurations; public class ReleaseConfiguration : BaseEntityConfiguration { public override void Configure(EntityTypeBuilder builder) { // Wires up Id PK + audit columns (CreatedAt, UpdatedAt, IsDeleted) and the IsDeleted index. base.Configure(builder); builder.ToTable("release"); // Map the base audit columns to the snake_case naming the rest of the schema uses. builder.Property(e => e.Id).HasColumnName("id"); builder.Property(e => e.CreatedAt).HasColumnName("created_at"); builder.Property(e => e.UpdatedAt).HasColumnName("updated_at"); builder.Property(e => e.IsDeleted).HasColumnName("is_deleted"); builder.Property(e => e.Title) .IsRequired() .HasMaxLength(200) .HasColumnName("title"); builder.Property(e => e.Artist) .IsRequired() .HasMaxLength(200) .HasColumnName("artist"); builder.Property(e => e.Genre) .HasMaxLength(100) .HasColumnName("genre"); builder.Property(e => e.ReleaseDate) .HasColumnName("release_date"); builder.Property(e => e.ImagePath) .HasMaxLength(500) .HasColumnName("image_path"); builder.Property(e => e.ReleaseType) .IsRequired() .HasConversion() // Store as readable string, not int ordinal .HasMaxLength(20) .HasColumnName("release_type") .HasDefaultValue(ReleaseType.Single); builder.Property(e => e.CreatedByUserId) .HasColumnName("created_by_user_id"); // Names the is_deleted index explicitly. BaseEntityConfiguration.Configure already // calls HasIndex(e => e.IsDeleted); this adds HasDatabaseName so EF always uses // "IX_release_is_deleted" regardless of auto-naming conventions. builder.HasIndex(e => e.IsDeleted).HasDatabaseName("IX_release_is_deleted"); // Unique constraint on the natural key (title + artist). Prevents duplicate release rows // from concurrent uploads of the same album. The FindOrCreateRelease path catches the // resulting ClassifiedDbException (UniqueViolation) and re-queries for the winning row. builder.HasIndex(e => new { e.Title, e.Artist }) .IsUnique() .HasDatabaseName("IX_release_title_artist"); } }