Refactors the book, artist, and album slices across the stack

This commit is contained in:
BinaryAlley committed 2026-09-17 13:30:48 -07:00
1 parent 8aaf9fe64e
commit ea6eb9f796
439 files changed
+28235 -3156

No files matched your search

@@ -0,0 +1,183 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
#endregion
namespace Lumina.DataAccess.Common.Configuration;
/// <summary>
/// Configures the entity mapping for the <see cref="AlbumEntity"/> entity.
/// </summary>
public class AlbumConfiguration : IEntityTypeConfiguration<AlbumEntity>
{
/// <summary>
/// Configures the <see cref="AlbumEntity"/> entity.
/// </summary>
/// <param name="builder">The builder to be used to configure the entity.</param>
public void Configure(EntityTypeBuilder<AlbumEntity> builder)
{
builder.ToTable("Albums");
builder.HasKey(album => album.Id);
builder.Property(album => album.Id)
.ValueGeneratedNever()
.HasColumnOrder(0);
builder.Property(album => album.ArtistId)
.IsRequired()
.HasColumnOrder(1);
builder.Property(album => album.LibraryId)
.IsRequired()
.HasColumnOrder(2);
builder.Property(album => album.Title)
.IsRequired()
.HasMaxLength(255)
.HasColumnOrder(3);
builder.Property(album => album.OriginalTitle)
.HasMaxLength(255)
.HasColumnOrder(4);
builder.Property(album => album.Description)
.HasMaxLength(2000)
.HasColumnOrder(5);
builder.Property(album => album.OriginalReleaseDate)
.HasColumnOrder(6);
builder.Property(album => album.OriginalReleaseYear)
.HasColumnOrder(7);
builder.Property(album => album.ReReleaseDate)
.HasColumnOrder(8);
builder.Property(album => album.ReReleaseYear)
.HasColumnOrder(9);
builder.Property(album => album.ReleaseCountry)
.HasConversion<string>()
.HasMaxLength(2)
.HasColumnOrder(10);
builder.Property(album => album.ReleaseVersion)
.HasColumnOrder(11);
builder.Property(album => album.LanguageCode)
.HasColumnOrder(12);
builder.Property(album => album.LanguageName)
.HasColumnOrder(13);
builder.Property(album => album.LanguageNativeName)
.HasColumnOrder(14);
builder.Property(album => album.OriginalLanguageCode)
.HasColumnOrder(15);
builder.Property(album => album.OriginalLanguageName)
.HasColumnOrder(16);
builder.Property(album => album.OriginalLanguageNativeName)
.HasColumnOrder(17);
builder.Property(album => album.ReleaseType)
.HasConversion<string>()
.HasMaxLength(50)
.HasColumnOrder(18);
builder.Property(album => album.ReleaseStatus)
.HasConversion<string>()
.HasMaxLength(50)
.HasColumnOrder(19);
builder.Property(album => album.TotalDiscs)
.HasColumnOrder(20);
builder.Property(album => album.TotalTracks)
.HasColumnOrder(21);
builder.Property(album => album.MediaFormat)
.HasConversion<string>()
.HasMaxLength(50)
.HasColumnOrder(22);
builder.Property(album => album.Barcode)
.HasMaxLength(13)
.HasColumnOrder(23);
builder.Property(album => album.CatalogNumber)
.HasMaxLength(50)
.HasColumnOrder(24);
builder.Property(album => album.MusicBrainzReleaseId)
.HasColumnOrder(25);
builder.Property(album => album.MusicBrainzReleaseGroupId)
.HasColumnOrder(26);
builder.Property(album => album.MusicBrainzReleaseArtistId)
.HasColumnOrder(27);
builder.Property(album => album.CreatedOnUtc)
.IsRequired()
.HasColumnOrder(28);
builder.Property(album => album.CreatedBy)
.IsRequired()
.HasColumnOrder(29);
builder.Property(album => album.UpdatedOnUtc)
.HasColumnOrder(30);
builder.Property(album => album.UpdatedBy)
.HasColumnOrder(31);
builder.HasOne(album => album.Artist)
.WithMany(artist => artist.Albums)
.HasForeignKey(album => album.ArtistId)
.OnDelete(DeleteBehavior.Cascade);
// since Tag and Genre are Domain ValueObjects (no identity), but we also don't want to have duplicates,
// we need to configure them as many-to-many relationships, where the tag/genre itself is the primary key
builder.HasMany(album => album.Tags)
.WithMany()
.UsingEntity<Dictionary<string, object>>(
"AlbumTags",
j => j.HasOne<TagEntity>()
.WithMany()
.HasForeignKey("TagId"),
j => j.HasOne<AlbumEntity>()
.WithMany()
.HasForeignKey("AlbumId"),
j =>
{
j.HasKey("AlbumId", "TagId");
j.ToTable("AlbumTags");
});
builder.HasMany(album => album.Genres)
.WithMany()
.UsingEntity<Dictionary<string, object>>(
"AlbumGenres",
j => j.HasOne<GenreEntity>()
.WithMany()
.HasForeignKey("GenreId"),
j => j.HasOne<AlbumEntity>()
.WithMany()
.HasForeignKey("AlbumId"),
j =>
{
j.HasKey("AlbumId", "GenreId");
j.ToTable("AlbumGenres");
});
builder.OwnsMany(album => album.Ratings, ratingBuilder =>
{
ratingBuilder.ToTable("AlbumRatings");
ratingBuilder.WithOwner()
.HasForeignKey("AlbumId");
ratingBuilder.Property<Guid>("Id")
.ValueGeneratedOnAdd();
ratingBuilder.HasKey("Id");
ratingBuilder.Property(rating => rating.Value)
.HasColumnType("decimal(3,2)")
.IsRequired();
ratingBuilder.Property(rating => rating.MaxValue)
.HasColumnType("decimal(3,2)")
.IsRequired();
ratingBuilder.Property(rating => rating.VoteCount)
.IsRequired(false);
ratingBuilder.Property(rating => rating.Source)
.HasConversion<string>()
.HasMaxLength(50)
.IsRequired(false);
});
builder.HasMany(album => album.Contributors)
.WithOne()
.HasForeignKey(contributor => contributor.AlbumId)
.OnDelete(DeleteBehavior.Cascade);
builder.HasIndex(album => new { album.ArtistId, album.Title });
builder.HasIndex(album => new { album.LibraryId, album.Title });
}
}
@@ -0,0 +1,57 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
#endregion
namespace Lumina.DataAccess.Common.Configuration;
/// <summary>
/// Configures the entity mapping for the <see cref="AlbumContributorEntity"/> entity.
/// </summary>
public class AlbumContributorConfiguration : IEntityTypeConfiguration<AlbumContributorEntity>
{
/// <summary>
/// Configures the <see cref="AlbumContributorEntity"/> entity.
/// </summary>
/// <param name="builder">The builder to be used to configure the entity.</param>
public void Configure(EntityTypeBuilder<AlbumContributorEntity> builder)
{
builder.ToTable("AlbumContributors");
builder.HasKey(albumContributor => albumContributor.Id);
builder.Property(albumContributor => albumContributor.Id)
.ValueGeneratedNever() // because EF always tries to generate the value for the Id, and because we generate it as part of the aggregate root, we need to tell EF not to generate it
.HasColumnOrder(0);
builder.Property(albumContributor => albumContributor.AlbumId)
.IsRequired()
.HasColumnOrder(1);
builder.Property(albumContributor => albumContributor.MediaContributorId)
.IsRequired()
.HasColumnOrder(2);
builder.Property(albumContributor => albumContributor.Role)
.HasConversion<string>()
.HasMaxLength(50)
.IsRequired()
.HasColumnOrder(3);
// audit
builder.Property(albumContributor => albumContributor.CreatedOnUtc)
.IsRequired()
.HasColumnOrder(4);
builder.Property(albumContributor => albumContributor.CreatedBy)
.IsRequired()
.HasColumnOrder(5);
builder.Property(albumContributor => albumContributor.UpdatedOnUtc)
.HasColumnOrder(6);
builder.Property(albumContributor => albumContributor.UpdatedBy)
.HasColumnOrder(7);
builder.HasIndex(albumContributor => new { albumContributor.AlbumId, albumContributor.MediaContributorId, albumContributor.Role })
.IsUnique();
builder.HasIndex(albumContributor => albumContributor.MediaContributorId);
}
}
@@ -0,0 +1,58 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
#endregion
namespace Lumina.DataAccess.Common.Configuration;
/// <summary>
/// Configures the entity mapping for the <see cref="ArtistEntity"/> entity.
/// </summary>
public class ArtistConfiguration : IEntityTypeConfiguration<ArtistEntity>
{
/// <summary>
/// Configures the <see cref="ArtistEntity"/> entity.
/// </summary>
/// <param name="builder">The builder to be used to configure the entity.</param>
public void Configure(EntityTypeBuilder<ArtistEntity> builder)
{
builder.ToTable("Artists");
builder.HasKey(artist => artist.Id);
builder.Property(artist => artist.Id)
.ValueGeneratedNever() // because EF always tries to generate the value for the Id, and because we generate it as part of the aggregate root, we need to tell EF not to generate it
.HasColumnOrder(0);
builder.Property(artist => artist.LibraryId)
.IsRequired()
.HasColumnOrder(1);
builder.Property(artist => artist.Name)
.IsRequired()
.HasMaxLength(255)
.HasColumnOrder(2);
builder.Property(artist => artist.Website)
.HasMaxLength(2048)
.HasColumnOrder(3);
builder.Property(artist => artist.MusicBrainzArtistId)
.HasColumnOrder(4);
builder.Property(artist => artist.CreatedOnUtc)
.IsRequired()
.HasColumnOrder(5);
builder.Property(artist => artist.CreatedBy)
.IsRequired()
.HasColumnOrder(6);
builder.Property(artist => artist.UpdatedOnUtc)
.HasColumnOrder(7);
builder.Property(artist => artist.UpdatedBy)
.HasColumnOrder(8);
builder.HasMany(artist => artist.Contributors)
.WithOne()
.HasForeignKey(contributor => contributor.ArtistId)
.OnDelete(DeleteBehavior.Cascade);
builder.HasIndex(artist => new { artist.LibraryId, artist.Name })
.IsUnique(); // the same artist cannot appear twice in the same library
}
}
@@ -0,0 +1,57 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
#endregion
namespace Lumina.DataAccess.Common.Configuration;
/// <summary>
/// Configures the entity mapping for the <see cref="ArtistContributorEntity"/> entity.
/// </summary>
public class ArtistContributorConfiguration : IEntityTypeConfiguration<ArtistContributorEntity>
{
/// <summary>
/// Configures the <see cref="ArtistContributorEntity"/> entity.
/// </summary>
/// <param name="builder">The builder to be used to configure the entity.</param>
public void Configure(EntityTypeBuilder<ArtistContributorEntity> builder)
{
builder.ToTable("ArtistContributors");
builder.HasKey(artistContributor => artistContributor.Id);
builder.Property(artistContributor => artistContributor.Id)
.ValueGeneratedNever() // because EF always tries to generate the value for the Id, and because we generate it as part of the aggregate root, we need to tell EF not to generate it
.HasColumnOrder(0);
builder.Property(artistContributor => artistContributor.ArtistId)
.IsRequired()
.HasColumnOrder(1);
builder.Property(artistContributor => artistContributor.MediaContributorId)
.IsRequired()
.HasColumnOrder(2);
builder.Property(artistContributor => artistContributor.Role)
.HasConversion<string>()
.HasMaxLength(50)
.IsRequired()
.HasColumnOrder(3);
// audit
builder.Property(artistContributor => artistContributor.CreatedOnUtc)
.IsRequired()
.HasColumnOrder(4);
builder.Property(artistContributor => artistContributor.CreatedBy)
.IsRequired()
.HasColumnOrder(5);
builder.Property(artistContributor => artistContributor.UpdatedOnUtc)
.HasColumnOrder(6);
builder.Property(artistContributor => artistContributor.UpdatedBy)
.HasColumnOrder(7);
builder.HasIndex(artistContributor => new { artistContributor.ArtistId, artistContributor.MediaContributorId, artistContributor.Role })
.IsUnique();
builder.HasIndex(artistContributor => artistContributor.MediaContributorId);
}
}
@@ -149,17 +149,13 @@ public class BookConfiguration : IEntityTypeConfiguration<BookEntity>
builder.Property(book => book.MetadataProvider)
.HasMaxLength(100)
.HasColumnOrder(40);
builder.Property(book => book.CreatedOnUtc)
.HasColumnOrder(30);
builder.Property(book => book.UpdatedOnUtc)
.HasColumnOrder(31);
builder.HasMany(book => book.BookContributors)
builder.HasMany(book => book.Contributors)
.WithOne()
.HasForeignKey(bookContributor => bookContributor.BookId)
.OnDelete(DeleteBehavior.Cascade);
builder.HasMany(book => book.BookArtwork)
builder.HasMany(book => book.Artwork)
.WithOne()
.HasForeignKey(bookArtwork => bookArtwork.BookId)
.OnDelete(DeleteBehavior.Cascade);
@@ -0,0 +1,224 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
#endregion
namespace Lumina.DataAccess.Common.Configuration;
/// <summary>
/// Configures the entity mapping for the <see cref="TrackEntity"/> entity.
/// </summary>
public class TrackConfiguration : IEntityTypeConfiguration<TrackEntity>
{
/// <summary>
/// Configures the <see cref="TrackEntity"/> entity.
/// </summary>
/// <param name="builder">The builder to be used to configure the entity.</param>
public void Configure(EntityTypeBuilder<TrackEntity> builder)
{
builder.ToTable("Tracks");
builder.HasKey(track => track.Id);
builder.Property(track => track.Id)
.ValueGeneratedNever()
.HasColumnOrder(0);
builder.Property(track => track.AlbumId)
.IsRequired()
.HasColumnOrder(1);
builder.Property(track => track.LibraryId)
.IsRequired()
.HasColumnOrder(2);
builder.Property(track => track.Path)
.IsRequired()
.HasMaxLength(2048)
.HasColumnOrder(3);
builder.Property(track => track.Title)
.IsRequired()
.HasMaxLength(255)
.HasColumnOrder(4);
builder.Property(track => track.OriginalTitle)
.HasMaxLength(255)
.HasColumnOrder(5);
builder.Property(track => track.Description)
.HasMaxLength(2000)
.HasColumnOrder(6);
builder.Property(track => track.OriginalReleaseDate)
.HasColumnOrder(7);
builder.Property(track => track.OriginalReleaseYear)
.HasColumnOrder(8);
builder.Property(track => track.ReReleaseDate)
.HasColumnOrder(9);
builder.Property(track => track.ReReleaseYear)
.HasColumnOrder(10);
builder.Property(track => track.ReleaseCountry)
.HasConversion<string>()
.HasMaxLength(2)
.HasColumnOrder(11);
builder.Property(track => track.ReleaseVersion)
.HasColumnOrder(12);
builder.Property(track => track.LanguageCode)
.HasColumnOrder(13);
builder.Property(track => track.LanguageName)
.HasColumnOrder(14);
builder.Property(track => track.LanguageNativeName)
.HasColumnOrder(15);
builder.Property(track => track.OriginalLanguageCode)
.HasColumnOrder(16);
builder.Property(track => track.OriginalLanguageName)
.HasColumnOrder(17);
builder.Property(track => track.OriginalLanguageNativeName)
.HasColumnOrder(18);
builder.Property(track => track.DurationInSeconds)
.HasColumnOrder(19);
builder.Property(track => track.SampleRate)
.HasColumnOrder(20);
builder.Property(track => track.Channels)
.HasColumnOrder(21);
builder.Property(track => track.BitDepth)
.HasColumnOrder(22);
builder.Property(track => track.AudioCodec)
.HasMaxLength(50)
.HasColumnOrder(23);
builder.Property(track => track.Bitrate)
.HasColumnOrder(24);
builder.Property(track => track.TrackNumber)
.HasColumnOrder(25);
builder.Property(track => track.DiscNumber)
.HasColumnOrder(26);
builder.Property(track => track.Script)
.HasMaxLength(50)
.HasColumnOrder(27);
builder.Property(track => track.Key)
.HasConversion<string>()
.HasMaxLength(50)
.HasColumnOrder(28);
builder.Property(track => track.Bpm)
.HasColumnOrder(29);
builder.Property(track => track.Work)
.HasMaxLength(255)
.HasColumnOrder(30);
builder.Property(track => track.MusicBrainzRecordingId)
.HasColumnOrder(31);
builder.Property(track => track.MusicBrainzTrackId)
.HasColumnOrder(32);
builder.Property(track => track.MusicBrainzWorkId)
.HasColumnOrder(33);
builder.Property(track => track.CreatedOnUtc)
.IsRequired()
.HasColumnOrder(34);
builder.Property(track => track.CreatedBy)
.IsRequired()
.HasColumnOrder(35);
builder.Property(track => track.UpdatedOnUtc)
.HasColumnOrder(36);
builder.Property(track => track.UpdatedBy)
.HasColumnOrder(37);
builder.HasOne(track => track.Album)
.WithMany(album => album.Tracks)
.HasForeignKey(track => track.AlbumId)
.OnDelete(DeleteBehavior.Cascade);
// since Tag and Genre are Domain ValueObjects (no identity), but we also don't want to have duplicates,
// we need to configure them as many-to-many relationships, where the tag/genre itself is the primary key
builder.HasMany(track => track.Tags)
.WithMany()
.UsingEntity<Dictionary<string, object>>(
"TrackTags",
j => j.HasOne<TagEntity>()
.WithMany()
.HasForeignKey("TagId"),
j => j.HasOne<TrackEntity>()
.WithMany()
.HasForeignKey("TrackId"),
j =>
{
j.HasKey("TrackId", "TagId");
j.ToTable("TrackTags");
});
builder.HasMany(track => track.Genres)
.WithMany()
.UsingEntity<Dictionary<string, object>>(
"TrackGenres",
j => j.HasOne<GenreEntity>()
.WithMany()
.HasForeignKey("GenreId"),
j => j.HasOne<TrackEntity>()
.WithMany()
.HasForeignKey("TrackId"),
j =>
{
j.HasKey("TrackId", "GenreId");
j.ToTable("TrackGenres");
});
builder.OwnsMany(track => track.Ratings, ratingBuilder =>
{
ratingBuilder.ToTable("TrackRatings");
ratingBuilder.WithOwner()
.HasForeignKey("TrackId");
ratingBuilder.Property<Guid>("Id")
.ValueGeneratedOnAdd();
ratingBuilder.HasKey("Id");
ratingBuilder.Property(rating => rating.Value)
.HasColumnType("decimal(3,2)")
.IsRequired();
ratingBuilder.Property(rating => rating.MaxValue)
.HasColumnType("decimal(3,2)")
.IsRequired();
ratingBuilder.Property(rating => rating.VoteCount)
.IsRequired(false);
ratingBuilder.Property(rating => rating.Source)
.HasConversion<string>()
.HasMaxLength(50)
.IsRequired(false);
});
builder.HasMany(track => track.Contributors)
.WithOne()
.HasForeignKey(contributor => contributor.TrackId)
.OnDelete(DeleteBehavior.Cascade);
builder.OwnsMany(track => track.Moods, moodBuilder =>
{
moodBuilder.ToTable("TrackMoods");
moodBuilder.WithOwner()
.HasForeignKey("TrackId");
moodBuilder.Property<Guid>("Id")
.ValueGeneratedOnAdd();
moodBuilder.HasKey("Id");
moodBuilder.Property(mood => mood.Name)
.IsRequired()
.HasMaxLength(50);
});
builder.OwnsMany(track => track.Isrcs, isrcBuilder =>
{
isrcBuilder.ToTable("TrackIsrcs");
isrcBuilder.WithOwner()
.HasForeignKey("TrackId");
isrcBuilder.Property<Guid>("Id")
.ValueGeneratedOnAdd();
isrcBuilder.HasKey("Id");
isrcBuilder.Property(isrc => isrc.Value)
.HasColumnName("ISRC")
.HasMaxLength(12)
.IsRequired();
});
builder.HasIndex(track => new { track.AlbumId, track.TrackNumber });
builder.HasIndex(track => new { track.LibraryId, track.Path })
.IsUnique(); // the same physical track file cannot appear twice in the same library
}
}
@@ -0,0 +1,57 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
#endregion
namespace Lumina.DataAccess.Common.Configuration;
/// <summary>
/// Configures the entity mapping for the <see cref="TrackContributorEntity"/> entity.
/// </summary>
public class TrackContributorConfiguration : IEntityTypeConfiguration<TrackContributorEntity>
{
/// <summary>
/// Configures the <see cref="TrackContributorEntity"/> entity.
/// </summary>
/// <param name="builder">The builder to be used to configure the entity.</param>
public void Configure(EntityTypeBuilder<TrackContributorEntity> builder)
{
builder.ToTable("TrackContributors");
builder.HasKey(trackContributor => trackContributor.Id);
builder.Property(trackContributor => trackContributor.Id)
.ValueGeneratedNever() // because EF always tries to generate the value for the Id, and because we generate it as part of the aggregate root, we need to tell EF not to generate it
.HasColumnOrder(0);
builder.Property(trackContributor => trackContributor.TrackId)
.IsRequired()
.HasColumnOrder(1);
builder.Property(trackContributor => trackContributor.MediaContributorId)
.IsRequired()
.HasColumnOrder(2);
builder.Property(trackContributor => trackContributor.Role)
.HasConversion<string>()
.HasMaxLength(50)
.IsRequired()
.HasColumnOrder(3);
// audit
builder.Property(trackContributor => trackContributor.CreatedOnUtc)
.IsRequired()
.HasColumnOrder(4);
builder.Property(trackContributor => trackContributor.CreatedBy)
.IsRequired()
.HasColumnOrder(5);
builder.Property(trackContributor => trackContributor.UpdatedOnUtc)
.HasColumnOrder(6);
builder.Property(trackContributor => trackContributor.UpdatedBy)
.HasColumnOrder(7);
builder.HasIndex(trackContributor => new { trackContributor.TrackId, trackContributor.MediaContributorId, trackContributor.Role })
.IsUnique();
builder.HasIndex(trackContributor => trackContributor.MediaContributorId);
}
}