mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 11:11:10 +00:00
Refactors the book, artist, and album slices across the stack
This commit is contained in:
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);
|
||||
}
|
||||
}
|
||||
+2606
File diff suppressed because it is too large.
Load diff
+680
@@ -0,0 +1,680 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Lumina.DataAccess.Common.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddsMusicLibraryAndCanonicalContributorRoles : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_BookContributors_BookId_MediaContributorId",
|
||||
table: "BookContributors");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "RoleName",
|
||||
table: "BookContributors");
|
||||
|
||||
migrationBuilder.RenameColumn(
|
||||
name: "RoleCategory",
|
||||
table: "BookContributors",
|
||||
newName: "Role");
|
||||
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "UpdatedOnUtc",
|
||||
table: "BookContributors",
|
||||
type: "TEXT",
|
||||
nullable: true,
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "TEXT",
|
||||
oldNullable: true)
|
||||
.Annotation("Relational:ColumnOrder", 6)
|
||||
.OldAnnotation("Relational:ColumnOrder", 7);
|
||||
|
||||
migrationBuilder.AlterColumn<Guid>(
|
||||
name: "UpdatedBy",
|
||||
table: "BookContributors",
|
||||
type: "TEXT",
|
||||
nullable: true,
|
||||
oldClrType: typeof(Guid),
|
||||
oldType: "TEXT",
|
||||
oldNullable: true)
|
||||
.Annotation("Relational:ColumnOrder", 7)
|
||||
.OldAnnotation("Relational:ColumnOrder", 8);
|
||||
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "CreatedOnUtc",
|
||||
table: "BookContributors",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "TEXT")
|
||||
.Annotation("Relational:ColumnOrder", 4)
|
||||
.OldAnnotation("Relational:ColumnOrder", 5);
|
||||
|
||||
migrationBuilder.AlterColumn<Guid>(
|
||||
name: "CreatedBy",
|
||||
table: "BookContributors",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
oldClrType: typeof(Guid),
|
||||
oldType: "TEXT")
|
||||
.Annotation("Relational:ColumnOrder", 5)
|
||||
.OldAnnotation("Relational:ColumnOrder", 6);
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "Role",
|
||||
table: "BookContributors",
|
||||
type: "TEXT",
|
||||
maxLength: 50,
|
||||
nullable: false,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "TEXT",
|
||||
oldMaxLength: 50)
|
||||
.Annotation("Relational:ColumnOrder", 3)
|
||||
.OldAnnotation("Relational:ColumnOrder", 4);
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Artists",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
LibraryId = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
Name = table.Column<string>(type: "TEXT", maxLength: 255, nullable: false),
|
||||
Website = table.Column<string>(type: "TEXT", maxLength: 2048, nullable: true),
|
||||
MusicBrainzArtistId = table.Column<Guid>(type: "TEXT", nullable: true),
|
||||
CreatedOnUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
CreatedBy = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
UpdatedOnUtc = table.Column<DateTime>(type: "TEXT", nullable: true),
|
||||
UpdatedBy = table.Column<Guid>(type: "TEXT", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Artists", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Albums",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
ArtistId = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
LibraryId = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
Title = table.Column<string>(type: "TEXT", maxLength: 255, nullable: false),
|
||||
OriginalTitle = table.Column<string>(type: "TEXT", maxLength: 255, nullable: true),
|
||||
Description = table.Column<string>(type: "TEXT", maxLength: 2000, nullable: true),
|
||||
OriginalReleaseDate = table.Column<DateOnly>(type: "TEXT", nullable: true),
|
||||
OriginalReleaseYear = table.Column<int>(type: "INTEGER", nullable: true),
|
||||
ReReleaseDate = table.Column<DateOnly>(type: "TEXT", nullable: true),
|
||||
ReReleaseYear = table.Column<int>(type: "INTEGER", nullable: true),
|
||||
ReleaseCountry = table.Column<string>(type: "TEXT", maxLength: 2, nullable: true),
|
||||
ReleaseVersion = table.Column<string>(type: "TEXT", nullable: true),
|
||||
LanguageCode = table.Column<string>(type: "TEXT", nullable: true),
|
||||
LanguageName = table.Column<string>(type: "TEXT", nullable: true),
|
||||
LanguageNativeName = table.Column<string>(type: "TEXT", nullable: true),
|
||||
OriginalLanguageCode = table.Column<string>(type: "TEXT", nullable: true),
|
||||
OriginalLanguageName = table.Column<string>(type: "TEXT", nullable: true),
|
||||
OriginalLanguageNativeName = table.Column<string>(type: "TEXT", nullable: true),
|
||||
ReleaseType = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
|
||||
ReleaseStatus = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
|
||||
TotalDiscs = table.Column<int>(type: "INTEGER", nullable: true),
|
||||
TotalTracks = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
MediaFormat = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
|
||||
Barcode = table.Column<string>(type: "TEXT", maxLength: 13, nullable: true),
|
||||
CatalogNumber = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
|
||||
MusicBrainzReleaseId = table.Column<Guid>(type: "TEXT", nullable: true),
|
||||
MusicBrainzReleaseGroupId = table.Column<Guid>(type: "TEXT", nullable: true),
|
||||
MusicBrainzReleaseArtistId = table.Column<Guid>(type: "TEXT", nullable: true),
|
||||
CreatedOnUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
CreatedBy = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
UpdatedOnUtc = table.Column<DateTime>(type: "TEXT", nullable: true),
|
||||
UpdatedBy = table.Column<Guid>(type: "TEXT", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Albums", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Albums_Artists_ArtistId",
|
||||
column: x => x.ArtistId,
|
||||
principalTable: "Artists",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ArtistContributors",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
ArtistId = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
MediaContributorId = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
Role = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false),
|
||||
CreatedOnUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
CreatedBy = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
UpdatedOnUtc = table.Column<DateTime>(type: "TEXT", nullable: true),
|
||||
UpdatedBy = table.Column<Guid>(type: "TEXT", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ArtistContributors", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_ArtistContributors_Artists_ArtistId",
|
||||
column: x => x.ArtistId,
|
||||
principalTable: "Artists",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AlbumContributors",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
AlbumId = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
MediaContributorId = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
Role = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false),
|
||||
CreatedOnUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
CreatedBy = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
UpdatedOnUtc = table.Column<DateTime>(type: "TEXT", nullable: true),
|
||||
UpdatedBy = table.Column<Guid>(type: "TEXT", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AlbumContributors", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_AlbumContributors_Albums_AlbumId",
|
||||
column: x => x.AlbumId,
|
||||
principalTable: "Albums",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AlbumGenres",
|
||||
columns: table => new
|
||||
{
|
||||
AlbumId = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
GenreId = table.Column<string>(type: "TEXT", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AlbumGenres", x => new { x.AlbumId, x.GenreId });
|
||||
table.ForeignKey(
|
||||
name: "FK_AlbumGenres_Albums_AlbumId",
|
||||
column: x => x.AlbumId,
|
||||
principalTable: "Albums",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_AlbumGenres_Genres_GenreId",
|
||||
column: x => x.GenreId,
|
||||
principalTable: "Genres",
|
||||
principalColumn: "Name",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AlbumRatings",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
Source = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
|
||||
AlbumId = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
Value = table.Column<decimal>(type: "decimal(3,2)", nullable: false),
|
||||
MaxValue = table.Column<decimal>(type: "decimal(3,2)", nullable: false),
|
||||
VoteCount = table.Column<int>(type: "INTEGER", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AlbumRatings", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_AlbumRatings_Albums_AlbumId",
|
||||
column: x => x.AlbumId,
|
||||
principalTable: "Albums",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AlbumTags",
|
||||
columns: table => new
|
||||
{
|
||||
AlbumId = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
TagId = table.Column<string>(type: "TEXT", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AlbumTags", x => new { x.AlbumId, x.TagId });
|
||||
table.ForeignKey(
|
||||
name: "FK_AlbumTags_Albums_AlbumId",
|
||||
column: x => x.AlbumId,
|
||||
principalTable: "Albums",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_AlbumTags_Tags_TagId",
|
||||
column: x => x.TagId,
|
||||
principalTable: "Tags",
|
||||
principalColumn: "Name",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Tracks",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
AlbumId = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
LibraryId = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
Path = table.Column<string>(type: "TEXT", maxLength: 2048, nullable: false),
|
||||
Title = table.Column<string>(type: "TEXT", maxLength: 255, nullable: false),
|
||||
OriginalTitle = table.Column<string>(type: "TEXT", maxLength: 255, nullable: true),
|
||||
Description = table.Column<string>(type: "TEXT", maxLength: 2000, nullable: true),
|
||||
OriginalReleaseDate = table.Column<DateOnly>(type: "TEXT", nullable: true),
|
||||
OriginalReleaseYear = table.Column<int>(type: "INTEGER", nullable: true),
|
||||
ReReleaseDate = table.Column<DateOnly>(type: "TEXT", nullable: true),
|
||||
ReReleaseYear = table.Column<int>(type: "INTEGER", nullable: true),
|
||||
ReleaseCountry = table.Column<string>(type: "TEXT", maxLength: 2, nullable: true),
|
||||
ReleaseVersion = table.Column<string>(type: "TEXT", nullable: true),
|
||||
LanguageCode = table.Column<string>(type: "TEXT", nullable: true),
|
||||
LanguageName = table.Column<string>(type: "TEXT", nullable: true),
|
||||
LanguageNativeName = table.Column<string>(type: "TEXT", nullable: true),
|
||||
OriginalLanguageCode = table.Column<string>(type: "TEXT", nullable: true),
|
||||
OriginalLanguageName = table.Column<string>(type: "TEXT", nullable: true),
|
||||
OriginalLanguageNativeName = table.Column<string>(type: "TEXT", nullable: true),
|
||||
DurationInSeconds = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
SampleRate = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
Channels = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
BitDepth = table.Column<int>(type: "INTEGER", nullable: true),
|
||||
AudioCodec = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
|
||||
Bitrate = table.Column<int>(type: "INTEGER", nullable: true),
|
||||
TrackNumber = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
DiscNumber = table.Column<int>(type: "INTEGER", nullable: true),
|
||||
Script = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
|
||||
Key = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
|
||||
Bpm = table.Column<int>(type: "INTEGER", nullable: true),
|
||||
Work = table.Column<string>(type: "TEXT", maxLength: 255, nullable: true),
|
||||
MusicBrainzRecordingId = table.Column<Guid>(type: "TEXT", nullable: true),
|
||||
MusicBrainzTrackId = table.Column<Guid>(type: "TEXT", nullable: true),
|
||||
MusicBrainzWorkId = table.Column<Guid>(type: "TEXT", nullable: true),
|
||||
CreatedOnUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
CreatedBy = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
UpdatedOnUtc = table.Column<DateTime>(type: "TEXT", nullable: true),
|
||||
UpdatedBy = table.Column<Guid>(type: "TEXT", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Tracks", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Tracks_Albums_AlbumId",
|
||||
column: x => x.AlbumId,
|
||||
principalTable: "Albums",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "TrackContributors",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
TrackId = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
MediaContributorId = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
Role = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false),
|
||||
CreatedOnUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
CreatedBy = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
UpdatedOnUtc = table.Column<DateTime>(type: "TEXT", nullable: true),
|
||||
UpdatedBy = table.Column<Guid>(type: "TEXT", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_TrackContributors", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_TrackContributors_Tracks_TrackId",
|
||||
column: x => x.TrackId,
|
||||
principalTable: "Tracks",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "TrackGenres",
|
||||
columns: table => new
|
||||
{
|
||||
TrackId = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
GenreId = table.Column<string>(type: "TEXT", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_TrackGenres", x => new { x.TrackId, x.GenreId });
|
||||
table.ForeignKey(
|
||||
name: "FK_TrackGenres_Genres_GenreId",
|
||||
column: x => x.GenreId,
|
||||
principalTable: "Genres",
|
||||
principalColumn: "Name",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_TrackGenres_Tracks_TrackId",
|
||||
column: x => x.TrackId,
|
||||
principalTable: "Tracks",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "TrackIsrcs",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
ISRC = table.Column<string>(type: "TEXT", maxLength: 12, nullable: false),
|
||||
TrackId = table.Column<Guid>(type: "TEXT", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_TrackIsrcs", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_TrackIsrcs_Tracks_TrackId",
|
||||
column: x => x.TrackId,
|
||||
principalTable: "Tracks",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "TrackMoods",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
Name = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false),
|
||||
TrackId = table.Column<Guid>(type: "TEXT", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_TrackMoods", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_TrackMoods_Tracks_TrackId",
|
||||
column: x => x.TrackId,
|
||||
principalTable: "Tracks",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "TrackRatings",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
Source = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
|
||||
TrackId = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
Value = table.Column<decimal>(type: "decimal(3,2)", nullable: false),
|
||||
MaxValue = table.Column<decimal>(type: "decimal(3,2)", nullable: false),
|
||||
VoteCount = table.Column<int>(type: "INTEGER", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_TrackRatings", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_TrackRatings_Tracks_TrackId",
|
||||
column: x => x.TrackId,
|
||||
principalTable: "Tracks",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "TrackTags",
|
||||
columns: table => new
|
||||
{
|
||||
TrackId = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
TagId = table.Column<string>(type: "TEXT", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_TrackTags", x => new { x.TrackId, x.TagId });
|
||||
table.ForeignKey(
|
||||
name: "FK_TrackTags_Tags_TagId",
|
||||
column: x => x.TagId,
|
||||
principalTable: "Tags",
|
||||
principalColumn: "Name",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_TrackTags_Tracks_TrackId",
|
||||
column: x => x.TrackId,
|
||||
principalTable: "Tracks",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_BookContributors_BookId_MediaContributorId_Role",
|
||||
table: "BookContributors",
|
||||
columns: new[] { "BookId", "MediaContributorId", "Role" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AlbumContributors_AlbumId_MediaContributorId_Role",
|
||||
table: "AlbumContributors",
|
||||
columns: new[] { "AlbumId", "MediaContributorId", "Role" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AlbumContributors_MediaContributorId",
|
||||
table: "AlbumContributors",
|
||||
column: "MediaContributorId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AlbumGenres_GenreId",
|
||||
table: "AlbumGenres",
|
||||
column: "GenreId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AlbumRatings_AlbumId",
|
||||
table: "AlbumRatings",
|
||||
column: "AlbumId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Albums_ArtistId_Title",
|
||||
table: "Albums",
|
||||
columns: new[] { "ArtistId", "Title" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Albums_LibraryId_Title",
|
||||
table: "Albums",
|
||||
columns: new[] { "LibraryId", "Title" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AlbumTags_TagId",
|
||||
table: "AlbumTags",
|
||||
column: "TagId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ArtistContributors_ArtistId_MediaContributorId_Role",
|
||||
table: "ArtistContributors",
|
||||
columns: new[] { "ArtistId", "MediaContributorId", "Role" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ArtistContributors_MediaContributorId",
|
||||
table: "ArtistContributors",
|
||||
column: "MediaContributorId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Artists_LibraryId_Name",
|
||||
table: "Artists",
|
||||
columns: new[] { "LibraryId", "Name" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_TrackContributors_MediaContributorId",
|
||||
table: "TrackContributors",
|
||||
column: "MediaContributorId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_TrackContributors_TrackId_MediaContributorId_Role",
|
||||
table: "TrackContributors",
|
||||
columns: new[] { "TrackId", "MediaContributorId", "Role" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_TrackGenres_GenreId",
|
||||
table: "TrackGenres",
|
||||
column: "GenreId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_TrackIsrcs_TrackId",
|
||||
table: "TrackIsrcs",
|
||||
column: "TrackId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_TrackMoods_TrackId",
|
||||
table: "TrackMoods",
|
||||
column: "TrackId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_TrackRatings_TrackId",
|
||||
table: "TrackRatings",
|
||||
column: "TrackId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Tracks_AlbumId_TrackNumber",
|
||||
table: "Tracks",
|
||||
columns: new[] { "AlbumId", "TrackNumber" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Tracks_LibraryId_Path",
|
||||
table: "Tracks",
|
||||
columns: new[] { "LibraryId", "Path" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_TrackTags_TagId",
|
||||
table: "TrackTags",
|
||||
column: "TagId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "AlbumContributors");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "AlbumGenres");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "AlbumRatings");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "AlbumTags");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ArtistContributors");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "TrackContributors");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "TrackGenres");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "TrackIsrcs");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "TrackMoods");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "TrackRatings");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "TrackTags");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Tracks");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Albums");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Artists");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_BookContributors_BookId_MediaContributorId_Role",
|
||||
table: "BookContributors");
|
||||
|
||||
migrationBuilder.RenameColumn(
|
||||
name: "Role",
|
||||
table: "BookContributors",
|
||||
newName: "RoleCategory");
|
||||
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "UpdatedOnUtc",
|
||||
table: "BookContributors",
|
||||
type: "TEXT",
|
||||
nullable: true,
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "TEXT",
|
||||
oldNullable: true)
|
||||
.Annotation("Relational:ColumnOrder", 7)
|
||||
.OldAnnotation("Relational:ColumnOrder", 6);
|
||||
|
||||
migrationBuilder.AlterColumn<Guid>(
|
||||
name: "UpdatedBy",
|
||||
table: "BookContributors",
|
||||
type: "TEXT",
|
||||
nullable: true,
|
||||
oldClrType: typeof(Guid),
|
||||
oldType: "TEXT",
|
||||
oldNullable: true)
|
||||
.Annotation("Relational:ColumnOrder", 8)
|
||||
.OldAnnotation("Relational:ColumnOrder", 7);
|
||||
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "CreatedOnUtc",
|
||||
table: "BookContributors",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "TEXT")
|
||||
.Annotation("Relational:ColumnOrder", 5)
|
||||
.OldAnnotation("Relational:ColumnOrder", 4);
|
||||
|
||||
migrationBuilder.AlterColumn<Guid>(
|
||||
name: "CreatedBy",
|
||||
table: "BookContributors",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
oldClrType: typeof(Guid),
|
||||
oldType: "TEXT")
|
||||
.Annotation("Relational:ColumnOrder", 6)
|
||||
.OldAnnotation("Relational:ColumnOrder", 5);
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "RoleCategory",
|
||||
table: "BookContributors",
|
||||
type: "TEXT",
|
||||
maxLength: 50,
|
||||
nullable: false,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "TEXT",
|
||||
oldMaxLength: 50)
|
||||
.Annotation("Relational:ColumnOrder", 4)
|
||||
.OldAnnotation("Relational:ColumnOrder", 3);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "RoleName",
|
||||
table: "BookContributors",
|
||||
type: "TEXT",
|
||||
maxLength: 100,
|
||||
nullable: false,
|
||||
defaultValue: "")
|
||||
.Annotation("Relational:ColumnOrder", 3);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_BookContributors_BookId_MediaContributorId",
|
||||
table: "BookContributors",
|
||||
columns: new[] { "BookId", "MediaContributorId" });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user