From 00376c8313158ed515c942f553aceba1a4266a2b Mon Sep 17 00:00:00 2001 From: Binary Alley Date: Thu, 8 Oct 2026 20:48:00 +0300 Subject: [PATCH] Adds the music library persistence model, its repositories, and the scanning migration --- .../MusicLibrary/AlbumCatalogNumberEntity.cs | 14 + .../AudioLibrary/MusicLibrary/AlbumEntity.cs | 54 +- .../MusicLibrary/AlbumReleaseTypeEntity.cs | 15 + .../MusicLibrary/ArtistAliasEntity.cs | 29 + .../AudioLibrary/MusicLibrary/ArtistEntity.cs | 101 + .../MusicLibrary/ArtistIpiEntity.cs | 14 + .../MusicLibrary/ArtistIsniEntity.cs | 14 + .../MusicLibrary/MusicAreaEntity.cs | 25 + .../MusicLibraryScanItemMetadataEntity.cs | 171 + .../AudioLibrary/MusicLibrary/TrackEntity.cs | 68 +- .../MusicLibrary/TrackWorkIswcEntity.cs | 14 + .../MusicLibrary/TrackWorkLanguageEntity.cs | 18 + .../BookLibrary/BookEntity.cs | 1 + .../UsersManagement/UserSettingsEntity.cs | 5 + .../BookLibrary/IBookRepository.cs | 9 + .../ILibraryScanStagingResultsRepository.cs | 9 + .../MusicLibrary/IAlbumRepository.cs | 66 +- .../MusicLibrary/IArtistRepository.cs | 59 + ...IMusicLibraryScanItemMetadataRepository.cs | 35 + .../MusicLibrary/ITrackRepository.cs | 39 +- .../Common/DataAccess/UoW/IUnitOfWork.cs | 10 + .../Configuration/AlbumConfiguration.cs | 113 +- .../Configuration/ArtistConfiguration.cs | 162 +- ...sicLibraryScanItemMetadataConfiguration.cs | 105 + .../Configuration/TrackConfiguration.cs | 132 +- .../UserSettingsConfiguration.cs | 4 + ...usicLibraryScanningAndMetadata.Designer.cs | 3381 +++++++++++++++++ ...629_AddsMusicLibraryScanningAndMetadata.cs | 2199 +++++++++++ .../BookLibrary/BookRepository.cs | 21 + .../LibraryScanStagingResultsRepository.cs | 23 + .../MediaContributorRepository.cs | 27 +- .../MusicLibrary/AlbumRepository.cs | 169 + .../MusicLibrary/ArtistRepository.cs | 214 +- .../MusicLibraryScanItemMetadataRepository.cs | 74 + .../MusicLibrary/TrackRepository.cs | 121 + .../Core/UoW/LuminaDbContext.cs | 2 + src/Lumina.DataAccess/Core/UoW/UnitOfWork.cs | 26 + .../Common/Errors/Errors.MediaContributor.cs | 1 + .../AlbumCatalogNumberEntityFixture.cs | 39 + .../MusicLibrary/AlbumEntityFixture.cs | 19 +- .../AlbumReleaseTypeEntityFixture.cs | 40 + .../MusicLibrary/ArtistAliasEntityFixture.cs | 78 + .../MusicLibrary/ArtistIpiEntityFixture.cs | 39 + .../MusicLibrary/ArtistIsniEntityFixture.cs | 39 + .../MusicLibrary/MusicAreaEntityFixture.cs | 64 + ...sicLibraryScanItemMetadataEntityFixture.cs | 102 + .../MusicLibrary/TrackEntityFixture.cs | 10 +- .../TrackWorkIswcEntityFixture.cs | 39 + .../TrackWorkLanguageEntityFixture.cs | 48 + .../BookLibrary/BookEntityFixture.cs | 110 +- .../BookLibrary/IsbnEntityFixture.cs | 45 +- .../MediaContributorRepositoryTests.cs | 49 + .../Core/UoW/LuminaDbContextTests.cs | 22 +- .../Configuration/AlbumConfigurationTests.cs | 6 +- .../Configuration/BookConfigurationTests.cs | 1 + ...braryScanItemMetadataConfigurationTests.cs | 163 + .../Configuration/TrackConfigurationTests.cs | 6 +- .../BookLibrary/BookRepositoryTests.cs | 68 + .../MediaContributorRepositoryTests.cs | 54 + .../MusicLibrary/AlbumRepositoryTests.cs | 47 + .../MusicLibrary/ArtistRepositoryTests.cs | 99 + ...cLibraryScanItemMetadataRepositoryTests.cs | 130 + .../MusicLibrary/TrackRepositoryTests.cs | 21 + 63 files changed, 8679 insertions(+), 203 deletions(-) create mode 100644 src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/AlbumCatalogNumberEntity.cs create mode 100644 src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/AlbumReleaseTypeEntity.cs create mode 100644 src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/ArtistAliasEntity.cs create mode 100644 src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/ArtistIpiEntity.cs create mode 100644 src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/ArtistIsniEntity.cs create mode 100644 src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/MusicAreaEntity.cs create mode 100644 src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/MusicLibraryScanItemMetadataEntity.cs create mode 100644 src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/TrackWorkIswcEntity.cs create mode 100644 src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/TrackWorkLanguageEntity.cs create mode 100644 src/Lumina.Application/Common/DataAccess/Repositories/MusicLibrary/IMusicLibraryScanItemMetadataRepository.cs create mode 100644 src/Lumina.DataAccess/Common/Configuration/MusicLibraryScanItemMetadataConfiguration.cs create mode 100644 src/Lumina.DataAccess/Common/Migrations/20261004113629_AddsMusicLibraryScanningAndMetadata.Designer.cs create mode 100644 src/Lumina.DataAccess/Common/Migrations/20261004113629_AddsMusicLibraryScanningAndMetadata.cs create mode 100644 src/Lumina.DataAccess/Core/Repositories/MusicLibrary/MusicLibraryScanItemMetadataRepository.cs create mode 100644 tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/AlbumCatalogNumberEntityFixture.cs create mode 100644 tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/AlbumReleaseTypeEntityFixture.cs create mode 100644 tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/ArtistAliasEntityFixture.cs create mode 100644 tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/ArtistIpiEntityFixture.cs create mode 100644 tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/ArtistIsniEntityFixture.cs create mode 100644 tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/MusicAreaEntityFixture.cs create mode 100644 tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/MusicLibraryScanItemMetadataEntityFixture.cs create mode 100644 tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/TrackWorkIswcEntityFixture.cs create mode 100644 tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/TrackWorkLanguageEntityFixture.cs create mode 100644 tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/Repositories/MediaContributors/MediaContributorRepositoryTests.cs create mode 100644 tests/UnitTests/Lumina.DataAccess.UnitTests/Common/Configuration/MusicLibraryScanItemMetadataConfigurationTests.cs create mode 100644 tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MusicLibrary/MusicLibraryScanItemMetadataRepositoryTests.cs diff --git a/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/AlbumCatalogNumberEntity.cs b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/AlbumCatalogNumberEntity.cs new file mode 100644 index 00000000..76234755 --- /dev/null +++ b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/AlbumCatalogNumberEntity.cs @@ -0,0 +1,14 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; + +/// +/// Repository entity for a catalog number of a music release. A release can carry more than one catalog number at the same time. +/// +/// The catalog number assigned by the label. +[DebuggerDisplay("CatalogNumber: {CatalogNumber}")] +public record AlbumCatalogNumberEntity( + string CatalogNumber +); diff --git a/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/AlbumEntity.cs b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/AlbumEntity.cs index 2a5c2330..c42bbf90 100644 --- a/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/AlbumEntity.cs +++ b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/AlbumEntity.cs @@ -2,6 +2,7 @@ using Lumina.Application.Common.DataAccess.Entities.Common; using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary; using Lumina.Domain.SharedKernel.Common.Enums.Common; +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; using System; using System.Collections.Generic; using System.Diagnostics; @@ -40,11 +41,21 @@ public class AlbumEntity : IStorageEntity, IAuditableEntity /// public string? OriginalTitle { get; set; } + /// + /// Gets or sets the title of the specific release (edition) the album files match, if different from the release group title. + /// + public string? ReleaseTitle { get; set; } + /// /// Gets or sets the description of the album, if applicable. /// public string? Description { get; set; } + /// + /// Gets or sets the disambiguation comment of the album, used to distinguish albums with the same title, if applicable. + /// + public string? Disambiguation { get; set; } + /// /// Gets or sets the original release date of the album, if applicable. /// @@ -106,9 +117,9 @@ public class AlbumEntity : IStorageEntity, IAuditableEntity public string? OriginalLanguageNativeName { get; set; } /// - /// Gets or sets the type of the release, if applicable. + /// Gets or sets the script used by the language of the release of the album, if applicable. /// - public MusicReleaseType? ReleaseType { get; set; } + public string? Script { get; set; } /// /// Gets or sets the status of the release, if applicable. @@ -130,15 +141,30 @@ public class AlbumEntity : IStorageEntity, IAuditableEntity /// public MusicMediaFormat? MediaFormat { get; set; } + /// + /// Gets or sets the outermost physical packaging of the album, if applicable. + /// + public MusicReleasePackaging? Packaging { get; set; } + /// /// Gets or sets the barcode of the album, if applicable. /// public string? Barcode { get; set; } /// - /// Gets or sets the catalog number of the album, if applicable. + /// Gets or sets the catalog numbers of the album. /// - public string? CatalogNumber { get; set; } + public List CatalogNumbers { get; set; } = []; + + /// + /// Gets or sets the name of the label that issued the album, if applicable. + /// + public string? Label { get; set; } + + /// + /// Gets or sets the ASIN (Amazon Standard Identification Number) of the album, if applicable. + /// + public string? ASIN { get; set; } /// /// Gets or sets the MusicBrainz identifier of the release, if applicable. @@ -175,6 +201,11 @@ public class AlbumEntity : IStorageEntity, IAuditableEntity /// public List Contributors { get; set; } = []; + /// + /// Gets or sets the types of the release. A release can carry more than one type at the same time. + /// + public List ReleaseTypes { get; set; } = []; + /// /// Gets or sets the genres of the album. /// @@ -185,6 +216,21 @@ public class AlbumEntity : IStorageEntity, IAuditableEntity /// public HashSet Tags { get; set; } = []; + /// + /// Gets or sets the status of the metadata enrichment of the album. + /// + public MetadataStatus MetadataStatus { get; set; } + + /// + /// Gets or sets the date and time when the metadata of the album was last enriched. + /// + public DateTime? LastMetadataUpdateUtc { get; set; } + + /// + /// Gets or sets the name of the plugin that enriched the metadata of the album. + /// + public string? MetadataProvider { get; set; } + /// /// Gets or sets the time and date when the entity was added. /// diff --git a/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/AlbumReleaseTypeEntity.cs b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/AlbumReleaseTypeEntity.cs new file mode 100644 index 00000000..c39cc489 --- /dev/null +++ b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/AlbumReleaseTypeEntity.cs @@ -0,0 +1,15 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary; +using System.Diagnostics; +#endregion + +namespace Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; + +/// +/// Repository entity for a type of a music release. A release can carry more than one type at the same time. +/// +/// The type of the release. +[DebuggerDisplay("ReleaseType: {ReleaseType}")] +public record AlbumReleaseTypeEntity( + MusicReleaseType ReleaseType +); diff --git a/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/ArtistAliasEntity.cs b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/ArtistAliasEntity.cs new file mode 100644 index 00000000..c802fd6f --- /dev/null +++ b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/ArtistAliasEntity.cs @@ -0,0 +1,29 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; + +/// +/// Repository entity for an alternative name of a music artist. +/// +/// The name of the alias. +/// The sort name of the alias, if applicable. +/// The type of the alias, if applicable. +/// The locale the alias is used in, if applicable. +/// Whether this is the primary alias of the artist. +/// The date the alias began being used, if applicable. +/// The date the alias stopped being used, if applicable. +/// Whether the alias is no longer used. +[DebuggerDisplay("Name: {Name}")] +public record ArtistAliasEntity( + string Name, + string? SortName, + string? Type, + string? Locale, + bool IsPrimary, + DateOnly? BeginDate, + DateOnly? EndDate, + bool IsEnded +); diff --git a/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/ArtistEntity.cs b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/ArtistEntity.cs index 5a01a28b..380683c4 100644 --- a/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/ArtistEntity.cs +++ b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/ArtistEntity.cs @@ -1,6 +1,7 @@ #region ========================================================================= USING ===================================================================================== using Lumina.Application.Common.DataAccess.Entities.Common; using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary; +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; using System; using System.Collections.Generic; using System.Diagnostics; @@ -29,6 +30,46 @@ public class ArtistEntity : IStorageEntity, IAuditableEntity /// public required string Name { get; set; } + /// + /// Gets or sets the sort name of the artist, a variant of the name used when sorting artists, if applicable. + /// + public string? SortName { get; set; } + + /// + /// Gets or sets the disambiguation comment of the artist, used to distinguish artists with the same name, if applicable. + /// + public string? Disambiguation { get; set; } + + /// + /// Gets or sets the type of the artist, if applicable. + /// + public MusicArtistType? Type { get; set; } + + /// + /// Gets or sets the gender of the artist, applicable only to artists that are persons or characters, if applicable. + /// + public MusicArtistGender? Gender { get; set; } + + /// + /// Gets or sets the ISO 3166-1 alpha-2 code of the country the artist is associated with, if applicable. + /// + public string? Country { get; set; } + + /// + /// Gets or sets the date the artist started existing, if applicable. + /// + public DateOnly? LifeSpanBegin { get; set; } + + /// + /// Gets or sets the date the artist stopped existing, if applicable. + /// + public DateOnly? LifeSpanEnd { get; set; } + + /// + /// Gets or sets a value indicating whether the artist no longer exists. + /// + public bool IsEnded { get; set; } + /// /// Gets or sets the website of the artist, if applicable. /// @@ -39,6 +80,51 @@ public class ArtistEntity : IStorageEntity, IAuditableEntity /// public Guid? MusicBrainzArtistId { get; set; } + /// + /// Gets or sets the area the artist is primarily identified with, if applicable. + /// + public MusicAreaEntity? Area { get; set; } + + /// + /// Gets or sets the area the artist began in, if applicable. + /// + public MusicAreaEntity? BeginArea { get; set; } + + /// + /// Gets or sets the area the artist ended in, if applicable. + /// + public MusicAreaEntity? EndArea { get; set; } + + /// + /// Gets or sets the list of alternative names of the artist. + /// + public List Aliases { get; set; } = []; + + /// + /// Gets or sets the list of IPI (Interested Party Information) codes of the artist. + /// + public List Ipis { get; set; } = []; + + /// + /// Gets or sets the list of ISNI (International Standard Name Identifier) codes of the artist. + /// + public List Isnis { get; set; } = []; + + /// + /// Gets or sets the genres of the artist. + /// + public HashSet Genres { get; set; } = []; + + /// + /// Gets or sets the tags of the artist. + /// + public HashSet Tags { get; set; } = []; + + /// + /// Gets or sets the list of ratings of the artist. + /// + public List Ratings { get; set; } = []; + /// /// Gets or sets the albums of the artist. /// @@ -49,6 +135,21 @@ public class ArtistEntity : IStorageEntity, IAuditableEntity /// public List Contributors { get; set; } = []; + /// + /// Gets or sets the status of the metadata enrichment of the artist. + /// + public MetadataStatus MetadataStatus { get; set; } + + /// + /// Gets or sets the date and time when the metadata of the artist was last enriched. + /// + public DateTime? LastMetadataUpdateUtc { get; set; } + + /// + /// Gets or sets the name of the plugin that enriched the metadata of the artist. + /// + public string? MetadataProvider { get; set; } + /// /// Gets or sets the time and date when the entity was added. /// diff --git a/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/ArtistIpiEntity.cs b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/ArtistIpiEntity.cs new file mode 100644 index 00000000..1b8644d6 --- /dev/null +++ b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/ArtistIpiEntity.cs @@ -0,0 +1,14 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; + +/// +/// Repository entity for an IPI (Interested Party Information) code of a music artist. +/// +/// The value of the IPI code. +[DebuggerDisplay("Value: {Value}")] +public record ArtistIpiEntity( + string Value +); diff --git a/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/ArtistIsniEntity.cs b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/ArtistIsniEntity.cs new file mode 100644 index 00000000..ff3d5d63 --- /dev/null +++ b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/ArtistIsniEntity.cs @@ -0,0 +1,14 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; + +/// +/// Repository entity for an ISNI (International Standard Name Identifier) code of a music artist. +/// +/// The value of the ISNI code. +[DebuggerDisplay("Value: {Value}")] +public record ArtistIsniEntity( + string Value +); diff --git a/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/MusicAreaEntity.cs b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/MusicAreaEntity.cs new file mode 100644 index 00000000..4902bf67 --- /dev/null +++ b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/MusicAreaEntity.cs @@ -0,0 +1,25 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; + +/// +/// Repository entity for a MusicBrainz area, the geographic area a music artist is associated with. +/// +/// The MusicBrainz identifier of the area. +/// The name of the area. +/// The sort name of the area, if applicable. +/// The disambiguation comment of the area, if applicable. +/// The MusicBrainz type of the area, if applicable. +/// The ISO 3166 code of the area, if applicable. +[DebuggerDisplay("Name: {Name}")] +public record MusicAreaEntity( + Guid MusicBrainzAreaId, + string Name, + string? SortName, + string? Disambiguation, + string? Type, + string? Iso3166Code +); diff --git a/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/MusicLibraryScanItemMetadataEntity.cs b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/MusicLibraryScanItemMetadataEntity.cs new file mode 100644 index 00000000..8b943070 --- /dev/null +++ b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/MusicLibraryScanItemMetadataEntity.cs @@ -0,0 +1,171 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Application.Common.DataAccess.Entities.Common; +using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary; +using System; +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; + +/// +/// Repository entity for the metadata extracted from a discovered music file, staged during a scan, before the artists, albums and tracks are materialized from it. +/// +[DebuggerDisplay("Path: {Path}")] +public class MusicLibraryScanItemMetadataEntity : IStorageEntity +{ + /// + /// Gets the Id of the staged music metadata. + /// + public required Guid Id { get; init; } + + /// + /// Gets the Id of the media library scan that this staged music metadata belongs to. + /// + public required Guid LibraryScanId { get; init; } + + /// + /// Gets the Id of the media library that this staged music metadata belongs to. + /// + public required Guid LibraryId { get; init; } + + /// + /// Gets the file system path of the music file whose metadata was extracted. + /// + public required string Path { get; init; } + + /// + /// Gets the name of the artist, if applicable. + /// + public string? ArtistName { get; set; } + + /// + /// Gets the type of the release, if applicable. + /// + public MusicReleaseType? ReleaseType { get; set; } + + /// + /// Gets the release year, if applicable. + /// + public int? ReleaseYear { get; set; } + + /// + /// Gets the name of the release, if applicable. + /// + public string? ReleaseName { get; set; } + + /// + /// Gets the title of the track, if applicable. + /// + public string? TrackTitle { get; set; } + + /// + /// Gets the number of the track on its disc, if applicable. + /// + public int? TrackNumber { get; set; } + + /// + /// Gets the number of the disc the track belongs to, if applicable. + /// + public int? DiscNumber { get; set; } + + /// + /// Gets the duration of the audio in seconds. + /// + public int DurationInSeconds { get; set; } + + /// + /// Gets the sample rate of the audio in Hz. + /// + public int SampleRate { get; set; } + + /// + /// Gets the number of audio channels. + /// + public int Channels { get; set; } + + /// + /// Gets the bit depth of the audio, if applicable. + /// + public int? BitDepth { get; set; } + + /// + /// Gets the audio codec used, if applicable. + /// + public string? AudioCodec { get; set; } + + /// + /// Gets or sets the bitrate of the audio in kbps, if applicable. + /// + public int? Bitrate { get; set; } + + /// + /// Gets or sets the AcoustID fingerprint identifier of the audio file, if applicable. + /// + public string? AcoustId { get; set; } + + /// + /// Gets or sets the ReplayGain track gain in decibels, if applicable. + /// + public decimal? ReplayGainTrackGain { get; set; } + + /// + /// Gets or sets the ReplayGain track peak, if applicable. + /// + public decimal? ReplayGainTrackPeak { get; set; } + + /// + /// Gets or sets the ReplayGain album gain in decibels, if applicable. + /// + public decimal? ReplayGainAlbumGain { get; set; } + + /// + /// Gets or sets the ReplayGain album peak, if applicable. + /// + public decimal? ReplayGainAlbumPeak { get; set; } + + /// + /// Gets or sets the moods of the track, read from the tags of the file. + /// + public List Moods { get; set; } = []; + + /// + /// Gets the MusicBrainz identifier of the artist, read from the tags of the file, if applicable. + /// + public Guid? MusicBrainzArtistId { get; set; } + + /// + /// Gets the MusicBrainz identifier of the release artist, read from the tags of the file, if applicable. + /// + public Guid? MusicBrainzReleaseArtistId { get; set; } + + /// + /// Gets the MusicBrainz identifier of the release group, read from the tags of the file, if applicable. + /// + public Guid? MusicBrainzReleaseGroupId { get; set; } + + /// + /// Gets the MusicBrainz identifier of the release, read from the tags of the file, if applicable. + /// + public Guid? MusicBrainzReleaseId { get; set; } + + /// + /// Gets the MusicBrainz identifier of the recording, read from the tags of the file, if applicable. + /// + public Guid? MusicBrainzRecordingId { get; set; } + + /// + /// Gets the MusicBrainz identifier of the track, read from the tags of the file, if applicable. + /// + public Guid? MusicBrainzTrackId { get; set; } + + /// + /// Gets the MusicBrainz identifier of the work the track is a recording of, read from the tags of the file, if applicable. + /// + public Guid? MusicBrainzWorkId { get; set; } + + /// + /// Gets the title of the work the track is a recording of, read from the tags of the file, if applicable. + /// + public string? WorkTitle { get; set; } +} diff --git a/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/TrackEntity.cs b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/TrackEntity.cs index 8ea83524..23a2794e 100644 --- a/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/TrackEntity.cs +++ b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/TrackEntity.cs @@ -2,6 +2,7 @@ using Lumina.Application.Common.DataAccess.Entities.Common; using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary; using Lumina.Domain.SharedKernel.Common.Enums.Common; +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; using System; using System.Collections.Generic; using System.Diagnostics; @@ -50,6 +51,11 @@ public class TrackEntity : IStorageEntity, IAuditableEntity /// public string? Description { get; set; } + /// + /// Gets or sets the disambiguation comment of the track, used to distinguish tracks with the same title, if applicable. + /// + public string? Disambiguation { get; set; } + /// /// Gets or sets the original release date of the track, if applicable. /// @@ -140,6 +146,31 @@ public class TrackEntity : IStorageEntity, IAuditableEntity /// public int? Bitrate { get; set; } + /// + /// Gets or sets the AcoustID fingerprint identifier of the audio file, if applicable. + /// + public string? AcoustId { get; set; } + + /// + /// Gets or sets the ReplayGain track gain in decibels, if applicable. + /// + public decimal? ReplayGainTrackGain { get; set; } + + /// + /// Gets or sets the ReplayGain track peak, if applicable. + /// + public decimal? ReplayGainTrackPeak { get; set; } + + /// + /// Gets or sets the ReplayGain album gain in decibels, if applicable. + /// + public decimal? ReplayGainAlbumGain { get; set; } + + /// + /// Gets or sets the ReplayGain album peak, if applicable. + /// + public decimal? ReplayGainAlbumPeak { get; set; } + /// /// Gets or sets the number of the track on its disc. /// @@ -165,10 +196,20 @@ public class TrackEntity : IStorageEntity, IAuditableEntity /// public int? Bpm { get; set; } + /// + /// Gets or sets a value indicating whether the recording of the track is a video recording. + /// + public bool IsVideo { get; set; } + /// /// Gets or sets the title of the work the track is a recording of, if applicable. /// - public string? Work { get; set; } + public string? WorkTitle { get; set; } + + /// + /// Gets or sets the MusicBrainz type of the work the track is a recording of, if applicable. + /// + public string? WorkType { get; set; } /// /// Gets or sets the MusicBrainz identifier of the recording, if applicable. @@ -200,6 +241,16 @@ public class TrackEntity : IStorageEntity, IAuditableEntity /// public List Isrcs { get; set; } = []; + /// + /// Gets or sets the list of the languages of the work the track is a recording of. + /// + public List WorkLanguages { get; set; } = []; + + /// + /// Gets or sets the list of ISWC (International Standard Musical Work Code) of the work the track is a recording of. + /// + public List WorkIswcs { get; set; } = []; + /// /// Gets or sets the list of the media contributors of the track. /// @@ -220,6 +271,21 @@ public class TrackEntity : IStorageEntity, IAuditableEntity /// public HashSet Tags { get; set; } = []; + /// + /// Gets or sets the status of the metadata enrichment of the track. + /// + public MetadataStatus MetadataStatus { get; set; } + + /// + /// Gets or sets the date and time when the metadata of the track was last enriched. + /// + public DateTime? LastMetadataUpdateUtc { get; set; } + + /// + /// Gets or sets the name of the plugin that enriched the metadata of the track. + /// + public string? MetadataProvider { get; set; } + /// /// Gets or sets the time and date when the entity was added. /// diff --git a/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/TrackWorkIswcEntity.cs b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/TrackWorkIswcEntity.cs new file mode 100644 index 00000000..dbcfae5b --- /dev/null +++ b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/TrackWorkIswcEntity.cs @@ -0,0 +1,14 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; + +/// +/// Repository entity for an ISWC (International Standard Musical Work Code) of the work a track is a recording of. +/// +/// The value of the ISWC. +[DebuggerDisplay("Value: {Value}")] +public record TrackWorkIswcEntity( + string Value +); diff --git a/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/TrackWorkLanguageEntity.cs b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/TrackWorkLanguageEntity.cs new file mode 100644 index 00000000..ff7197c1 --- /dev/null +++ b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/TrackWorkLanguageEntity.cs @@ -0,0 +1,18 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; + +/// +/// Repository entity for a language of the work a track is a recording of. +/// +/// The ISO 639-1 two-letter language code. +/// The full name of the language in English. +/// The native name of the language, if applicable. +[DebuggerDisplay("LanguageCode: {LanguageCode}")] +public record TrackWorkLanguageEntity( + string LanguageCode, + string LanguageName, + string? NativeName +); diff --git a/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/WrittenContentLibrary/BookLibrary/BookEntity.cs b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/WrittenContentLibrary/BookLibrary/BookEntity.cs index 45779d8a..0cd1b059 100644 --- a/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/WrittenContentLibrary/BookLibrary/BookEntity.cs +++ b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/WrittenContentLibrary/BookLibrary/BookEntity.cs @@ -2,6 +2,7 @@ using Lumina.Application.Common.DataAccess.Entities.Common; using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary; using Lumina.Domain.SharedKernel.Common.Enums.Common; +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/src/Lumina.Application/Common/DataAccess/Entities/UsersManagement/UserSettingsEntity.cs b/src/Lumina.Application/Common/DataAccess/Entities/UsersManagement/UserSettingsEntity.cs index 718dc8cb..877e541b 100644 --- a/src/Lumina.Application/Common/DataAccess/Entities/UsersManagement/UserSettingsEntity.cs +++ b/src/Lumina.Application/Common/DataAccess/Entities/UsersManagement/UserSettingsEntity.cs @@ -47,6 +47,11 @@ public class UserSettingsEntity : IStorageEntity, IAuditableEntity /// public bool ShouldAggregateMetadataWhenMissing { get; set; } + /// + /// Gets or sets whether the artwork of the media library items is aggregated from multiple providers, when it is missing, or not. + /// + public bool ShouldAggregateArtworkWhenMissing { get; set; } + /// /// Gets or sets whether PDF books are rendered as page images for the user, or not. Rendering PDFs as images preserves the /// original layout, but the pages are not selectable or searchable, unlike their text layer. diff --git a/src/Lumina.Application/Common/DataAccess/Repositories/BookLibrary/IBookRepository.cs b/src/Lumina.Application/Common/DataAccess/Repositories/BookLibrary/IBookRepository.cs index 64ddf7cd..56ebf0c6 100644 --- a/src/Lumina.Application/Common/DataAccess/Repositories/BookLibrary/IBookRepository.cs +++ b/src/Lumina.Application/Common/DataAccess/Repositories/BookLibrary/IBookRepository.cs @@ -40,6 +40,15 @@ public interface IBookRepository : IRepository, /// An containing either the stored at the provided path, or an error. Task> GetByPathAsync(Guid libraryId, string path, CancellationToken cancellationToken); + /// + /// Gets the subset of that is already used by a book of the library identified by . + /// + /// The Id of the library whose books are searched. + /// The book paths to check. + /// Cancellation token that can be used to stop the execution. + /// An containing either the paths that are already used, or an error. + Task>> GetExistingPathsAsync(Guid libraryId, IReadOnlyCollection paths, CancellationToken cancellationToken); + /// /// Gets a page of the books of the media library identified by whose metadata has not been enriched yet, /// ordered by path, using keyset pagination. diff --git a/src/Lumina.Application/Common/DataAccess/Repositories/MediaLibrary/ILibraryScanStagingResultsRepository.cs b/src/Lumina.Application/Common/DataAccess/Repositories/MediaLibrary/ILibraryScanStagingResultsRepository.cs index 8c042ba8..1174a464 100644 --- a/src/Lumina.Application/Common/DataAccess/Repositories/MediaLibrary/ILibraryScanStagingResultsRepository.cs +++ b/src/Lumina.Application/Common/DataAccess/Repositories/MediaLibrary/ILibraryScanStagingResultsRepository.cs @@ -55,6 +55,15 @@ public interface ILibraryScanStagingResultsRepository : IRepositoryAn containing either the paths of the changed staging results, or an error. Task>> GetChangedPathsAsync(Guid scanId, CancellationToken cancellationToken); + /// + /// Gets the paths of the media library scan staging results of the current scan that are new or changed, meaning they need their content hashed + /// and their metadata extracted. + /// + /// The unique identifier of the media library scan whose staging result paths are retrieved. + /// Cancellation token that can be used to stop the execution. + /// An containing either the paths of the staging results that need rehashing, or an error. + Task>> GetPathsNeedingRehashAsync(Guid scanId, CancellationToken cancellationToken); + /// /// Updates the content hashes of the provided media library scan staging results. /// diff --git a/src/Lumina.Application/Common/DataAccess/Repositories/MusicLibrary/IAlbumRepository.cs b/src/Lumina.Application/Common/DataAccess/Repositories/MusicLibrary/IAlbumRepository.cs index f4103045..4ad209be 100644 --- a/src/Lumina.Application/Common/DataAccess/Repositories/MusicLibrary/IAlbumRepository.cs +++ b/src/Lumina.Application/Common/DataAccess/Repositories/MusicLibrary/IAlbumRepository.cs @@ -20,7 +20,8 @@ public interface IAlbumRepository : IRepository, IInsertRepositoryAction, IUpdateRepositoryAction, IApplyUpdateRepositoryAction, - IGetByIdRepositoryAction + IGetByIdRepositoryAction, + IDeleteByIdRepositoryAction { /// /// Gets all the albums of the artist identified by . @@ -38,4 +39,67 @@ public interface IAlbumRepository : IRepository, /// Cancellation token that can be used to stop the execution. /// An containing either a paginated result of , or an error. Task>> GetAlbumsLiteByArtistIdAsync(Guid artistId, PaginationDataDto? paginationData, CancellationToken cancellationToken); + + /// + /// Gets the album of the artist identified by that has the provided . + /// + /// The Id of the artist whose album is retrieved. + /// The title of the album to retrieve. + /// Cancellation token that can be used to stop the execution. + /// An containing either the with the provided title, or an error. + Task> GetByTitleAsync(Guid artistId, string title, CancellationToken cancellationToken); + + /// + /// Gets the album of the artist identified by that owns a track stored in the provided . + /// + /// The Id of the artist whose album is retrieved. + /// The file system path of the album directory the album owns. + /// Cancellation token that can be used to stop the execution. + /// An containing either the owning the directory, or an error. + Task> GetByTrackDirectoryAsync(Guid artistId, string directoryPath, CancellationToken cancellationToken); + + /// + /// Gets the number of albums of the media library identified by whose metadata has not been enriched yet. + /// + /// The Id of the media library whose albums are counted. + /// Cancellation token that can be used to stop the execution. + /// An containing either the number of albums needing their metadata enriched, or an error. + Task> GetAlbumsNeedingMetadataCountAsync(Guid libraryId, CancellationToken cancellationToken); + + /// + /// Gets the number of albums of the media library identified by whose artwork has not been resolved yet, + /// meaning they have no artwork that is either enriched or confirmed as unavailable. + /// + /// The Id of the media library whose albums are counted. + /// Cancellation token that can be used to stop the execution. + /// An containing either the number of albums needing their artwork resolved, or an error. + Task> GetAlbumsNeedingArtworkCountAsync(Guid libraryId, CancellationToken cancellationToken); + + /// + /// Gets a page of the albums of the media library identified by whose artwork has not been resolved yet, + /// together with their artist, ordered by Id, excluding the provided albums. + /// + /// The Id of the media library whose albums are retrieved. + /// The Ids of the albums that were already processed in the current run and must not be retrieved again. + /// The maximum number of albums to retrieve. + /// Cancellation token that can be used to stop the execution. + /// An containing either a page of albums needing their artwork resolved, or an error. + Task>> GetAlbumsNeedingArtworkAsync(Guid libraryId, IReadOnlyCollection excludedAlbumIds, int pageSize, CancellationToken cancellationToken); + + /// + /// Gets the file system path of one track of each of the albums identified by , keyed by the Id of the album. + /// + /// The Ids of the albums whose track path is retrieved. + /// Cancellation token that can be used to stop the execution. + /// An containing either the file system path of a track of each album, or an error. + Task>> GetFirstTrackPathsByAlbumIdsAsync(IReadOnlyCollection albumIds, CancellationToken cancellationToken); + + /// + /// Resets the metadata enrichment status of all the albums of the media library identified by , + /// so that they are re-enriched, because the metadata provider configuration of the library changed. + /// + /// The Id of the media library whose albums are reset. + /// Cancellation token that can be used to stop the execution. + /// An representing either a successful operation, or an error. + Task> ResetMetadataStatusForLibraryAsync(Guid libraryId, CancellationToken cancellationToken); } diff --git a/src/Lumina.Application/Common/DataAccess/Repositories/MusicLibrary/IArtistRepository.cs b/src/Lumina.Application/Common/DataAccess/Repositories/MusicLibrary/IArtistRepository.cs index b15e7717..1cc604ac 100644 --- a/src/Lumina.Application/Common/DataAccess/Repositories/MusicLibrary/IArtistRepository.cs +++ b/src/Lumina.Application/Common/DataAccess/Repositories/MusicLibrary/IArtistRepository.cs @@ -3,7 +3,11 @@ using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.Mu using Lumina.Application.Common.DataAccess.Repositories.Common.Actions; using Lumina.Application.Common.DataAccess.Repositories.Common.Base; using Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Artists; +using Lumina.Domain.Common.Primitives; using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; #endregion namespace Lumina.Application.Common.DataAccess.Repositories.MusicLibrary; @@ -19,4 +23,59 @@ public interface IArtistRepository : IRepository, IGetAllLiteRepositoryAction, IDeleteByIdRepositoryAction { + /// + /// Gets the artist of the library identified by that has the provided . + /// + /// The Id of the library whose artist is retrieved. + /// The name of the artist to retrieve. + /// Cancellation token that can be used to stop the execution. + /// An containing either the with the provided name, or an error. + Task> GetByNameAsync(Guid libraryId, string name, CancellationToken cancellationToken); + + /// + /// Gets a page of the artists of the media library identified by whose metadata has not been enriched yet, + /// together with their albums and tracks and the collections needed to enrich them, ordered by name, using keyset pagination. + /// + /// The Id of the media library whose artists are retrieved. + /// The name of the last retrieved artist, used for keyset pagination. Pass to get the first page. + /// The maximum number of artists to retrieve. + /// Cancellation token that can be used to stop the execution. + /// An containing either a page of artists needing their metadata enriched, or an error. + Task>> GetArtistsNeedingMetadataAsync(Guid libraryId, string? lastName, int pageSize, CancellationToken cancellationToken); + + /// + /// Gets the number of artists of the media library identified by whose metadata has not been enriched yet. + /// + /// The Id of the media library whose artists are counted. + /// Cancellation token that can be used to stop the execution. + /// An containing either the number of artists needing their metadata enriched, or an error. + Task> GetArtistsNeedingMetadataCountAsync(Guid libraryId, CancellationToken cancellationToken); + + /// + /// Gets the number of artists of the media library identified by whose artwork has not been resolved yet. + /// + /// The Id of the media library whose artists are counted. + /// Cancellation token that can be used to stop the execution. + /// An containing either the number of artists needing their artwork resolved, or an error. + Task> GetArtistsNeedingArtworkCountAsync(Guid libraryId, CancellationToken cancellationToken); + + /// + /// Gets a page of the artists of the media library identified by whose artwork has not been resolved yet, + /// together with their albums and tracks, ordered by name, using keyset pagination. + /// + /// The Id of the media library whose artists are retrieved. + /// The name of the last retrieved artist, used for keyset pagination. Pass to get the first page. + /// The maximum number of artists to retrieve. + /// Cancellation token that can be used to stop the execution. + /// An containing either a page of artists needing their artwork resolved, or an error. + Task>> GetArtistsNeedingArtworkAsync(Guid libraryId, string? lastName, int pageSize, CancellationToken cancellationToken); + + /// + /// Resets the metadata enrichment status of all the artists of the media library identified by , + /// so that they are re-enriched, because the metadata provider configuration of the library changed. + /// + /// The Id of the media library whose artists are reset. + /// Cancellation token that can be used to stop the execution. + /// An representing either a successful operation, or an error. + Task> ResetMetadataStatusForLibraryAsync(Guid libraryId, CancellationToken cancellationToken); } diff --git a/src/Lumina.Application/Common/DataAccess/Repositories/MusicLibrary/IMusicLibraryScanItemMetadataRepository.cs b/src/Lumina.Application/Common/DataAccess/Repositories/MusicLibrary/IMusicLibraryScanItemMetadataRepository.cs new file mode 100644 index 00000000..488c0d9c --- /dev/null +++ b/src/Lumina.Application/Common/DataAccess/Repositories/MusicLibrary/IMusicLibraryScanItemMetadataRepository.cs @@ -0,0 +1,35 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; +using Lumina.Application.Common.DataAccess.Repositories.Common.Actions; +using Lumina.Application.Common.DataAccess.Repositories.Common.Base; +using Lumina.Domain.Common.Primitives; +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +#endregion + +namespace Lumina.Application.Common.DataAccess.Repositories.MusicLibrary; + +/// +/// Interface for the repository for the music metadata staged during a media library scan. +/// +public interface IMusicLibraryScanItemMetadataRepository : IRepository, + IInsertRangeRepositoryAction +{ + /// + /// Gets all the staged music metadata items of the media library scan identified by . + /// + /// The Id of the media library scan whose staged music metadata is retrieved. + /// Cancellation token that can be used to stop the execution. + /// An containing either a collection of , or an error. + Task>> GetByScanIdAsync(Guid scanId, CancellationToken cancellationToken); + + /// + /// Deletes all the staged music metadata items of the media library scan identified by . + /// + /// The Id of the media library scan whose staged music metadata is deleted. + /// Cancellation token that can be used to stop the execution. + /// An representing either a successful operation, or an error. + Task> DeleteByScanIdAsync(Guid scanId, CancellationToken cancellationToken); +} diff --git a/src/Lumina.Application/Common/DataAccess/Repositories/MusicLibrary/ITrackRepository.cs b/src/Lumina.Application/Common/DataAccess/Repositories/MusicLibrary/ITrackRepository.cs index b2720f5f..72f1b185 100644 --- a/src/Lumina.Application/Common/DataAccess/Repositories/MusicLibrary/ITrackRepository.cs +++ b/src/Lumina.Application/Common/DataAccess/Repositories/MusicLibrary/ITrackRepository.cs @@ -20,7 +20,8 @@ public interface ITrackRepository : IRepository, IInsertRepositoryAction, IUpdateRepositoryAction, IApplyUpdateRepositoryAction, - IGetByIdRepositoryAction + IGetByIdRepositoryAction, + IDeleteByIdRepositoryAction { /// /// Gets the subset of that is already used by a track of the library identified by . @@ -47,4 +48,40 @@ public interface ITrackRepository : IRepository, /// Cancellation token that can be used to stop the execution. /// An containing either a paginated result of , or an error. Task>> GetTracksLiteByAlbumIdAsync(Guid albumId, PaginationDataDto? paginationData, CancellationToken cancellationToken); + + /// + /// Gets the track of the library identified by that is stored at the provided . + /// + /// The Id of the library whose track is retrieved. + /// The file system path of the track to retrieve. + /// Cancellation token that can be used to stop the execution. + /// An containing either the stored at the provided path, or an error. + Task> GetByPathAsync(Guid libraryId, string path, CancellationToken cancellationToken); + + /// + /// Resets the enrichment state of the tracks stored at the provided in the media library identified by + /// , together with their albums and artists, so that they are re-enriched, because their content changed since the last scan. + /// + /// The Id of the media library whose tracks are reset. + /// The file system paths of the tracks whose enrichment state is reset. + /// Cancellation token that can be used to stop the execution. + /// An representing either a successful operation, or an error. + Task> ResetEnrichmentStateForPathsAsync(Guid libraryId, IReadOnlyCollection paths, CancellationToken cancellationToken); + + /// + /// Gets the number of tracks of the media library identified by whose metadata has not been enriched yet. + /// + /// The Id of the media library whose tracks are counted. + /// Cancellation token that can be used to stop the execution. + /// An containing either the number of tracks needing their metadata enriched, or an error. + Task> GetTracksNeedingMetadataCountAsync(Guid libraryId, CancellationToken cancellationToken); + + /// + /// Resets the metadata enrichment status of all the tracks of the media library identified by , + /// so that they are re-enriched, because the metadata provider configuration of the library changed. + /// + /// The Id of the media library whose tracks are reset. + /// Cancellation token that can be used to stop the execution. + /// An representing either a successful operation, or an error. + Task> ResetMetadataStatusForLibraryAsync(Guid libraryId, CancellationToken cancellationToken); } diff --git a/src/Lumina.Application/Common/DataAccess/UoW/IUnitOfWork.cs b/src/Lumina.Application/Common/DataAccess/UoW/IUnitOfWork.cs index f944b9f4..0290d2a0 100644 --- a/src/Lumina.Application/Common/DataAccess/UoW/IUnitOfWork.cs +++ b/src/Lumina.Application/Common/DataAccess/UoW/IUnitOfWork.cs @@ -60,6 +60,16 @@ public interface IUnitOfWork /// ITrackRepository TrackRepository { get; } + /// + /// Gets the repository for the artwork of the music library items. + /// + IMusicArtworkRepository MusicArtworkRepository { get; } + + /// + /// Gets the repository for the music metadata staged during a media library scan. + /// + IMusicLibraryScanItemMetadataRepository MusicLibraryScanItemMetadataRepository { get; } + /// /// Gets the media contributor repository. /// diff --git a/src/Lumina.DataAccess/Common/Configuration/AlbumConfiguration.cs b/src/Lumina.DataAccess/Common/Configuration/AlbumConfiguration.cs index dcfc6aa0..29e95f2f 100644 --- a/src/Lumina.DataAccess/Common/Configuration/AlbumConfiguration.cs +++ b/src/Lumina.DataAccess/Common/Configuration/AlbumConfiguration.cs @@ -1,6 +1,7 @@ #region ========================================================================= USING ===================================================================================== using Lumina.Application.Common.DataAccess.Entities.Common; using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using System; @@ -39,73 +40,96 @@ public class AlbumConfiguration : IEntityTypeConfiguration builder.Property(album => album.OriginalTitle) .HasMaxLength(255) .HasColumnOrder(4); + builder.Property(album => album.ReleaseTitle) + .HasMaxLength(255) + .HasColumnOrder(26); builder.Property(album => album.Description) .HasMaxLength(2000) .HasColumnOrder(5); - builder.Property(album => album.OriginalReleaseDate) + builder.Property(album => album.Disambiguation) + .HasMaxLength(255) .HasColumnOrder(6); - builder.Property(album => album.OriginalReleaseYear) + builder.Property(album => album.OriginalReleaseDate) .HasColumnOrder(7); - builder.Property(album => album.ReReleaseDate) + builder.Property(album => album.OriginalReleaseYear) .HasColumnOrder(8); - builder.Property(album => album.ReReleaseYear) + builder.Property(album => album.ReReleaseDate) .HasColumnOrder(9); + builder.Property(album => album.ReReleaseYear) + .HasColumnOrder(10); builder.Property(album => album.ReleaseCountry) .HasConversion() .HasMaxLength(2) - .HasColumnOrder(10); - builder.Property(album => album.ReleaseVersion) .HasColumnOrder(11); - builder.Property(album => album.LanguageCode) + builder.Property(album => album.ReleaseVersion) .HasColumnOrder(12); - builder.Property(album => album.LanguageName) + builder.Property(album => album.LanguageCode) .HasColumnOrder(13); - builder.Property(album => album.LanguageNativeName) + builder.Property(album => album.LanguageName) .HasColumnOrder(14); - builder.Property(album => album.OriginalLanguageCode) + builder.Property(album => album.LanguageNativeName) .HasColumnOrder(15); - builder.Property(album => album.OriginalLanguageName) + builder.Property(album => album.OriginalLanguageCode) .HasColumnOrder(16); - builder.Property(album => album.OriginalLanguageNativeName) + builder.Property(album => album.OriginalLanguageName) .HasColumnOrder(17); - builder.Property(album => album.ReleaseType) - .HasConversion() - .HasMaxLength(50) + builder.Property(album => album.OriginalLanguageNativeName) .HasColumnOrder(18); + builder.Property(album => album.Script) + .HasMaxLength(50) + .HasColumnOrder(19); builder.Property(album => album.ReleaseStatus) .HasConversion() .HasMaxLength(50) - .HasColumnOrder(19); - builder.Property(album => album.TotalDiscs) .HasColumnOrder(20); - builder.Property(album => album.TotalTracks) + builder.Property(album => album.TotalDiscs) .HasColumnOrder(21); + builder.Property(album => album.TotalTracks) + .HasColumnOrder(22); builder.Property(album => album.MediaFormat) .HasConversion() .HasMaxLength(50) - .HasColumnOrder(22); - builder.Property(album => album.Barcode) - .HasMaxLength(13) .HasColumnOrder(23); - builder.Property(album => album.CatalogNumber) + builder.Property(album => album.Packaging) + .HasConversion() .HasMaxLength(50) .HasColumnOrder(24); - builder.Property(album => album.MusicBrainzReleaseId) + builder.Property(album => album.Barcode) + .HasMaxLength(13) .HasColumnOrder(25); - builder.Property(album => album.MusicBrainzReleaseGroupId) - .HasColumnOrder(26); - builder.Property(album => album.MusicBrainzReleaseArtistId) + builder.Property(album => album.Label) + .HasMaxLength(255) .HasColumnOrder(27); + builder.Property(album => album.ASIN) + .HasMaxLength(20) + .HasColumnOrder(28); + builder.Property(album => album.MusicBrainzReleaseId) + .HasColumnOrder(29); + builder.Property(album => album.MusicBrainzReleaseGroupId) + .HasColumnOrder(30); + builder.Property(album => album.MusicBrainzReleaseArtistId) + .HasColumnOrder(31); builder.Property(album => album.CreatedOnUtc) .IsRequired() - .HasColumnOrder(28); + .HasColumnOrder(32); builder.Property(album => album.CreatedBy) .IsRequired() - .HasColumnOrder(29); + .HasColumnOrder(33); builder.Property(album => album.UpdatedOnUtc) - .HasColumnOrder(30); + .HasColumnOrder(34); builder.Property(album => album.UpdatedBy) - .HasColumnOrder(31); + .HasColumnOrder(35); + builder.Property(album => album.MetadataStatus) + .HasConversion() + .HasMaxLength(20) + .IsRequired() + .HasDefaultValue(MetadataStatus.Pending) + .HasColumnOrder(36); + builder.Property(album => album.LastMetadataUpdateUtc) + .HasColumnOrder(37); + builder.Property(album => album.MetadataProvider) + .HasMaxLength(100) + .HasColumnOrder(38); builder.HasOne(album => album.Artist) .WithMany(artist => artist.Albums) @@ -146,6 +170,35 @@ public class AlbumConfiguration : IEntityTypeConfiguration j.ToTable("AlbumGenres"); }); + builder.OwnsMany(album => album.ReleaseTypes, releaseTypeBuilder => + { + releaseTypeBuilder.ToTable("AlbumReleaseTypes"); + releaseTypeBuilder.WithOwner() + .HasForeignKey("AlbumId"); + releaseTypeBuilder.Property("Id") + .ValueGeneratedOnAdd(); + releaseTypeBuilder.HasKey("Id"); + + releaseTypeBuilder.Property(releaseType => releaseType.ReleaseType) + .HasConversion() + .HasMaxLength(50) + .IsRequired(); + }); + + builder.OwnsMany(album => album.CatalogNumbers, catalogNumberBuilder => + { + catalogNumberBuilder.ToTable("AlbumCatalogNumbers"); + catalogNumberBuilder.WithOwner() + .HasForeignKey("AlbumId"); + catalogNumberBuilder.Property("Id") + .ValueGeneratedOnAdd(); + catalogNumberBuilder.HasKey("Id"); + + catalogNumberBuilder.Property(catalogNumber => catalogNumber.CatalogNumber) + .HasMaxLength(50) + .IsRequired(); + }); + builder.OwnsMany(album => album.Ratings, ratingBuilder => { ratingBuilder.ToTable("AlbumRatings"); diff --git a/src/Lumina.DataAccess/Common/Configuration/ArtistConfiguration.cs b/src/Lumina.DataAccess/Common/Configuration/ArtistConfiguration.cs index 530f6917..a4a63eb7 100644 --- a/src/Lumina.DataAccess/Common/Configuration/ArtistConfiguration.cs +++ b/src/Lumina.DataAccess/Common/Configuration/ArtistConfiguration.cs @@ -1,8 +1,11 @@ #region ========================================================================= USING ===================================================================================== +using Lumina.Application.Common.DataAccess.Entities.Common; using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using System; +using System.Collections.Generic; #endregion namespace Lumina.DataAccess.Common.Configuration; @@ -31,21 +34,168 @@ public class ArtistConfiguration : IEntityTypeConfiguration .IsRequired() .HasMaxLength(255) .HasColumnOrder(2); + builder.Property(artist => artist.SortName) + .HasMaxLength(255) + .HasColumnOrder(3); + builder.Property(artist => artist.Disambiguation) + .HasMaxLength(255) + .HasColumnOrder(4); + builder.Property(artist => artist.Type) + .HasConversion() + .HasMaxLength(20) + .HasColumnOrder(5); + builder.Property(artist => artist.Gender) + .HasConversion() + .HasMaxLength(20) + .HasColumnOrder(6); + builder.Property(artist => artist.Country) + .HasMaxLength(2) + .HasColumnOrder(7); + builder.Property(artist => artist.LifeSpanBegin) + .HasColumnOrder(8); + builder.Property(artist => artist.LifeSpanEnd) + .HasColumnOrder(9); + builder.Property(artist => artist.IsEnded) + .HasColumnOrder(10); builder.Property(artist => artist.Website) .HasMaxLength(2048) - .HasColumnOrder(3); + .HasColumnOrder(11); builder.Property(artist => artist.MusicBrainzArtistId) - .HasColumnOrder(4); + .HasColumnOrder(12); builder.Property(artist => artist.CreatedOnUtc) .IsRequired() - .HasColumnOrder(5); + .HasColumnOrder(13); builder.Property(artist => artist.CreatedBy) .IsRequired() - .HasColumnOrder(6); + .HasColumnOrder(14); builder.Property(artist => artist.UpdatedOnUtc) - .HasColumnOrder(7); + .HasColumnOrder(15); builder.Property(artist => artist.UpdatedBy) - .HasColumnOrder(8); + .HasColumnOrder(16); + builder.Property(artist => artist.MetadataStatus) + .HasConversion() + .HasMaxLength(20) + .IsRequired() + .HasDefaultValue(MetadataStatus.Pending) + .HasColumnOrder(17); + builder.Property(artist => artist.LastMetadataUpdateUtc) + .HasColumnOrder(18); + builder.Property(artist => artist.MetadataProvider) + .HasMaxLength(100) + .HasColumnOrder(19); + + // The areas are owned value objects that are never referenced on their own, so they are stored as JSON documents next to the artist. + builder.OwnsOne(artist => artist.Area, areaBuilder => areaBuilder.ToJson()); + builder.OwnsOne(artist => artist.BeginArea, beginAreaBuilder => beginAreaBuilder.ToJson()); + builder.OwnsOne(artist => artist.EndArea, endAreaBuilder => endAreaBuilder.ToJson()); + + builder.OwnsMany(artist => artist.Aliases, aliasBuilder => + { + aliasBuilder.ToTable("ArtistAliases"); + aliasBuilder.WithOwner() + .HasForeignKey("ArtistId"); + aliasBuilder.Property("Id") + .ValueGeneratedOnAdd(); + aliasBuilder.HasKey("Id"); + + aliasBuilder.Property(alias => alias.Name) + .IsRequired() + .HasMaxLength(255); + aliasBuilder.Property(alias => alias.SortName) + .HasMaxLength(255); + aliasBuilder.Property(alias => alias.Type) + .HasMaxLength(50); + aliasBuilder.Property(alias => alias.Locale) + .HasMaxLength(20); + }); + + builder.OwnsMany(artist => artist.Ipis, ipiBuilder => + { + ipiBuilder.ToTable("ArtistIpis"); + ipiBuilder.WithOwner() + .HasForeignKey("ArtistId"); + ipiBuilder.Property("Id") + .ValueGeneratedOnAdd(); + ipiBuilder.HasKey("Id"); + + ipiBuilder.Property(ipi => ipi.Value) + .IsRequired() + .HasMaxLength(20); + }); + + builder.OwnsMany(artist => artist.Isnis, isniBuilder => + { + isniBuilder.ToTable("ArtistIsnis"); + isniBuilder.WithOwner() + .HasForeignKey("ArtistId"); + isniBuilder.Property("Id") + .ValueGeneratedOnAdd(); + isniBuilder.HasKey("Id"); + + isniBuilder.Property(isni => isni.Value) + .IsRequired() + .HasMaxLength(20); + }); + + // 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(artist => artist.Tags) + .WithMany() + .UsingEntity>( + "ArtistTags", + j => j.HasOne() + .WithMany() + .HasForeignKey("TagId"), + j => j.HasOne() + .WithMany() + .HasForeignKey("ArtistId"), + j => + { + j.HasKey("ArtistId", "TagId"); + j.ToTable("ArtistTags"); + }); + + builder.HasMany(artist => artist.Genres) + .WithMany() + .UsingEntity>( + "ArtistGenres", + j => j.HasOne() + .WithMany() + .HasForeignKey("GenreId"), + j => j.HasOne() + .WithMany() + .HasForeignKey("ArtistId"), + j => + { + j.HasKey("ArtistId", "GenreId"); + j.ToTable("ArtistGenres"); + }); + + builder.OwnsMany(artist => artist.Ratings, ratingBuilder => + { + ratingBuilder.ToTable("ArtistRatings"); + ratingBuilder.WithOwner() + .HasForeignKey("ArtistId"); + ratingBuilder.Property("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() + .HasMaxLength(50) + .IsRequired(false); + }); builder.HasMany(artist => artist.Contributors) .WithOne() diff --git a/src/Lumina.DataAccess/Common/Configuration/MusicLibraryScanItemMetadataConfiguration.cs b/src/Lumina.DataAccess/Common/Configuration/MusicLibraryScanItemMetadataConfiguration.cs new file mode 100644 index 00000000..7cc8aa53 --- /dev/null +++ b/src/Lumina.DataAccess/Common/Configuration/MusicLibraryScanItemMetadataConfiguration.cs @@ -0,0 +1,105 @@ +#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; + +/// +/// Configures the entity mapping for the entity. +/// +public class MusicLibraryScanItemMetadataConfiguration : IEntityTypeConfiguration +{ + /// + /// Configures the entity. + /// + /// The builder to be used to configure the entity. + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable("MusicLibraryScanItemMetadata"); + builder.HasKey(musicMetadata => musicMetadata.Id); + builder.Property(musicMetadata => musicMetadata.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(musicMetadata => musicMetadata.LibraryScanId) + .IsRequired() + .HasColumnOrder(1); + builder.Property(musicMetadata => musicMetadata.LibraryId) + .IsRequired() + .HasColumnOrder(2); + builder.Property(musicMetadata => musicMetadata.Path) + .IsRequired() + .HasMaxLength(2048) + .HasColumnOrder(3); + builder.Property(musicMetadata => musicMetadata.ArtistName) + .HasMaxLength(255) + .HasColumnOrder(4); + builder.Property(musicMetadata => musicMetadata.ReleaseType) + .HasConversion() + .HasMaxLength(50) + .HasColumnOrder(5); + builder.Property(musicMetadata => musicMetadata.ReleaseYear) + .HasColumnOrder(6); + builder.Property(musicMetadata => musicMetadata.ReleaseName) + .HasMaxLength(255) + .HasColumnOrder(7); + builder.Property(musicMetadata => musicMetadata.TrackTitle) + .HasMaxLength(255) + .HasColumnOrder(8); + builder.Property(musicMetadata => musicMetadata.TrackNumber) + .HasColumnOrder(9); + builder.Property(musicMetadata => musicMetadata.DiscNumber) + .HasColumnOrder(10); + builder.Property(musicMetadata => musicMetadata.DurationInSeconds) + .HasColumnOrder(11); + builder.Property(musicMetadata => musicMetadata.SampleRate) + .HasColumnOrder(12); + builder.Property(musicMetadata => musicMetadata.Channels) + .HasColumnOrder(13); + builder.Property(musicMetadata => musicMetadata.BitDepth) + .HasColumnOrder(14); + builder.Property(musicMetadata => musicMetadata.AudioCodec) + .HasMaxLength(50) + .HasColumnOrder(15); + builder.Property(musicMetadata => musicMetadata.Bitrate) + .HasColumnOrder(16); + builder.Property(musicMetadata => musicMetadata.MusicBrainzArtistId) + .HasColumnOrder(17); + builder.Property(musicMetadata => musicMetadata.MusicBrainzReleaseArtistId) + .HasColumnOrder(18); + builder.Property(musicMetadata => musicMetadata.MusicBrainzReleaseGroupId) + .HasColumnOrder(19); + builder.Property(musicMetadata => musicMetadata.MusicBrainzReleaseId) + .HasColumnOrder(20); + builder.Property(musicMetadata => musicMetadata.MusicBrainzRecordingId) + .HasColumnOrder(21); + builder.Property(musicMetadata => musicMetadata.MusicBrainzTrackId) + .HasColumnOrder(22); + builder.Property(musicMetadata => musicMetadata.MusicBrainzWorkId) + .HasColumnOrder(23); + builder.Property(musicMetadata => musicMetadata.WorkTitle) + .HasMaxLength(255) + .HasColumnOrder(24); + builder.Property(musicMetadata => musicMetadata.AcoustId) + .HasMaxLength(64) + .HasColumnOrder(25); + builder.Property(musicMetadata => musicMetadata.ReplayGainTrackGain) + .HasColumnType("decimal(8,2)") + .HasColumnOrder(26); + builder.Property(musicMetadata => musicMetadata.ReplayGainTrackPeak) + .HasColumnType("decimal(8,6)") + .HasColumnOrder(27); + builder.Property(musicMetadata => musicMetadata.ReplayGainAlbumGain) + .HasColumnType("decimal(8,2)") + .HasColumnOrder(28); + builder.Property(musicMetadata => musicMetadata.ReplayGainAlbumPeak) + .HasColumnType("decimal(8,6)") + .HasColumnOrder(29); + builder.PrimitiveCollection(musicMetadata => musicMetadata.Moods) + .HasColumnOrder(30); + + builder.HasIndex(musicMetadata => new { musicMetadata.LibraryScanId, musicMetadata.Path }) + .IsUnique(); // the metadata of the same physical file cannot be staged twice during the same scan + } +} diff --git a/src/Lumina.DataAccess/Common/Configuration/TrackConfiguration.cs b/src/Lumina.DataAccess/Common/Configuration/TrackConfiguration.cs index c32b2194..733def1b 100644 --- a/src/Lumina.DataAccess/Common/Configuration/TrackConfiguration.cs +++ b/src/Lumina.DataAccess/Common/Configuration/TrackConfiguration.cs @@ -1,6 +1,7 @@ #region ========================================================================= USING ===================================================================================== using Lumina.Application.Common.DataAccess.Entities.Common; using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using System; @@ -46,77 +47,111 @@ public class TrackConfiguration : IEntityTypeConfiguration builder.Property(track => track.Description) .HasMaxLength(2000) .HasColumnOrder(6); - builder.Property(track => track.OriginalReleaseDate) + builder.Property(track => track.Disambiguation) + .HasMaxLength(255) .HasColumnOrder(7); - builder.Property(track => track.OriginalReleaseYear) + builder.Property(track => track.OriginalReleaseDate) .HasColumnOrder(8); - builder.Property(track => track.ReReleaseDate) + builder.Property(track => track.OriginalReleaseYear) .HasColumnOrder(9); - builder.Property(track => track.ReReleaseYear) + builder.Property(track => track.ReReleaseDate) .HasColumnOrder(10); + builder.Property(track => track.ReReleaseYear) + .HasColumnOrder(11); builder.Property(track => track.ReleaseCountry) .HasConversion() .HasMaxLength(2) - .HasColumnOrder(11); - builder.Property(track => track.ReleaseVersion) .HasColumnOrder(12); - builder.Property(track => track.LanguageCode) + builder.Property(track => track.ReleaseVersion) .HasColumnOrder(13); - builder.Property(track => track.LanguageName) + builder.Property(track => track.LanguageCode) .HasColumnOrder(14); - builder.Property(track => track.LanguageNativeName) + builder.Property(track => track.LanguageName) .HasColumnOrder(15); - builder.Property(track => track.OriginalLanguageCode) + builder.Property(track => track.LanguageNativeName) .HasColumnOrder(16); - builder.Property(track => track.OriginalLanguageName) + builder.Property(track => track.OriginalLanguageCode) .HasColumnOrder(17); - builder.Property(track => track.OriginalLanguageNativeName) + builder.Property(track => track.OriginalLanguageName) .HasColumnOrder(18); - builder.Property(track => track.DurationInSeconds) + builder.Property(track => track.OriginalLanguageNativeName) .HasColumnOrder(19); - builder.Property(track => track.SampleRate) + builder.Property(track => track.DurationInSeconds) .HasColumnOrder(20); - builder.Property(track => track.Channels) + builder.Property(track => track.SampleRate) .HasColumnOrder(21); - builder.Property(track => track.BitDepth) + builder.Property(track => track.Channels) .HasColumnOrder(22); + builder.Property(track => track.BitDepth) + .HasColumnOrder(23); builder.Property(track => track.AudioCodec) .HasMaxLength(50) - .HasColumnOrder(23); - builder.Property(track => track.Bitrate) .HasColumnOrder(24); - builder.Property(track => track.TrackNumber) + builder.Property(track => track.Bitrate) .HasColumnOrder(25); - builder.Property(track => track.DiscNumber) + builder.Property(track => track.TrackNumber) .HasColumnOrder(26); + builder.Property(track => track.DiscNumber) + .HasColumnOrder(27); builder.Property(track => track.Script) .HasMaxLength(50) - .HasColumnOrder(27); + .HasColumnOrder(28); builder.Property(track => track.Key) .HasConversion() .HasMaxLength(50) - .HasColumnOrder(28); - builder.Property(track => track.Bpm) .HasColumnOrder(29); - builder.Property(track => track.Work) - .HasMaxLength(255) + builder.Property(track => track.Bpm) .HasColumnOrder(30); - builder.Property(track => track.MusicBrainzRecordingId) + builder.Property(track => track.IsVideo) .HasColumnOrder(31); - builder.Property(track => track.MusicBrainzTrackId) + builder.Property(track => track.WorkTitle) + .HasMaxLength(255) .HasColumnOrder(32); - builder.Property(track => track.MusicBrainzWorkId) + builder.Property(track => track.WorkType) + .HasMaxLength(50) .HasColumnOrder(33); + builder.Property(track => track.MusicBrainzRecordingId) + .HasColumnOrder(34); + builder.Property(track => track.MusicBrainzTrackId) + .HasColumnOrder(35); + builder.Property(track => track.MusicBrainzWorkId) + .HasColumnOrder(36); builder.Property(track => track.CreatedOnUtc) .IsRequired() - .HasColumnOrder(34); + .HasColumnOrder(37); builder.Property(track => track.CreatedBy) .IsRequired() - .HasColumnOrder(35); + .HasColumnOrder(38); builder.Property(track => track.UpdatedOnUtc) - .HasColumnOrder(36); + .HasColumnOrder(39); builder.Property(track => track.UpdatedBy) - .HasColumnOrder(37); + .HasColumnOrder(40); + builder.Property(track => track.MetadataStatus) + .HasConversion() + .HasMaxLength(20) + .IsRequired() + .HasDefaultValue(MetadataStatus.Pending) + .HasColumnOrder(41); + builder.Property(track => track.LastMetadataUpdateUtc) + .HasColumnOrder(42); + builder.Property(track => track.MetadataProvider) + .HasMaxLength(100) + .HasColumnOrder(43); + builder.Property(track => track.AcoustId) + .HasMaxLength(64) + .HasColumnOrder(44); + builder.Property(track => track.ReplayGainTrackGain) + .HasColumnType("decimal(8,2)") + .HasColumnOrder(45); + builder.Property(track => track.ReplayGainTrackPeak) + .HasColumnType("decimal(8,6)") + .HasColumnOrder(46); + builder.Property(track => track.ReplayGainAlbumGain) + .HasColumnType("decimal(8,2)") + .HasColumnOrder(47); + builder.Property(track => track.ReplayGainAlbumPeak) + .HasColumnType("decimal(8,6)") + .HasColumnOrder(48); builder.HasOne(track => track.Album) .WithMany(album => album.Tracks) @@ -186,6 +221,39 @@ public class TrackConfiguration : IEntityTypeConfiguration .IsRequired(); }); + builder.OwnsMany(track => track.WorkLanguages, workLanguageBuilder => + { + workLanguageBuilder.ToTable("TrackWorkLanguages"); + workLanguageBuilder.WithOwner() + .HasForeignKey("TrackId"); + workLanguageBuilder.Property("Id") + .ValueGeneratedOnAdd(); + workLanguageBuilder.HasKey("Id"); + + workLanguageBuilder.Property(workLanguage => workLanguage.LanguageCode) + .IsRequired() + .HasMaxLength(5); + workLanguageBuilder.Property(workLanguage => workLanguage.LanguageName) + .IsRequired() + .HasMaxLength(100); + workLanguageBuilder.Property(workLanguage => workLanguage.NativeName) + .HasMaxLength(100); + }); + + builder.OwnsMany(track => track.WorkIswcs, workIswcBuilder => + { + workIswcBuilder.ToTable("TrackWorkIswcs"); + workIswcBuilder.WithOwner() + .HasForeignKey("TrackId"); + workIswcBuilder.Property("Id") + .ValueGeneratedOnAdd(); + workIswcBuilder.HasKey("Id"); + + workIswcBuilder.Property(workIswc => workIswc.Value) + .HasMaxLength(20) + .IsRequired(); + }); + builder.HasMany(track => track.Contributors) .WithOne() .HasForeignKey(contributor => contributor.TrackId) diff --git a/src/Lumina.DataAccess/Common/Configuration/UserSettingsConfiguration.cs b/src/Lumina.DataAccess/Common/Configuration/UserSettingsConfiguration.cs index 3e88f89f..d6713dc8 100644 --- a/src/Lumina.DataAccess/Common/Configuration/UserSettingsConfiguration.cs +++ b/src/Lumina.DataAccess/Common/Configuration/UserSettingsConfiguration.cs @@ -50,6 +50,10 @@ public class UserSettingsConfiguration : IEntityTypeConfiguration settings.ShouldAggregateArtworkWhenMissing) + .IsRequired() + .HasColumnOrder(13); + builder.Property(settings => settings.ShouldRenderPdfAsImages) .IsRequired() .HasColumnOrder(11); diff --git a/src/Lumina.DataAccess/Common/Migrations/20261004113629_AddsMusicLibraryScanningAndMetadata.Designer.cs b/src/Lumina.DataAccess/Common/Migrations/20261004113629_AddsMusicLibraryScanningAndMetadata.Designer.cs new file mode 100644 index 00000000..6628af98 --- /dev/null +++ b/src/Lumina.DataAccess/Common/Migrations/20261004113629_AddsMusicLibraryScanningAndMetadata.Designer.cs @@ -0,0 +1,3381 @@ +// +using System; +using Lumina.DataAccess.Core.UoW; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Lumina.DataAccess.Common.Migrations +{ + [DbContext(typeof(LuminaDbContext))] + [Migration("20261004113629_AddsMusicLibraryScanningAndMetadata")] + partial class AddsMusicLibraryScanningAndMetadata + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "10.0.11"); + + modelBuilder.Entity("AlbumGenres", b => + { + b.Property("AlbumId") + .HasColumnType("TEXT"); + + b.Property("GenreId") + .HasColumnType("TEXT"); + + b.HasKey("AlbumId", "GenreId"); + + b.HasIndex("GenreId"); + + b.ToTable("AlbumGenres", (string)null); + }); + + modelBuilder.Entity("AlbumTags", b => + { + b.Property("AlbumId") + .HasColumnType("TEXT"); + + b.Property("TagId") + .HasColumnType("TEXT"); + + b.HasKey("AlbumId", "TagId"); + + b.HasIndex("TagId"); + + b.ToTable("AlbumTags", (string)null); + }); + + modelBuilder.Entity("ArtistGenres", b => + { + b.Property("ArtistId") + .HasColumnType("TEXT"); + + b.Property("GenreId") + .HasColumnType("TEXT"); + + b.HasKey("ArtistId", "GenreId"); + + b.HasIndex("GenreId"); + + b.ToTable("ArtistGenres", (string)null); + }); + + modelBuilder.Entity("ArtistTags", b => + { + b.Property("ArtistId") + .HasColumnType("TEXT"); + + b.Property("TagId") + .HasColumnType("TEXT"); + + b.HasKey("ArtistId", "TagId"); + + b.HasIndex("TagId"); + + b.ToTable("ArtistTags", (string)null); + }); + + modelBuilder.Entity("BookGenres", b => + { + b.Property("BookId") + .HasColumnType("TEXT"); + + b.Property("GenreId") + .HasColumnType("TEXT"); + + b.HasKey("BookId", "GenreId"); + + b.HasIndex("GenreId"); + + b.ToTable("BookGenres", (string)null); + }); + + modelBuilder.Entity("BookTags", b => + { + b.Property("BookId") + .HasColumnType("TEXT"); + + b.Property("TagId") + .HasColumnType("TEXT"); + + b.HasKey("BookId", "TagId"); + + b.HasIndex("TagId"); + + b.ToTable("BookTags", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.PermissionEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.HasKey("Id"); + + b.ToTable("Permissions", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.RoleEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.HasKey("Id"); + + b.ToTable("Roles", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.RolePermissionEntity", b => + { + b.Property("RoleId") + .HasColumnType("TEXT"); + + b.Property("PermissionId") + .HasColumnType("TEXT"); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.HasKey("RoleId", "PermissionId"); + + b.HasIndex("PermissionId"); + + b.HasIndex("RoleId", "PermissionId") + .IsUnique(); + + b.ToTable("RolePermissions", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.UserPermissionEntity", b => + { + b.Property("UserId") + .HasColumnType("TEXT"); + + b.Property("PermissionId") + .HasColumnType("TEXT"); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.HasKey("UserId", "PermissionId"); + + b.HasIndex("PermissionId"); + + b.HasIndex("UserId", "PermissionId") + .IsUnique(); + + b.ToTable("UserPermissions", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.UserRoleEntity", b => + { + b.Property("UserId") + .HasColumnType("TEXT"); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("RoleId") + .HasColumnType("TEXT"); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.HasKey("UserId"); + + b.HasIndex("RoleId"); + + b.HasIndex("UserId", "RoleId") + .IsUnique(); + + b.ToTable("UserRoles", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Common.GenreEntity", b => + { + b.Property("Name") + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.ToTable("Genres", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Common.TagEntity", b => + { + b.Property("Name") + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.ToTable("Tags", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaContributors.MediaContributorEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("Biography") + .HasMaxLength(2000) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("DateOfBirth") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("DateOfDeath") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("DisplayName") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(1) + .UseCollation("NOCASE"); + + b.Property("LegalName") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.HasKey("Id"); + + b.HasIndex("DisplayName") + .IsUnique(); + + b.ToTable("MediaContributors", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumContributorEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("AlbumId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("MediaContributorId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("Role") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.HasKey("Id"); + + b.HasIndex("MediaContributorId"); + + b.HasIndex("AlbumId", "MediaContributorId", "Role") + .IsUnique(); + + b.ToTable("AlbumContributors", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("ASIN") + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasColumnOrder(28); + + b.Property("ArtistId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("Barcode") + .HasMaxLength(13) + .HasColumnType("TEXT") + .HasColumnOrder(25); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(33); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(32); + + b.Property("Description") + .HasMaxLength(2000) + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("Disambiguation") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("Label") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(27); + + b.Property("LanguageCode") + .HasColumnType("TEXT") + .HasColumnOrder(13); + + b.Property("LanguageName") + .HasColumnType("TEXT") + .HasColumnOrder(14); + + b.Property("LanguageNativeName") + .HasColumnType("TEXT") + .HasColumnOrder(15); + + b.Property("LastMetadataUpdateUtc") + .HasColumnType("TEXT") + .HasColumnOrder(37); + + b.Property("LibraryId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("MediaFormat") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(23); + + b.Property("MetadataProvider") + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(38); + + b.Property("MetadataStatus") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasDefaultValue("Pending") + .HasColumnOrder(36); + + b.Property("MusicBrainzReleaseArtistId") + .HasColumnType("TEXT") + .HasColumnOrder(31); + + b.Property("MusicBrainzReleaseGroupId") + .HasColumnType("TEXT") + .HasColumnOrder(30); + + b.Property("MusicBrainzReleaseId") + .HasColumnType("TEXT") + .HasColumnOrder(29); + + b.Property("OriginalLanguageCode") + .HasColumnType("TEXT") + .HasColumnOrder(16); + + b.Property("OriginalLanguageName") + .HasColumnType("TEXT") + .HasColumnOrder(17); + + b.Property("OriginalLanguageNativeName") + .HasColumnType("TEXT") + .HasColumnOrder(18); + + b.Property("OriginalReleaseDate") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("OriginalReleaseYear") + .HasColumnType("INTEGER") + .HasColumnOrder(8); + + b.Property("OriginalTitle") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("Packaging") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(24); + + b.Property("ReReleaseDate") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("ReReleaseYear") + .HasColumnType("INTEGER") + .HasColumnOrder(10); + + b.Property("ReleaseCountry") + .HasMaxLength(2) + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.Property("ReleaseStatus") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(20); + + b.Property("ReleaseTitle") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(26); + + b.Property("ReleaseVersion") + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.Property("Script") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(19); + + b.Property("Title") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("TotalDiscs") + .HasColumnType("INTEGER") + .HasColumnOrder(21); + + b.Property("TotalTracks") + .HasColumnType("INTEGER") + .HasColumnOrder(22); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(35); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(34); + + b.HasKey("Id"); + + b.HasIndex("ArtistId", "Title"); + + b.HasIndex("LibraryId", "Title"); + + b.ToTable("Albums", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistContributorEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("ArtistId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("MediaContributorId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("Role") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.HasKey("Id"); + + b.HasIndex("MediaContributorId"); + + b.HasIndex("ArtistId", "MediaContributorId", "Role") + .IsUnique(); + + b.ToTable("ArtistContributors", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("Country") + .HasMaxLength(2) + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(14); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(13); + + b.Property("Disambiguation") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("Gender") + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("IsEnded") + .HasColumnType("INTEGER") + .HasColumnOrder(10); + + b.Property("LastMetadataUpdateUtc") + .HasColumnType("TEXT") + .HasColumnOrder(18); + + b.Property("LibraryId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("LifeSpanBegin") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("LifeSpanEnd") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("MetadataProvider") + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(19); + + b.Property("MetadataStatus") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasDefaultValue("Pending") + .HasColumnOrder(17); + + b.Property("MusicBrainzArtistId") + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.Property("Name") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("SortName") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("Type") + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(16); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(15); + + b.Property("Website") + .HasMaxLength(2048) + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.HasKey("Id"); + + b.HasIndex("LibraryId", "Name") + .IsUnique(); + + b.ToTable("Artists", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.MusicArtworkEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("ArtworkType") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("ContentHash") + .HasColumnType("INTEGER") + .HasColumnOrder(6); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("FileName") + .HasMaxLength(2048) + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("LastUpdateUtc") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("Ordinal") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.Property("OwnerId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("OwnerType") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("Provider") + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("Status") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(13); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.HasKey("Id"); + + b.HasIndex("Status"); + + b.HasIndex("OwnerType", "OwnerId", "ArtworkType", "Ordinal") + .IsUnique(); + + b.ToTable("MusicArtwork", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.MusicLibraryScanItemMetadataEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("AcoustId") + .HasMaxLength(64) + .HasColumnType("TEXT") + .HasColumnOrder(25); + + b.Property("ArtistName") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("AudioCodec") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(15); + + b.Property("BitDepth") + .HasColumnType("INTEGER") + .HasColumnOrder(14); + + b.Property("Bitrate") + .HasColumnType("INTEGER") + .HasColumnOrder(16); + + b.Property("Channels") + .HasColumnType("INTEGER") + .HasColumnOrder(13); + + b.Property("DiscNumber") + .HasColumnType("INTEGER") + .HasColumnOrder(10); + + b.Property("DurationInSeconds") + .HasColumnType("INTEGER") + .HasColumnOrder(11); + + b.Property("LibraryId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("LibraryScanId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.PrimitiveCollection("Moods") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(30); + + b.Property("MusicBrainzArtistId") + .HasColumnType("TEXT") + .HasColumnOrder(17); + + b.Property("MusicBrainzRecordingId") + .HasColumnType("TEXT") + .HasColumnOrder(21); + + b.Property("MusicBrainzReleaseArtistId") + .HasColumnType("TEXT") + .HasColumnOrder(18); + + b.Property("MusicBrainzReleaseGroupId") + .HasColumnType("TEXT") + .HasColumnOrder(19); + + b.Property("MusicBrainzReleaseId") + .HasColumnType("TEXT") + .HasColumnOrder(20); + + b.Property("MusicBrainzTrackId") + .HasColumnType("TEXT") + .HasColumnOrder(22); + + b.Property("MusicBrainzWorkId") + .HasColumnType("TEXT") + .HasColumnOrder(23); + + b.Property("Path") + .IsRequired() + .HasMaxLength(2048) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("ReleaseName") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("ReleaseType") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("ReleaseYear") + .HasColumnType("INTEGER") + .HasColumnOrder(6); + + b.Property("ReplayGainAlbumGain") + .HasColumnType("decimal(8,2)") + .HasColumnOrder(28); + + b.Property("ReplayGainAlbumPeak") + .HasColumnType("decimal(8,6)") + .HasColumnOrder(29); + + b.Property("ReplayGainTrackGain") + .HasColumnType("decimal(8,2)") + .HasColumnOrder(26); + + b.Property("ReplayGainTrackPeak") + .HasColumnType("decimal(8,6)") + .HasColumnOrder(27); + + b.Property("SampleRate") + .HasColumnType("INTEGER") + .HasColumnOrder(12); + + b.Property("TrackNumber") + .HasColumnType("INTEGER") + .HasColumnOrder(9); + + b.Property("TrackTitle") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("WorkTitle") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(24); + + b.HasKey("Id"); + + b.HasIndex("LibraryScanId", "Path") + .IsUnique(); + + b.ToTable("MusicLibraryScanItemMetadata", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackContributorEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("MediaContributorId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("Role") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("TrackId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.HasKey("Id"); + + b.HasIndex("MediaContributorId"); + + b.HasIndex("TrackId", "MediaContributorId", "Role") + .IsUnique(); + + b.ToTable("TrackContributors", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("AcoustId") + .HasMaxLength(64) + .HasColumnType("TEXT") + .HasColumnOrder(44); + + b.Property("AlbumId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("AudioCodec") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(24); + + b.Property("BitDepth") + .HasColumnType("INTEGER") + .HasColumnOrder(23); + + b.Property("Bitrate") + .HasColumnType("INTEGER") + .HasColumnOrder(25); + + b.Property("Bpm") + .HasColumnType("INTEGER") + .HasColumnOrder(30); + + b.Property("Channels") + .HasColumnType("INTEGER") + .HasColumnOrder(22); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(38); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(37); + + b.Property("Description") + .HasMaxLength(2000) + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("Disambiguation") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("DiscNumber") + .HasColumnType("INTEGER") + .HasColumnOrder(27); + + b.Property("DurationInSeconds") + .HasColumnType("INTEGER") + .HasColumnOrder(20); + + b.Property("IsVideo") + .HasColumnType("INTEGER") + .HasColumnOrder(31); + + b.Property("Key") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(29); + + b.Property("LanguageCode") + .HasColumnType("TEXT") + .HasColumnOrder(14); + + b.Property("LanguageName") + .HasColumnType("TEXT") + .HasColumnOrder(15); + + b.Property("LanguageNativeName") + .HasColumnType("TEXT") + .HasColumnOrder(16); + + b.Property("LastMetadataUpdateUtc") + .HasColumnType("TEXT") + .HasColumnOrder(42); + + b.Property("LibraryId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("MetadataProvider") + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(43); + + b.Property("MetadataStatus") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasDefaultValue("Pending") + .HasColumnOrder(41); + + b.Property("MusicBrainzRecordingId") + .HasColumnType("TEXT") + .HasColumnOrder(34); + + b.Property("MusicBrainzTrackId") + .HasColumnType("TEXT") + .HasColumnOrder(35); + + b.Property("MusicBrainzWorkId") + .HasColumnType("TEXT") + .HasColumnOrder(36); + + b.Property("OriginalLanguageCode") + .HasColumnType("TEXT") + .HasColumnOrder(17); + + b.Property("OriginalLanguageName") + .HasColumnType("TEXT") + .HasColumnOrder(18); + + b.Property("OriginalLanguageNativeName") + .HasColumnType("TEXT") + .HasColumnOrder(19); + + b.Property("OriginalReleaseDate") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("OriginalReleaseYear") + .HasColumnType("INTEGER") + .HasColumnOrder(9); + + b.Property("OriginalTitle") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("Path") + .IsRequired() + .HasMaxLength(2048) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("ReReleaseDate") + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("ReReleaseYear") + .HasColumnType("INTEGER") + .HasColumnOrder(11); + + b.Property("ReleaseCountry") + .HasMaxLength(2) + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.Property("ReleaseVersion") + .HasColumnType("TEXT") + .HasColumnOrder(13); + + b.Property("ReplayGainAlbumGain") + .HasColumnType("decimal(8,2)") + .HasColumnOrder(47); + + b.Property("ReplayGainAlbumPeak") + .HasColumnType("decimal(8,6)") + .HasColumnOrder(48); + + b.Property("ReplayGainTrackGain") + .HasColumnType("decimal(8,2)") + .HasColumnOrder(45); + + b.Property("ReplayGainTrackPeak") + .HasColumnType("decimal(8,6)") + .HasColumnOrder(46); + + b.Property("SampleRate") + .HasColumnType("INTEGER") + .HasColumnOrder(21); + + b.Property("Script") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(28); + + b.Property("Title") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("TrackNumber") + .HasColumnType("INTEGER") + .HasColumnOrder(26); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(40); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(39); + + b.Property("WorkTitle") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(32); + + b.Property("WorkType") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(33); + + b.HasKey("Id"); + + b.HasIndex("AlbumId", "TrackNumber"); + + b.HasIndex("LibraryId", "Path") + .IsUnique(); + + b.ToTable("Tracks", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.DirectoryScanFingerprintEntity", b => + { + b.Property("LibraryId") + .HasColumnType("TEXT"); + + b.Property("Path") + .HasMaxLength(1024) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("LastWriteTimeUtc") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.HasKey("LibraryId", "Path"); + + b.HasIndex("LibraryId"); + + b.ToTable("DirectoryScanFingerprints", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("ArtworkProvidersConfigurationFingerprint") + .HasMaxLength(64) + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("CanDownloadMetadataFromWeb") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER") + .HasDefaultValue(true) + .HasColumnOrder(6); + + b.Property("CoverImage") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.Property("IsEnabled") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER") + .HasDefaultValue(true) + .HasColumnOrder(4); + + b.Property("IsLocked") + .HasColumnType("INTEGER") + .HasColumnOrder(5); + + b.Property("LibraryType") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("MetadataProvidersConfigurationFingerprint") + .HasMaxLength(64) + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("ShouldSaveMetadataInMediaDirectories") + .HasColumnType("INTEGER") + .HasColumnOrder(7); + + b.Property("ShouldSkipUnchangedDirectoriesDuringScan") + .HasColumnType("INTEGER") + .HasColumnOrder(8); + + b.Property("Title") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(14); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(13); + + b.Property("UserId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Libraries", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("LibraryId") + .HasColumnType("TEXT"); + + b.Property("Status") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("UserId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.HasIndex("LibraryId", "Status", "CreatedOnUtc") + .IsDescending(true, false, true); + + b.ToTable("LibraryScans", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanResultEntity", b => + { + b.Property("LibraryScanId") + .HasColumnType("TEXT"); + + b.Property("Path") + .HasMaxLength(1024) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("ContentHash") + .HasMaxLength(24) + .HasColumnType("INTEGER") + .HasColumnOrder(2); + + b.Property("FileSize") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("Status") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("Ticks") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.HasKey("LibraryScanId", "Path"); + + b.HasIndex("Path"); + + b.HasIndex("ContentHash", "FileSize", "Path"); + + b.ToTable("LibraryScanResults", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanSnapshotEntity", b => + { + b.Property("LibraryId") + .HasColumnType("TEXT"); + + b.Property("Path") + .HasMaxLength(1024) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("ContentHash") + .HasColumnType("INTEGER") + .HasColumnOrder(2); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("FileSize") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("Ticks") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.HasKey("LibraryId", "Path"); + + b.HasIndex("LibraryId"); + + b.ToTable("LibraryScanSnapshots", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanStagingResultsEntity", b => + { + b.Property("LibraryScanId") + .HasColumnType("TEXT"); + + b.Property("Path") + .HasMaxLength(1024) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("ContentHash") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("IsNew") + .HasColumnType("INTEGER") + .HasColumnOrder(7); + + b.Property("NeedsRehash") + .HasColumnType("INTEGER") + .HasColumnOrder(6); + + b.Property("PreviousContentHash") + .HasColumnType("INTEGER") + .HasColumnOrder(5); + + b.Property("Size") + .HasColumnType("INTEGER") + .HasColumnOrder(2); + + b.Property("Ticks") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.HasKey("LibraryScanId", "Path"); + + b.HasIndex("LibraryScanId", "NeedsRehash"); + + b.ToTable("LibraryScanStagingResults", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookArtworkEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("ArtworkType") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("BookId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("ContentHash") + .HasColumnType("INTEGER") + .HasColumnOrder(5); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("FileName") + .HasMaxLength(2048) + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("LastUpdateUtc") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("Ordinal") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("Provider") + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("Status") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.HasKey("Id"); + + b.HasIndex("Status"); + + b.HasIndex("BookId", "ArtworkType", "Ordinal") + .IsUnique(); + + b.ToTable("BookArtwork", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookContributorEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("BookId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("MediaContributorId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("Role") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.HasKey("Id"); + + b.HasIndex("MediaContributorId"); + + b.HasIndex("BookId", "MediaContributorId", "Role") + .IsUnique(); + + b.ToTable("BookContributors", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("ASIN") + .HasMaxLength(10) + .HasColumnType("TEXT") + .HasColumnOrder(21); + + b.Property("AppleBooksId") + .HasColumnType("TEXT") + .HasColumnOrder(29); + + b.Property("BarnesAndNobleId") + .HasMaxLength(10) + .HasColumnType("TEXT") + .HasColumnOrder(28); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(33); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(32); + + b.Property("Description") + .HasMaxLength(2000) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("Edition") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(19); + + b.Property("Format") + .HasColumnType("TEXT") + .HasColumnOrder(18); + + b.Property("GoodreadsId") + .HasColumnType("TEXT") + .HasColumnOrder(22); + + b.Property("GoogleBooksId") + .HasMaxLength(12) + .HasColumnType("TEXT") + .HasColumnOrder(27); + + b.Property("LCCN") + .HasColumnType("TEXT") + .HasColumnOrder(23); + + b.Property("LanguageCode") + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("LanguageName") + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.Property("LanguageNativeName") + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.Property("LastMetadataUpdateUtc") + .HasColumnType("TEXT") + .HasColumnOrder(39); + + b.Property("LibraryId") + .HasColumnType("TEXT") + .HasColumnOrder(36); + + b.Property("LibraryThingId") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(26); + + b.Property("MetadataProvider") + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(40); + + b.Property("MetadataStatus") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasColumnOrder(38); + + b.Property("OCLCNumber") + .HasColumnType("TEXT") + .HasColumnOrder(24); + + b.Property("OpenLibraryId") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(25); + + b.Property("OriginalLanguageCode") + .HasColumnType("TEXT") + .HasColumnOrder(13); + + b.Property("OriginalLanguageName") + .HasColumnType("TEXT") + .HasColumnOrder(14); + + b.Property("OriginalLanguageNativeName") + .HasColumnType("TEXT") + .HasColumnOrder(15); + + b.Property("OriginalReleaseDate") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("OriginalReleaseYear") + .HasColumnType("INTEGER") + .HasColumnOrder(5); + + b.Property("OriginalTitle") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("PageCount") + .HasColumnType("INTEGER") + .HasColumnOrder(17); + + b.Property("Path") + .IsRequired() + .HasMaxLength(2048) + .HasColumnType("TEXT") + .HasColumnOrder(37); + + b.Property("Publisher") + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(16); + + b.Property("ReReleaseDate") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("ReReleaseYear") + .HasColumnType("INTEGER") + .HasColumnOrder(7); + + b.Property("ReleaseCountry") + .HasMaxLength(2) + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("ReleaseVersion") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("Title") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(35); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(34); + + b.Property("VolumeNumber") + .HasColumnType("REAL") + .HasColumnOrder(20); + + b.HasKey("Id"); + + b.HasIndex("LibraryId", "MetadataStatus"); + + b.HasIndex("LibraryId", "Path") + .IsUnique(); + + b.ToTable("Books", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Plugins.LibraryArtworkProviderConfigurationEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("IsEnabled") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("LibraryId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("PluginId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("Rank") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.HasKey("Id"); + + b.HasIndex("LibraryId", "PluginId"); + + b.ToTable("LibraryArtworkProviderConfigurations", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Plugins.LibraryBookReaderConfigurationEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("IsEnabled") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("LibraryId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("PluginId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.HasKey("Id"); + + b.HasIndex("LibraryId", "PluginId") + .IsUnique(); + + b.ToTable("LibraryBookReaderConfigurations", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Plugins.LibraryMetadataProviderConfigurationEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("IsEnabled") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("LibraryId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("PluginId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("Rank") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.HasKey("Id"); + + b.HasIndex("LibraryId", "PluginId"); + + b.ToTable("LibraryMetadataProviderConfigurations", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Plugins.PluginEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("Author") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("Description") + .IsRequired() + .HasMaxLength(2000) + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("LoadError") + .HasMaxLength(2000) + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("LoadStatus") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("Name") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("SettingsJson") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("Version") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.HasKey("Id"); + + b.ToTable("Plugins", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Scheduling.ScheduledJobEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.Property("Hour") + .HasColumnType("INTEGER") + .HasColumnOrder(5); + + b.Property("IntervalMinutes") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.Property("LastCompletedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("LastStartedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("Minute") + .HasColumnType("INTEGER") + .HasColumnOrder(6); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("OwnerUserId") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("ScheduleType") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("Status") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("TaskType") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(14); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(13); + + b.HasKey("Id"); + + b.HasIndex("Status"); + + b.ToTable("ScheduledJobs", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Scheduling.ScheduledJobExecutionEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CompletedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("IsCycleRun") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("ScheduledJobId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("StartedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("TaskType") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("WasCycleActive") + .HasColumnType("INTEGER") + .HasColumnOrder(6); + + b.HasKey("Id"); + + b.HasIndex("ScheduledJobId"); + + b.HasIndex("StartedOnUtc", "ScheduledJobId"); + + b.ToTable("ScheduledJobExecutions", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Scheduling.SchedulerDisplayPreferencesEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("DisplayTimeSpan") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("DisplayTimeUnit") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("JobTypeFilter") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UserId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("SchedulerDisplayPreferences", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Themes.ThemeEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("Author") + .IsRequired() + .HasMaxLength(80) + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.Property("Description") + .IsRequired() + .HasMaxLength(300) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("InstallSource") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("InstalledAtUtc") + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("IsCurrent") + .HasColumnType("INTEGER") + .HasColumnOrder(8); + + b.Property("IsDeleted") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER") + .HasDefaultValue(false) + .HasColumnOrder(9); + + b.Property("Name") + .IsRequired() + .HasMaxLength(80) + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("PreviewPath") + .HasMaxLength(240) + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("ThemeId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(14); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(13); + + b.Property("Version") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.HasKey("Id"); + + b.HasIndex("IsCurrent") + .IsUnique() + .HasFilter("IsCurrent = 1"); + + b.HasIndex("ThemeId") + .IsUnique(); + + b.ToTable("Themes", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("Password") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("TempPassword") + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("TempPasswordCreated") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("TotpSecret") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("Username") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.HasKey("Id"); + + b.HasIndex("Username") + .IsUnique(); + + b.ToTable("Users", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserSettingsEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("IsPaginationEnabled") + .HasColumnType("INTEGER") + .HasColumnOrder(2); + + b.Property("IsThemeCachingEnabled") + .HasColumnType("INTEGER") + .HasColumnOrder(9); + + b.Property("ItemsPerPage") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("ShouldAggregateArtworkWhenMissing") + .HasColumnType("INTEGER") + .HasColumnOrder(13); + + b.Property("ShouldAggregateMetadataWhenMissing") + .HasColumnType("INTEGER") + .HasColumnOrder(10); + + b.Property("ShouldIgnoreThePrefixForAlphaPicker") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.Property("ShouldPreserveBookStyles") + .HasColumnType("INTEGER") + .HasColumnOrder(12); + + b.Property("ShouldRenderPdfAsImages") + .HasColumnType("INTEGER") + .HasColumnOrder(11); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UserId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("UserSettings", (string)null); + }); + + modelBuilder.Entity("TrackGenres", b => + { + b.Property("TrackId") + .HasColumnType("TEXT"); + + b.Property("GenreId") + .HasColumnType("TEXT"); + + b.HasKey("TrackId", "GenreId"); + + b.HasIndex("GenreId"); + + b.ToTable("TrackGenres", (string)null); + }); + + modelBuilder.Entity("TrackTags", b => + { + b.Property("TrackId") + .HasColumnType("TEXT"); + + b.Property("TagId") + .HasColumnType("TEXT"); + + b.HasKey("TrackId", "TagId"); + + b.HasIndex("TagId"); + + b.ToTable("TrackTags", (string)null); + }); + + modelBuilder.Entity("AlbumGenres", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumEntity", null) + .WithMany() + .HasForeignKey("AlbumId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.GenreEntity", null) + .WithMany() + .HasForeignKey("GenreId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("AlbumTags", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumEntity", null) + .WithMany() + .HasForeignKey("AlbumId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.TagEntity", null) + .WithMany() + .HasForeignKey("TagId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ArtistGenres", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistEntity", null) + .WithMany() + .HasForeignKey("ArtistId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.GenreEntity", null) + .WithMany() + .HasForeignKey("GenreId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ArtistTags", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistEntity", null) + .WithMany() + .HasForeignKey("ArtistId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.TagEntity", null) + .WithMany() + .HasForeignKey("TagId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("BookGenres", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", null) + .WithMany() + .HasForeignKey("BookId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.GenreEntity", null) + .WithMany() + .HasForeignKey("GenreId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("BookTags", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", null) + .WithMany() + .HasForeignKey("BookId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.TagEntity", null) + .WithMany() + .HasForeignKey("TagId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.RolePermissionEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Authorization.PermissionEntity", "Permission") + .WithMany("RolePermissions") + .HasForeignKey("PermissionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Authorization.RoleEntity", "Role") + .WithMany("RolePermissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Permission"); + + b.Navigation("Role"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.UserPermissionEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Authorization.PermissionEntity", "Permission") + .WithMany("UserPermissions") + .HasForeignKey("PermissionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", "User") + .WithMany("UserPermissions") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Permission"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.UserRoleEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Authorization.RoleEntity", "Role") + .WithMany("UserRoles") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", "User") + .WithOne("UserRole") + .HasForeignKey("Lumina.Application.Common.DataAccess.Entities.Authorization.UserRoleEntity", "UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumContributorEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumEntity", null) + .WithMany("Contributors") + .HasForeignKey("AlbumId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistEntity", "Artist") + .WithMany("Albums") + .HasForeignKey("ArtistId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumCatalogNumberEntity", "CatalogNumbers", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("AlbumId") + .HasColumnType("TEXT"); + + b1.Property("CatalogNumber") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("AlbumId"); + + b1.ToTable("AlbumCatalogNumbers", (string)null); + + b1.WithOwner() + .HasForeignKey("AlbumId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AudioRatingEntity", "Ratings", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("AlbumId") + .HasColumnType("TEXT"); + + b1.Property("MaxValue") + .HasColumnType("decimal(3,2)"); + + b1.Property("Source") + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b1.Property("Value") + .HasColumnType("decimal(3,2)"); + + b1.Property("VoteCount") + .HasColumnType("INTEGER"); + + b1.HasKey("Id"); + + b1.HasIndex("AlbumId"); + + b1.ToTable("AlbumRatings", (string)null); + + b1.WithOwner() + .HasForeignKey("AlbumId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumReleaseTypeEntity", "ReleaseTypes", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("AlbumId") + .HasColumnType("TEXT"); + + b1.Property("ReleaseType") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("AlbumId"); + + b1.ToTable("AlbumReleaseTypes", (string)null); + + b1.WithOwner() + .HasForeignKey("AlbumId"); + }); + + b.Navigation("Artist"); + + b.Navigation("CatalogNumbers"); + + b.Navigation("Ratings"); + + b.Navigation("ReleaseTypes"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistContributorEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistEntity", null) + .WithMany("Contributors") + .HasForeignKey("ArtistId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistEntity", b => + { + b.OwnsOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.MusicAreaEntity", "Area", b1 => + { + b1.Property("ArtistEntityId"); + + b1.Property("Disambiguation"); + + b1.Property("Iso3166Code"); + + b1.Property("MusicBrainzAreaId"); + + b1.Property("Name") + .IsRequired(); + + b1.Property("SortName"); + + b1.Property("Type"); + + b1.HasKey("ArtistEntityId"); + + b1.ToTable("Artists"); + + b1 + .ToJson("Area") + .HasColumnType("TEXT"); + + b1.WithOwner() + .HasForeignKey("ArtistEntityId"); + }); + + b.OwnsOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.MusicAreaEntity", "BeginArea", b1 => + { + b1.Property("ArtistEntityId"); + + b1.Property("Disambiguation"); + + b1.Property("Iso3166Code"); + + b1.Property("MusicBrainzAreaId"); + + b1.Property("Name") + .IsRequired(); + + b1.Property("SortName"); + + b1.Property("Type"); + + b1.HasKey("ArtistEntityId"); + + b1.ToTable("Artists"); + + b1 + .ToJson("BeginArea") + .HasColumnType("TEXT"); + + b1.WithOwner() + .HasForeignKey("ArtistEntityId"); + }); + + b.OwnsOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.MusicAreaEntity", "EndArea", b1 => + { + b1.Property("ArtistEntityId"); + + b1.Property("Disambiguation"); + + b1.Property("Iso3166Code"); + + b1.Property("MusicBrainzAreaId"); + + b1.Property("Name") + .IsRequired(); + + b1.Property("SortName"); + + b1.Property("Type"); + + b1.HasKey("ArtistEntityId"); + + b1.ToTable("Artists"); + + b1 + .ToJson("EndArea") + .HasColumnType("TEXT"); + + b1.WithOwner() + .HasForeignKey("ArtistEntityId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistAliasEntity", "Aliases", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("ArtistId") + .HasColumnType("TEXT"); + + b1.Property("BeginDate") + .HasColumnType("TEXT"); + + b1.Property("EndDate") + .HasColumnType("TEXT"); + + b1.Property("IsEnded") + .HasColumnType("INTEGER"); + + b1.Property("IsPrimary") + .HasColumnType("INTEGER"); + + b1.Property("Locale") + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b1.Property("Name") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT"); + + b1.Property("SortName") + .HasMaxLength(255) + .HasColumnType("TEXT"); + + b1.Property("Type") + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("ArtistId"); + + b1.ToTable("ArtistAliases", (string)null); + + b1.WithOwner() + .HasForeignKey("ArtistId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AudioRatingEntity", "Ratings", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("ArtistId") + .HasColumnType("TEXT"); + + b1.Property("MaxValue") + .HasColumnType("decimal(3,2)"); + + b1.Property("Source") + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b1.Property("Value") + .HasColumnType("decimal(3,2)"); + + b1.Property("VoteCount") + .HasColumnType("INTEGER"); + + b1.HasKey("Id"); + + b1.HasIndex("ArtistId"); + + b1.ToTable("ArtistRatings", (string)null); + + b1.WithOwner() + .HasForeignKey("ArtistId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistIpiEntity", "Ipis", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("ArtistId") + .HasColumnType("TEXT"); + + b1.Property("Value") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("ArtistId"); + + b1.ToTable("ArtistIpis", (string)null); + + b1.WithOwner() + .HasForeignKey("ArtistId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistIsniEntity", "Isnis", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("ArtistId") + .HasColumnType("TEXT"); + + b1.Property("Value") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("ArtistId"); + + b1.ToTable("ArtistIsnis", (string)null); + + b1.WithOwner() + .HasForeignKey("ArtistId"); + }); + + b.Navigation("Aliases"); + + b.Navigation("Area"); + + b.Navigation("BeginArea"); + + b.Navigation("EndArea"); + + b.Navigation("Ipis"); + + b.Navigation("Isnis"); + + b.Navigation("Ratings"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackContributorEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackEntity", null) + .WithMany("Contributors") + .HasForeignKey("TrackId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumEntity", "Album") + .WithMany("Tracks") + .HasForeignKey("AlbumId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AudioRatingEntity", "Ratings", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("MaxValue") + .HasColumnType("decimal(3,2)"); + + b1.Property("Source") + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b1.Property("TrackId") + .HasColumnType("TEXT"); + + b1.Property("Value") + .HasColumnType("decimal(3,2)"); + + b1.Property("VoteCount") + .HasColumnType("INTEGER"); + + b1.HasKey("Id"); + + b1.HasIndex("TrackId"); + + b1.ToTable("TrackRatings", (string)null); + + b1.WithOwner() + .HasForeignKey("TrackId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackIsrcEntity", "Isrcs", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("TrackId") + .HasColumnType("TEXT"); + + b1.Property("Value") + .IsRequired() + .HasMaxLength(12) + .HasColumnType("TEXT") + .HasColumnName("ISRC"); + + b1.HasKey("Id"); + + b1.HasIndex("TrackId"); + + b1.ToTable("TrackIsrcs", (string)null); + + b1.WithOwner() + .HasForeignKey("TrackId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackMoodEntity", "Moods", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b1.Property("TrackId") + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("TrackId"); + + b1.ToTable("TrackMoods", (string)null); + + b1.WithOwner() + .HasForeignKey("TrackId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackWorkIswcEntity", "WorkIswcs", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("TrackId") + .HasColumnType("TEXT"); + + b1.Property("Value") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("TrackId"); + + b1.ToTable("TrackWorkIswcs", (string)null); + + b1.WithOwner() + .HasForeignKey("TrackId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackWorkLanguageEntity", "WorkLanguages", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("LanguageCode") + .IsRequired() + .HasMaxLength(5) + .HasColumnType("TEXT"); + + b1.Property("LanguageName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b1.Property("NativeName") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b1.Property("TrackId") + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("TrackId"); + + b1.ToTable("TrackWorkLanguages", (string)null); + + b1.WithOwner() + .HasForeignKey("TrackId"); + }); + + b.Navigation("Album"); + + b.Navigation("Isrcs"); + + b.Navigation("Moods"); + + b.Navigation("Ratings"); + + b.Navigation("WorkIswcs"); + + b.Navigation("WorkLanguages"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.DirectoryScanFingerprintEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", null) + .WithMany() + .HasForeignKey("LibraryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", "User") + .WithMany("Libraries") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryContentLocationEntity", "ContentLocations", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("LibraryId") + .HasColumnType("TEXT"); + + b1.Property("Path") + .IsRequired() + .HasMaxLength(260) + .HasColumnType("TEXT") + .HasColumnName("Path"); + + b1.HasKey("Id"); + + b1.HasIndex("LibraryId"); + + b1.ToTable("LibraryContentLocations", (string)null); + + b1.WithOwner() + .HasForeignKey("LibraryId"); + }); + + b.Navigation("ContentLocations"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", "Library") + .WithMany("LibraryScans") + .HasForeignKey("LibraryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", "User") + .WithMany("LibraryScans") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Library"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanResultEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanEntity", "LibraryScan") + .WithMany("LibraryScanResults") + .HasForeignKey("LibraryScanId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("LibraryScan"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanSnapshotEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", "Library") + .WithMany() + .HasForeignKey("LibraryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Library"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanStagingResultsEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanEntity", null) + .WithMany() + .HasForeignKey("LibraryScanId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookArtworkEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", null) + .WithMany("Artwork") + .HasForeignKey("BookId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookContributorEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", null) + .WithMany("Contributors") + .HasForeignKey("BookId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", b => + { + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookRatingEntity", "Ratings", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("BookId") + .HasColumnType("TEXT"); + + b1.Property("MaxValue") + .HasColumnType("decimal(3,2)"); + + b1.Property("Source") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b1.Property("Value") + .HasColumnType("decimal(3,2)"); + + b1.Property("VoteCount") + .HasColumnType("INTEGER"); + + b1.HasKey("Id"); + + b1.HasIndex("BookId"); + + b1.ToTable("BookRatings", (string)null); + + b1.WithOwner() + .HasForeignKey("BookId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.IsbnEntity", "ISBNs", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("BookId") + .HasColumnType("TEXT"); + + b1.Property("Format") + .IsRequired() + .HasMaxLength(6) + .HasColumnType("TEXT"); + + b1.Property("Value") + .IsRequired() + .HasMaxLength(13) + .HasColumnType("TEXT") + .HasColumnName("ISBN"); + + b1.HasKey("Id"); + + b1.HasIndex("BookId"); + + b1.ToTable("BookISBNs", (string)null); + + b1.WithOwner() + .HasForeignKey("BookId"); + }); + + b.Navigation("ISBNs"); + + b.Navigation("Ratings"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserSettingsEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", null) + .WithOne() + .HasForeignKey("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserSettingsEntity", "UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("TrackGenres", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.GenreEntity", null) + .WithMany() + .HasForeignKey("GenreId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackEntity", null) + .WithMany() + .HasForeignKey("TrackId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("TrackTags", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.TagEntity", null) + .WithMany() + .HasForeignKey("TagId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackEntity", null) + .WithMany() + .HasForeignKey("TrackId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.PermissionEntity", b => + { + b.Navigation("RolePermissions"); + + b.Navigation("UserPermissions"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.RoleEntity", b => + { + b.Navigation("RolePermissions"); + + b.Navigation("UserRoles"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumEntity", b => + { + b.Navigation("Contributors"); + + b.Navigation("Tracks"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistEntity", b => + { + b.Navigation("Albums"); + + b.Navigation("Contributors"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackEntity", b => + { + b.Navigation("Contributors"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", b => + { + b.Navigation("LibraryScans"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanEntity", b => + { + b.Navigation("LibraryScanResults"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", b => + { + b.Navigation("Artwork"); + + b.Navigation("Contributors"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", b => + { + b.Navigation("Libraries"); + + b.Navigation("LibraryScans"); + + b.Navigation("UserPermissions"); + + b.Navigation("UserRole"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Lumina.DataAccess/Common/Migrations/20261004113629_AddsMusicLibraryScanningAndMetadata.cs b/src/Lumina.DataAccess/Common/Migrations/20261004113629_AddsMusicLibraryScanningAndMetadata.cs new file mode 100644 index 00000000..a3693dea --- /dev/null +++ b/src/Lumina.DataAccess/Common/Migrations/20261004113629_AddsMusicLibraryScanningAndMetadata.cs @@ -0,0 +1,2199 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Lumina.DataAccess.Common.Migrations +{ + /// + public partial class AddsMusicLibraryScanningAndMetadata : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameColumn( + name: "Work", + table: "Tracks", + newName: "WorkTitle"); + + migrationBuilder.RenameColumn( + name: "ReleaseType", + table: "Albums", + newName: "Script"); + + migrationBuilder.RenameColumn( + name: "CatalogNumber", + table: "Albums", + newName: "Packaging"); + + migrationBuilder.AlterColumn( + name: "UpdatedOnUtc", + table: "Tracks", + type: "TEXT", + nullable: true, + oldClrType: typeof(DateTime), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 39) + .OldAnnotation("Relational:ColumnOrder", 36); + + migrationBuilder.AlterColumn( + name: "UpdatedBy", + table: "Tracks", + type: "TEXT", + nullable: true, + oldClrType: typeof(Guid), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 40) + .OldAnnotation("Relational:ColumnOrder", 37); + + migrationBuilder.AlterColumn( + name: "TrackNumber", + table: "Tracks", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER") + .Annotation("Relational:ColumnOrder", 26) + .OldAnnotation("Relational:ColumnOrder", 25); + + migrationBuilder.AlterColumn( + name: "Script", + table: "Tracks", + type: "TEXT", + maxLength: 50, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 50, + oldNullable: true) + .Annotation("Relational:ColumnOrder", 28) + .OldAnnotation("Relational:ColumnOrder", 27); + + migrationBuilder.AlterColumn( + name: "SampleRate", + table: "Tracks", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER") + .Annotation("Relational:ColumnOrder", 21) + .OldAnnotation("Relational:ColumnOrder", 20); + + migrationBuilder.AlterColumn( + name: "ReleaseVersion", + table: "Tracks", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 13) + .OldAnnotation("Relational:ColumnOrder", 12); + + migrationBuilder.AlterColumn( + name: "ReleaseCountry", + table: "Tracks", + type: "TEXT", + maxLength: 2, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 2, + oldNullable: true) + .Annotation("Relational:ColumnOrder", 12) + .OldAnnotation("Relational:ColumnOrder", 11); + + migrationBuilder.AlterColumn( + name: "ReReleaseYear", + table: "Tracks", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 11) + .OldAnnotation("Relational:ColumnOrder", 10); + + migrationBuilder.AlterColumn( + name: "ReReleaseDate", + table: "Tracks", + type: "TEXT", + nullable: true, + oldClrType: typeof(DateOnly), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 10) + .OldAnnotation("Relational:ColumnOrder", 9); + + migrationBuilder.AlterColumn( + name: "OriginalReleaseYear", + table: "Tracks", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 9) + .OldAnnotation("Relational:ColumnOrder", 8); + + migrationBuilder.AlterColumn( + name: "OriginalReleaseDate", + table: "Tracks", + type: "TEXT", + nullable: true, + oldClrType: typeof(DateOnly), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 8) + .OldAnnotation("Relational:ColumnOrder", 7); + + migrationBuilder.AlterColumn( + name: "OriginalLanguageNativeName", + table: "Tracks", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 19) + .OldAnnotation("Relational:ColumnOrder", 18); + + migrationBuilder.AlterColumn( + name: "OriginalLanguageName", + table: "Tracks", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 18) + .OldAnnotation("Relational:ColumnOrder", 17); + + migrationBuilder.AlterColumn( + name: "OriginalLanguageCode", + table: "Tracks", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 17) + .OldAnnotation("Relational:ColumnOrder", 16); + + migrationBuilder.AlterColumn( + name: "MusicBrainzWorkId", + table: "Tracks", + type: "TEXT", + nullable: true, + oldClrType: typeof(Guid), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 36) + .OldAnnotation("Relational:ColumnOrder", 33); + + migrationBuilder.AlterColumn( + name: "MusicBrainzTrackId", + table: "Tracks", + type: "TEXT", + nullable: true, + oldClrType: typeof(Guid), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 35) + .OldAnnotation("Relational:ColumnOrder", 32); + + migrationBuilder.AlterColumn( + name: "MusicBrainzRecordingId", + table: "Tracks", + type: "TEXT", + nullable: true, + oldClrType: typeof(Guid), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 34) + .OldAnnotation("Relational:ColumnOrder", 31); + + migrationBuilder.AlterColumn( + name: "LanguageNativeName", + table: "Tracks", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 16) + .OldAnnotation("Relational:ColumnOrder", 15); + + migrationBuilder.AlterColumn( + name: "LanguageName", + table: "Tracks", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 15) + .OldAnnotation("Relational:ColumnOrder", 14); + + migrationBuilder.AlterColumn( + name: "LanguageCode", + table: "Tracks", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 14) + .OldAnnotation("Relational:ColumnOrder", 13); + + migrationBuilder.AlterColumn( + name: "Key", + table: "Tracks", + type: "TEXT", + maxLength: 50, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 50, + oldNullable: true) + .Annotation("Relational:ColumnOrder", 29) + .OldAnnotation("Relational:ColumnOrder", 28); + + migrationBuilder.AlterColumn( + name: "DurationInSeconds", + table: "Tracks", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER") + .Annotation("Relational:ColumnOrder", 20) + .OldAnnotation("Relational:ColumnOrder", 19); + + migrationBuilder.AlterColumn( + name: "DiscNumber", + table: "Tracks", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 27) + .OldAnnotation("Relational:ColumnOrder", 26); + + migrationBuilder.AlterColumn( + name: "CreatedOnUtc", + table: "Tracks", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT") + .Annotation("Relational:ColumnOrder", 37) + .OldAnnotation("Relational:ColumnOrder", 34); + + migrationBuilder.AlterColumn( + name: "CreatedBy", + table: "Tracks", + type: "TEXT", + nullable: false, + oldClrType: typeof(Guid), + oldType: "TEXT") + .Annotation("Relational:ColumnOrder", 38) + .OldAnnotation("Relational:ColumnOrder", 35); + + migrationBuilder.AlterColumn( + name: "Channels", + table: "Tracks", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER") + .Annotation("Relational:ColumnOrder", 22) + .OldAnnotation("Relational:ColumnOrder", 21); + + migrationBuilder.AlterColumn( + name: "Bpm", + table: "Tracks", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 30) + .OldAnnotation("Relational:ColumnOrder", 29); + + migrationBuilder.AlterColumn( + name: "Bitrate", + table: "Tracks", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 25) + .OldAnnotation("Relational:ColumnOrder", 24); + + migrationBuilder.AlterColumn( + name: "BitDepth", + table: "Tracks", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 23) + .OldAnnotation("Relational:ColumnOrder", 22); + + migrationBuilder.AlterColumn( + name: "AudioCodec", + table: "Tracks", + type: "TEXT", + maxLength: 50, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 50, + oldNullable: true) + .Annotation("Relational:ColumnOrder", 24) + .OldAnnotation("Relational:ColumnOrder", 23); + + migrationBuilder.AlterColumn( + name: "WorkTitle", + table: "Tracks", + type: "TEXT", + maxLength: 255, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 255, + oldNullable: true) + .Annotation("Relational:ColumnOrder", 32) + .OldAnnotation("Relational:ColumnOrder", 30); + + migrationBuilder.AddColumn( + name: "AcoustId", + table: "Tracks", + type: "TEXT", + maxLength: 64, + nullable: true) + .Annotation("Relational:ColumnOrder", 44); + + migrationBuilder.AddColumn( + name: "Disambiguation", + table: "Tracks", + type: "TEXT", + maxLength: 255, + nullable: true) + .Annotation("Relational:ColumnOrder", 7); + + migrationBuilder.AddColumn( + name: "IsVideo", + table: "Tracks", + type: "INTEGER", + nullable: false, + defaultValue: false) + .Annotation("Relational:ColumnOrder", 31); + + migrationBuilder.AddColumn( + name: "LastMetadataUpdateUtc", + table: "Tracks", + type: "TEXT", + nullable: true) + .Annotation("Relational:ColumnOrder", 42); + + migrationBuilder.AddColumn( + name: "MetadataProvider", + table: "Tracks", + type: "TEXT", + maxLength: 100, + nullable: true) + .Annotation("Relational:ColumnOrder", 43); + + migrationBuilder.AddColumn( + name: "MetadataStatus", + table: "Tracks", + type: "TEXT", + maxLength: 20, + nullable: false, + defaultValue: "Pending") + .Annotation("Relational:ColumnOrder", 41); + + migrationBuilder.AddColumn( + name: "ReplayGainAlbumGain", + table: "Tracks", + type: "decimal(8,2)", + nullable: true) + .Annotation("Relational:ColumnOrder", 47); + + migrationBuilder.AddColumn( + name: "ReplayGainAlbumPeak", + table: "Tracks", + type: "decimal(8,6)", + nullable: true) + .Annotation("Relational:ColumnOrder", 48); + + migrationBuilder.AddColumn( + name: "ReplayGainTrackGain", + table: "Tracks", + type: "decimal(8,2)", + nullable: true) + .Annotation("Relational:ColumnOrder", 45); + + migrationBuilder.AddColumn( + name: "ReplayGainTrackPeak", + table: "Tracks", + type: "decimal(8,6)", + nullable: true) + .Annotation("Relational:ColumnOrder", 46); + + migrationBuilder.AddColumn( + name: "WorkType", + table: "Tracks", + type: "TEXT", + maxLength: 50, + nullable: true) + .Annotation("Relational:ColumnOrder", 33); + + migrationBuilder.AlterColumn( + name: "Website", + table: "Artists", + type: "TEXT", + maxLength: 2048, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 2048, + oldNullable: true) + .Annotation("Relational:ColumnOrder", 11) + .OldAnnotation("Relational:ColumnOrder", 3); + + migrationBuilder.AlterColumn( + name: "UpdatedOnUtc", + table: "Artists", + type: "TEXT", + nullable: true, + oldClrType: typeof(DateTime), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 15) + .OldAnnotation("Relational:ColumnOrder", 7); + + migrationBuilder.AlterColumn( + name: "UpdatedBy", + table: "Artists", + type: "TEXT", + nullable: true, + oldClrType: typeof(Guid), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 16) + .OldAnnotation("Relational:ColumnOrder", 8); + + migrationBuilder.AlterColumn( + name: "MusicBrainzArtistId", + table: "Artists", + type: "TEXT", + nullable: true, + oldClrType: typeof(Guid), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 12) + .OldAnnotation("Relational:ColumnOrder", 4); + + migrationBuilder.AlterColumn( + name: "CreatedOnUtc", + table: "Artists", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT") + .Annotation("Relational:ColumnOrder", 13) + .OldAnnotation("Relational:ColumnOrder", 5); + + migrationBuilder.AlterColumn( + name: "CreatedBy", + table: "Artists", + type: "TEXT", + nullable: false, + oldClrType: typeof(Guid), + oldType: "TEXT") + .Annotation("Relational:ColumnOrder", 14) + .OldAnnotation("Relational:ColumnOrder", 6); + + migrationBuilder.AddColumn( + name: "Area", + table: "Artists", + type: "TEXT", + nullable: true); + + migrationBuilder.AddColumn( + name: "BeginArea", + table: "Artists", + type: "TEXT", + nullable: true); + + migrationBuilder.AddColumn( + name: "Country", + table: "Artists", + type: "TEXT", + maxLength: 2, + nullable: true) + .Annotation("Relational:ColumnOrder", 7); + + migrationBuilder.AddColumn( + name: "Disambiguation", + table: "Artists", + type: "TEXT", + maxLength: 255, + nullable: true) + .Annotation("Relational:ColumnOrder", 4); + + migrationBuilder.AddColumn( + name: "EndArea", + table: "Artists", + type: "TEXT", + nullable: true); + + migrationBuilder.AddColumn( + name: "Gender", + table: "Artists", + type: "TEXT", + maxLength: 20, + nullable: true) + .Annotation("Relational:ColumnOrder", 6); + + migrationBuilder.AddColumn( + name: "IsEnded", + table: "Artists", + type: "INTEGER", + nullable: false, + defaultValue: false) + .Annotation("Relational:ColumnOrder", 10); + + migrationBuilder.AddColumn( + name: "LastMetadataUpdateUtc", + table: "Artists", + type: "TEXT", + nullable: true) + .Annotation("Relational:ColumnOrder", 18); + + migrationBuilder.AddColumn( + name: "LifeSpanBegin", + table: "Artists", + type: "TEXT", + nullable: true) + .Annotation("Relational:ColumnOrder", 8); + + migrationBuilder.AddColumn( + name: "LifeSpanEnd", + table: "Artists", + type: "TEXT", + nullable: true) + .Annotation("Relational:ColumnOrder", 9); + + migrationBuilder.AddColumn( + name: "MetadataProvider", + table: "Artists", + type: "TEXT", + maxLength: 100, + nullable: true) + .Annotation("Relational:ColumnOrder", 19); + + migrationBuilder.AddColumn( + name: "MetadataStatus", + table: "Artists", + type: "TEXT", + maxLength: 20, + nullable: false, + defaultValue: "Pending") + .Annotation("Relational:ColumnOrder", 17); + + migrationBuilder.AddColumn( + name: "SortName", + table: "Artists", + type: "TEXT", + maxLength: 255, + nullable: true) + .Annotation("Relational:ColumnOrder", 3); + + migrationBuilder.AddColumn( + name: "Type", + table: "Artists", + type: "TEXT", + maxLength: 20, + nullable: true) + .Annotation("Relational:ColumnOrder", 5); + + migrationBuilder.AlterColumn( + name: "UpdatedOnUtc", + table: "Albums", + type: "TEXT", + nullable: true, + oldClrType: typeof(DateTime), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 34) + .OldAnnotation("Relational:ColumnOrder", 30); + + migrationBuilder.AlterColumn( + name: "UpdatedBy", + table: "Albums", + type: "TEXT", + nullable: true, + oldClrType: typeof(Guid), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 35) + .OldAnnotation("Relational:ColumnOrder", 31); + + migrationBuilder.AlterColumn( + name: "TotalTracks", + table: "Albums", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER") + .Annotation("Relational:ColumnOrder", 22) + .OldAnnotation("Relational:ColumnOrder", 21); + + migrationBuilder.AlterColumn( + name: "TotalDiscs", + table: "Albums", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 21) + .OldAnnotation("Relational:ColumnOrder", 20); + + migrationBuilder.AlterColumn( + name: "ReleaseVersion", + table: "Albums", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 12) + .OldAnnotation("Relational:ColumnOrder", 11); + + migrationBuilder.AlterColumn( + name: "ReleaseStatus", + table: "Albums", + type: "TEXT", + maxLength: 50, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 50, + oldNullable: true) + .Annotation("Relational:ColumnOrder", 20) + .OldAnnotation("Relational:ColumnOrder", 19); + + migrationBuilder.AlterColumn( + name: "ReleaseCountry", + table: "Albums", + type: "TEXT", + maxLength: 2, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 2, + oldNullable: true) + .Annotation("Relational:ColumnOrder", 11) + .OldAnnotation("Relational:ColumnOrder", 10); + + migrationBuilder.AlterColumn( + name: "ReReleaseYear", + table: "Albums", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 10) + .OldAnnotation("Relational:ColumnOrder", 9); + + migrationBuilder.AlterColumn( + name: "ReReleaseDate", + table: "Albums", + type: "TEXT", + nullable: true, + oldClrType: typeof(DateOnly), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 9) + .OldAnnotation("Relational:ColumnOrder", 8); + + migrationBuilder.AlterColumn( + name: "OriginalReleaseYear", + table: "Albums", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 8) + .OldAnnotation("Relational:ColumnOrder", 7); + + migrationBuilder.AlterColumn( + name: "OriginalReleaseDate", + table: "Albums", + type: "TEXT", + nullable: true, + oldClrType: typeof(DateOnly), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 7) + .OldAnnotation("Relational:ColumnOrder", 6); + + migrationBuilder.AlterColumn( + name: "OriginalLanguageNativeName", + table: "Albums", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 18) + .OldAnnotation("Relational:ColumnOrder", 17); + + migrationBuilder.AlterColumn( + name: "OriginalLanguageName", + table: "Albums", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 17) + .OldAnnotation("Relational:ColumnOrder", 16); + + migrationBuilder.AlterColumn( + name: "OriginalLanguageCode", + table: "Albums", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 16) + .OldAnnotation("Relational:ColumnOrder", 15); + + migrationBuilder.AlterColumn( + name: "MusicBrainzReleaseId", + table: "Albums", + type: "TEXT", + nullable: true, + oldClrType: typeof(Guid), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 29) + .OldAnnotation("Relational:ColumnOrder", 25); + + migrationBuilder.AlterColumn( + name: "MusicBrainzReleaseGroupId", + table: "Albums", + type: "TEXT", + nullable: true, + oldClrType: typeof(Guid), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 30) + .OldAnnotation("Relational:ColumnOrder", 26); + + migrationBuilder.AlterColumn( + name: "MusicBrainzReleaseArtistId", + table: "Albums", + type: "TEXT", + nullable: true, + oldClrType: typeof(Guid), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 31) + .OldAnnotation("Relational:ColumnOrder", 27); + + migrationBuilder.AlterColumn( + name: "MediaFormat", + table: "Albums", + type: "TEXT", + maxLength: 50, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 50, + oldNullable: true) + .Annotation("Relational:ColumnOrder", 23) + .OldAnnotation("Relational:ColumnOrder", 22); + + migrationBuilder.AlterColumn( + name: "LanguageNativeName", + table: "Albums", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 15) + .OldAnnotation("Relational:ColumnOrder", 14); + + migrationBuilder.AlterColumn( + name: "LanguageName", + table: "Albums", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 14) + .OldAnnotation("Relational:ColumnOrder", 13); + + migrationBuilder.AlterColumn( + name: "LanguageCode", + table: "Albums", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 13) + .OldAnnotation("Relational:ColumnOrder", 12); + + migrationBuilder.AlterColumn( + name: "CreatedOnUtc", + table: "Albums", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT") + .Annotation("Relational:ColumnOrder", 32) + .OldAnnotation("Relational:ColumnOrder", 28); + + migrationBuilder.AlterColumn( + name: "CreatedBy", + table: "Albums", + type: "TEXT", + nullable: false, + oldClrType: typeof(Guid), + oldType: "TEXT") + .Annotation("Relational:ColumnOrder", 33) + .OldAnnotation("Relational:ColumnOrder", 29); + + migrationBuilder.AlterColumn( + name: "Barcode", + table: "Albums", + type: "TEXT", + maxLength: 13, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 13, + oldNullable: true) + .Annotation("Relational:ColumnOrder", 25) + .OldAnnotation("Relational:ColumnOrder", 23); + + migrationBuilder.AlterColumn( + name: "Script", + table: "Albums", + type: "TEXT", + maxLength: 50, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 50, + oldNullable: true) + .Annotation("Relational:ColumnOrder", 19) + .OldAnnotation("Relational:ColumnOrder", 18); + + migrationBuilder.AddColumn( + name: "ASIN", + table: "Albums", + type: "TEXT", + maxLength: 20, + nullable: true) + .Annotation("Relational:ColumnOrder", 28); + + migrationBuilder.AddColumn( + name: "Disambiguation", + table: "Albums", + type: "TEXT", + maxLength: 255, + nullable: true) + .Annotation("Relational:ColumnOrder", 6); + + migrationBuilder.AddColumn( + name: "Label", + table: "Albums", + type: "TEXT", + maxLength: 255, + nullable: true) + .Annotation("Relational:ColumnOrder", 27); + + migrationBuilder.AddColumn( + name: "LastMetadataUpdateUtc", + table: "Albums", + type: "TEXT", + nullable: true) + .Annotation("Relational:ColumnOrder", 37); + + migrationBuilder.AddColumn( + name: "MetadataProvider", + table: "Albums", + type: "TEXT", + maxLength: 100, + nullable: true) + .Annotation("Relational:ColumnOrder", 38); + + migrationBuilder.AddColumn( + name: "MetadataStatus", + table: "Albums", + type: "TEXT", + maxLength: 20, + nullable: false, + defaultValue: "Pending") + .Annotation("Relational:ColumnOrder", 36); + + migrationBuilder.AddColumn( + name: "ReleaseTitle", + table: "Albums", + type: "TEXT", + maxLength: 255, + nullable: true) + .Annotation("Relational:ColumnOrder", 26); + + migrationBuilder.CreateTable( + name: "AlbumCatalogNumbers", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + CatalogNumber = table.Column(type: "TEXT", maxLength: 50, nullable: false), + AlbumId = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AlbumCatalogNumbers", x => x.Id); + table.ForeignKey( + name: "FK_AlbumCatalogNumbers_Albums_AlbumId", + column: x => x.AlbumId, + principalTable: "Albums", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AlbumReleaseTypes", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + ReleaseType = table.Column(type: "TEXT", maxLength: 50, nullable: false), + AlbumId = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AlbumReleaseTypes", x => x.Id); + table.ForeignKey( + name: "FK_AlbumReleaseTypes_Albums_AlbumId", + column: x => x.AlbumId, + principalTable: "Albums", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ArtistAliases", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + Name = table.Column(type: "TEXT", maxLength: 255, nullable: false), + SortName = table.Column(type: "TEXT", maxLength: 255, nullable: true), + Type = table.Column(type: "TEXT", maxLength: 50, nullable: true), + Locale = table.Column(type: "TEXT", maxLength: 20, nullable: true), + IsPrimary = table.Column(type: "INTEGER", nullable: false), + BeginDate = table.Column(type: "TEXT", nullable: true), + EndDate = table.Column(type: "TEXT", nullable: true), + IsEnded = table.Column(type: "INTEGER", nullable: false), + ArtistId = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ArtistAliases", x => x.Id); + table.ForeignKey( + name: "FK_ArtistAliases_Artists_ArtistId", + column: x => x.ArtistId, + principalTable: "Artists", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ArtistGenres", + columns: table => new + { + ArtistId = table.Column(type: "TEXT", nullable: false), + GenreId = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ArtistGenres", x => new { x.ArtistId, x.GenreId }); + table.ForeignKey( + name: "FK_ArtistGenres_Artists_ArtistId", + column: x => x.ArtistId, + principalTable: "Artists", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ArtistGenres_Genres_GenreId", + column: x => x.GenreId, + principalTable: "Genres", + principalColumn: "Name", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ArtistIpis", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + Value = table.Column(type: "TEXT", maxLength: 20, nullable: false), + ArtistId = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ArtistIpis", x => x.Id); + table.ForeignKey( + name: "FK_ArtistIpis_Artists_ArtistId", + column: x => x.ArtistId, + principalTable: "Artists", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ArtistIsnis", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + Value = table.Column(type: "TEXT", maxLength: 20, nullable: false), + ArtistId = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ArtistIsnis", x => x.Id); + table.ForeignKey( + name: "FK_ArtistIsnis_Artists_ArtistId", + column: x => x.ArtistId, + principalTable: "Artists", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ArtistRatings", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + Source = table.Column(type: "TEXT", maxLength: 50, nullable: true), + ArtistId = table.Column(type: "TEXT", nullable: false), + Value = table.Column(type: "decimal(3,2)", nullable: false), + MaxValue = table.Column(type: "decimal(3,2)", nullable: false), + VoteCount = table.Column(type: "INTEGER", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ArtistRatings", x => x.Id); + table.ForeignKey( + name: "FK_ArtistRatings_Artists_ArtistId", + column: x => x.ArtistId, + principalTable: "Artists", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ArtistTags", + columns: table => new + { + ArtistId = table.Column(type: "TEXT", nullable: false), + TagId = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ArtistTags", x => new { x.ArtistId, x.TagId }); + table.ForeignKey( + name: "FK_ArtistTags_Artists_ArtistId", + column: x => x.ArtistId, + principalTable: "Artists", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ArtistTags_Tags_TagId", + column: x => x.TagId, + principalTable: "Tags", + principalColumn: "Name", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "MusicArtwork", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + OwnerType = table.Column(type: "TEXT", maxLength: 50, nullable: false), + OwnerId = table.Column(type: "TEXT", nullable: false), + ArtworkType = table.Column(type: "TEXT", maxLength: 50, nullable: false), + Ordinal = table.Column(type: "INTEGER", nullable: false), + FileName = table.Column(type: "TEXT", maxLength: 2048, nullable: true), + ContentHash = table.Column(type: "INTEGER", nullable: false), + Status = table.Column(type: "TEXT", maxLength: 20, nullable: false), + Provider = table.Column(type: "TEXT", maxLength: 100, nullable: true), + LastUpdateUtc = table.Column(type: "TEXT", nullable: true), + CreatedOnUtc = table.Column(type: "TEXT", nullable: false), + CreatedBy = table.Column(type: "TEXT", nullable: false), + UpdatedOnUtc = table.Column(type: "TEXT", nullable: true), + UpdatedBy = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_MusicArtwork", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "MusicLibraryScanItemMetadata", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + LibraryScanId = table.Column(type: "TEXT", nullable: false), + LibraryId = table.Column(type: "TEXT", nullable: false), + Path = table.Column(type: "TEXT", maxLength: 2048, nullable: false), + ArtistName = table.Column(type: "TEXT", maxLength: 255, nullable: true), + ReleaseType = table.Column(type: "TEXT", maxLength: 50, nullable: true), + ReleaseYear = table.Column(type: "INTEGER", nullable: true), + ReleaseName = table.Column(type: "TEXT", maxLength: 255, nullable: true), + TrackTitle = table.Column(type: "TEXT", maxLength: 255, nullable: true), + TrackNumber = table.Column(type: "INTEGER", nullable: true), + DiscNumber = table.Column(type: "INTEGER", nullable: true), + DurationInSeconds = table.Column(type: "INTEGER", nullable: false), + SampleRate = table.Column(type: "INTEGER", nullable: false), + Channels = table.Column(type: "INTEGER", nullable: false), + BitDepth = table.Column(type: "INTEGER", nullable: true), + AudioCodec = table.Column(type: "TEXT", maxLength: 50, nullable: true), + Bitrate = table.Column(type: "INTEGER", nullable: true), + MusicBrainzArtistId = table.Column(type: "TEXT", nullable: true), + MusicBrainzReleaseArtistId = table.Column(type: "TEXT", nullable: true), + MusicBrainzReleaseGroupId = table.Column(type: "TEXT", nullable: true), + MusicBrainzReleaseId = table.Column(type: "TEXT", nullable: true), + MusicBrainzRecordingId = table.Column(type: "TEXT", nullable: true), + MusicBrainzTrackId = table.Column(type: "TEXT", nullable: true), + MusicBrainzWorkId = table.Column(type: "TEXT", nullable: true), + WorkTitle = table.Column(type: "TEXT", maxLength: 255, nullable: true), + AcoustId = table.Column(type: "TEXT", maxLength: 64, nullable: true), + ReplayGainTrackGain = table.Column(type: "decimal(8,2)", nullable: true), + ReplayGainTrackPeak = table.Column(type: "decimal(8,6)", nullable: true), + ReplayGainAlbumGain = table.Column(type: "decimal(8,2)", nullable: true), + ReplayGainAlbumPeak = table.Column(type: "decimal(8,6)", nullable: true), + Moods = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_MusicLibraryScanItemMetadata", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "TrackWorkIswcs", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + Value = table.Column(type: "TEXT", maxLength: 20, nullable: false), + TrackId = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_TrackWorkIswcs", x => x.Id); + table.ForeignKey( + name: "FK_TrackWorkIswcs_Tracks_TrackId", + column: x => x.TrackId, + principalTable: "Tracks", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "TrackWorkLanguages", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + LanguageCode = table.Column(type: "TEXT", maxLength: 5, nullable: false), + LanguageName = table.Column(type: "TEXT", maxLength: 100, nullable: false), + NativeName = table.Column(type: "TEXT", maxLength: 100, nullable: true), + TrackId = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_TrackWorkLanguages", x => x.Id); + table.ForeignKey( + name: "FK_TrackWorkLanguages_Tracks_TrackId", + column: x => x.TrackId, + principalTable: "Tracks", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_AlbumCatalogNumbers_AlbumId", + table: "AlbumCatalogNumbers", + column: "AlbumId"); + + migrationBuilder.CreateIndex( + name: "IX_AlbumReleaseTypes_AlbumId", + table: "AlbumReleaseTypes", + column: "AlbumId"); + + migrationBuilder.CreateIndex( + name: "IX_ArtistAliases_ArtistId", + table: "ArtistAliases", + column: "ArtistId"); + + migrationBuilder.CreateIndex( + name: "IX_ArtistGenres_GenreId", + table: "ArtistGenres", + column: "GenreId"); + + migrationBuilder.CreateIndex( + name: "IX_ArtistIpis_ArtistId", + table: "ArtistIpis", + column: "ArtistId"); + + migrationBuilder.CreateIndex( + name: "IX_ArtistIsnis_ArtistId", + table: "ArtistIsnis", + column: "ArtistId"); + + migrationBuilder.CreateIndex( + name: "IX_ArtistRatings_ArtistId", + table: "ArtistRatings", + column: "ArtistId"); + + migrationBuilder.CreateIndex( + name: "IX_ArtistTags_TagId", + table: "ArtistTags", + column: "TagId"); + + migrationBuilder.CreateIndex( + name: "IX_MusicArtwork_OwnerType_OwnerId_ArtworkType_Ordinal", + table: "MusicArtwork", + columns: new[] { "OwnerType", "OwnerId", "ArtworkType", "Ordinal" }, + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_MusicArtwork_Status", + table: "MusicArtwork", + column: "Status"); + + migrationBuilder.CreateIndex( + name: "IX_MusicLibraryScanItemMetadata_LibraryScanId_Path", + table: "MusicLibraryScanItemMetadata", + columns: new[] { "LibraryScanId", "Path" }, + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_TrackWorkIswcs_TrackId", + table: "TrackWorkIswcs", + column: "TrackId"); + + migrationBuilder.CreateIndex( + name: "IX_TrackWorkLanguages_TrackId", + table: "TrackWorkLanguages", + column: "TrackId"); + + migrationBuilder.AddColumn( + name: "ShouldAggregateArtworkWhenMissing", + table: "UserSettings", + type: "INTEGER", + nullable: false, + defaultValue: false) + .Annotation("Relational:ColumnOrder", 13); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "ShouldAggregateArtworkWhenMissing", + table: "UserSettings"); + + migrationBuilder.DropTable( + name: "AlbumCatalogNumbers"); + + migrationBuilder.DropTable( + name: "AlbumReleaseTypes"); + + migrationBuilder.DropTable( + name: "ArtistAliases"); + + migrationBuilder.DropTable( + name: "ArtistGenres"); + + migrationBuilder.DropTable( + name: "ArtistIpis"); + + migrationBuilder.DropTable( + name: "ArtistIsnis"); + + migrationBuilder.DropTable( + name: "ArtistRatings"); + + migrationBuilder.DropTable( + name: "ArtistTags"); + + migrationBuilder.DropTable( + name: "MusicArtwork"); + + migrationBuilder.DropTable( + name: "MusicLibraryScanItemMetadata"); + + migrationBuilder.DropTable( + name: "TrackWorkIswcs"); + + migrationBuilder.DropTable( + name: "TrackWorkLanguages"); + + migrationBuilder.DropColumn( + name: "AcoustId", + table: "Tracks"); + + migrationBuilder.DropColumn( + name: "Disambiguation", + table: "Tracks"); + + migrationBuilder.DropColumn( + name: "IsVideo", + table: "Tracks"); + + migrationBuilder.DropColumn( + name: "LastMetadataUpdateUtc", + table: "Tracks"); + + migrationBuilder.DropColumn( + name: "MetadataProvider", + table: "Tracks"); + + migrationBuilder.DropColumn( + name: "MetadataStatus", + table: "Tracks"); + + migrationBuilder.DropColumn( + name: "ReplayGainAlbumGain", + table: "Tracks"); + + migrationBuilder.DropColumn( + name: "ReplayGainAlbumPeak", + table: "Tracks"); + + migrationBuilder.DropColumn( + name: "ReplayGainTrackGain", + table: "Tracks"); + + migrationBuilder.DropColumn( + name: "ReplayGainTrackPeak", + table: "Tracks"); + + migrationBuilder.DropColumn( + name: "WorkType", + table: "Tracks"); + + migrationBuilder.DropColumn( + name: "Area", + table: "Artists"); + + migrationBuilder.DropColumn( + name: "BeginArea", + table: "Artists"); + + migrationBuilder.DropColumn( + name: "Country", + table: "Artists"); + + migrationBuilder.DropColumn( + name: "Disambiguation", + table: "Artists"); + + migrationBuilder.DropColumn( + name: "EndArea", + table: "Artists"); + + migrationBuilder.DropColumn( + name: "Gender", + table: "Artists"); + + migrationBuilder.DropColumn( + name: "IsEnded", + table: "Artists"); + + migrationBuilder.DropColumn( + name: "LastMetadataUpdateUtc", + table: "Artists"); + + migrationBuilder.DropColumn( + name: "LifeSpanBegin", + table: "Artists"); + + migrationBuilder.DropColumn( + name: "LifeSpanEnd", + table: "Artists"); + + migrationBuilder.DropColumn( + name: "MetadataProvider", + table: "Artists"); + + migrationBuilder.DropColumn( + name: "MetadataStatus", + table: "Artists"); + + migrationBuilder.DropColumn( + name: "SortName", + table: "Artists"); + + migrationBuilder.DropColumn( + name: "Type", + table: "Artists"); + + migrationBuilder.DropColumn( + name: "ASIN", + table: "Albums"); + + migrationBuilder.DropColumn( + name: "Disambiguation", + table: "Albums"); + + migrationBuilder.DropColumn( + name: "Label", + table: "Albums"); + + migrationBuilder.DropColumn( + name: "LastMetadataUpdateUtc", + table: "Albums"); + + migrationBuilder.DropColumn( + name: "MetadataProvider", + table: "Albums"); + + migrationBuilder.DropColumn( + name: "MetadataStatus", + table: "Albums"); + + migrationBuilder.DropColumn( + name: "ReleaseTitle", + table: "Albums"); + + migrationBuilder.RenameColumn( + name: "WorkTitle", + table: "Tracks", + newName: "Work"); + + migrationBuilder.RenameColumn( + name: "Script", + table: "Albums", + newName: "ReleaseType"); + + migrationBuilder.RenameColumn( + name: "Packaging", + table: "Albums", + newName: "CatalogNumber"); + + migrationBuilder.AlterColumn( + name: "UpdatedOnUtc", + table: "Tracks", + type: "TEXT", + nullable: true, + oldClrType: typeof(DateTime), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 36) + .OldAnnotation("Relational:ColumnOrder", 39); + + migrationBuilder.AlterColumn( + name: "UpdatedBy", + table: "Tracks", + type: "TEXT", + nullable: true, + oldClrType: typeof(Guid), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 37) + .OldAnnotation("Relational:ColumnOrder", 40); + + migrationBuilder.AlterColumn( + name: "TrackNumber", + table: "Tracks", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER") + .Annotation("Relational:ColumnOrder", 25) + .OldAnnotation("Relational:ColumnOrder", 26); + + migrationBuilder.AlterColumn( + name: "Script", + table: "Tracks", + type: "TEXT", + maxLength: 50, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 50, + oldNullable: true) + .Annotation("Relational:ColumnOrder", 27) + .OldAnnotation("Relational:ColumnOrder", 28); + + migrationBuilder.AlterColumn( + name: "SampleRate", + table: "Tracks", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER") + .Annotation("Relational:ColumnOrder", 20) + .OldAnnotation("Relational:ColumnOrder", 21); + + migrationBuilder.AlterColumn( + name: "ReleaseVersion", + table: "Tracks", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 12) + .OldAnnotation("Relational:ColumnOrder", 13); + + migrationBuilder.AlterColumn( + name: "ReleaseCountry", + table: "Tracks", + type: "TEXT", + maxLength: 2, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 2, + oldNullable: true) + .Annotation("Relational:ColumnOrder", 11) + .OldAnnotation("Relational:ColumnOrder", 12); + + migrationBuilder.AlterColumn( + name: "ReReleaseYear", + table: "Tracks", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 10) + .OldAnnotation("Relational:ColumnOrder", 11); + + migrationBuilder.AlterColumn( + name: "ReReleaseDate", + table: "Tracks", + type: "TEXT", + nullable: true, + oldClrType: typeof(DateOnly), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 9) + .OldAnnotation("Relational:ColumnOrder", 10); + + migrationBuilder.AlterColumn( + name: "OriginalReleaseYear", + table: "Tracks", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 8) + .OldAnnotation("Relational:ColumnOrder", 9); + + migrationBuilder.AlterColumn( + name: "OriginalReleaseDate", + table: "Tracks", + type: "TEXT", + nullable: true, + oldClrType: typeof(DateOnly), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 7) + .OldAnnotation("Relational:ColumnOrder", 8); + + migrationBuilder.AlterColumn( + name: "OriginalLanguageNativeName", + table: "Tracks", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 18) + .OldAnnotation("Relational:ColumnOrder", 19); + + migrationBuilder.AlterColumn( + name: "OriginalLanguageName", + table: "Tracks", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 17) + .OldAnnotation("Relational:ColumnOrder", 18); + + migrationBuilder.AlterColumn( + name: "OriginalLanguageCode", + table: "Tracks", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 16) + .OldAnnotation("Relational:ColumnOrder", 17); + + migrationBuilder.AlterColumn( + name: "MusicBrainzWorkId", + table: "Tracks", + type: "TEXT", + nullable: true, + oldClrType: typeof(Guid), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 33) + .OldAnnotation("Relational:ColumnOrder", 36); + + migrationBuilder.AlterColumn( + name: "MusicBrainzTrackId", + table: "Tracks", + type: "TEXT", + nullable: true, + oldClrType: typeof(Guid), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 32) + .OldAnnotation("Relational:ColumnOrder", 35); + + migrationBuilder.AlterColumn( + name: "MusicBrainzRecordingId", + table: "Tracks", + type: "TEXT", + nullable: true, + oldClrType: typeof(Guid), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 31) + .OldAnnotation("Relational:ColumnOrder", 34); + + migrationBuilder.AlterColumn( + name: "LanguageNativeName", + table: "Tracks", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 15) + .OldAnnotation("Relational:ColumnOrder", 16); + + migrationBuilder.AlterColumn( + name: "LanguageName", + table: "Tracks", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 14) + .OldAnnotation("Relational:ColumnOrder", 15); + + migrationBuilder.AlterColumn( + name: "LanguageCode", + table: "Tracks", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 13) + .OldAnnotation("Relational:ColumnOrder", 14); + + migrationBuilder.AlterColumn( + name: "Key", + table: "Tracks", + type: "TEXT", + maxLength: 50, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 50, + oldNullable: true) + .Annotation("Relational:ColumnOrder", 28) + .OldAnnotation("Relational:ColumnOrder", 29); + + migrationBuilder.AlterColumn( + name: "DurationInSeconds", + table: "Tracks", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER") + .Annotation("Relational:ColumnOrder", 19) + .OldAnnotation("Relational:ColumnOrder", 20); + + migrationBuilder.AlterColumn( + name: "DiscNumber", + table: "Tracks", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 26) + .OldAnnotation("Relational:ColumnOrder", 27); + + migrationBuilder.AlterColumn( + name: "CreatedOnUtc", + table: "Tracks", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT") + .Annotation("Relational:ColumnOrder", 34) + .OldAnnotation("Relational:ColumnOrder", 37); + + migrationBuilder.AlterColumn( + name: "CreatedBy", + table: "Tracks", + type: "TEXT", + nullable: false, + oldClrType: typeof(Guid), + oldType: "TEXT") + .Annotation("Relational:ColumnOrder", 35) + .OldAnnotation("Relational:ColumnOrder", 38); + + migrationBuilder.AlterColumn( + name: "Channels", + table: "Tracks", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER") + .Annotation("Relational:ColumnOrder", 21) + .OldAnnotation("Relational:ColumnOrder", 22); + + migrationBuilder.AlterColumn( + name: "Bpm", + table: "Tracks", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 29) + .OldAnnotation("Relational:ColumnOrder", 30); + + migrationBuilder.AlterColumn( + name: "Bitrate", + table: "Tracks", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 24) + .OldAnnotation("Relational:ColumnOrder", 25); + + migrationBuilder.AlterColumn( + name: "BitDepth", + table: "Tracks", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 22) + .OldAnnotation("Relational:ColumnOrder", 23); + + migrationBuilder.AlterColumn( + name: "AudioCodec", + table: "Tracks", + type: "TEXT", + maxLength: 50, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 50, + oldNullable: true) + .Annotation("Relational:ColumnOrder", 23) + .OldAnnotation("Relational:ColumnOrder", 24); + + migrationBuilder.AlterColumn( + name: "Work", + table: "Tracks", + type: "TEXT", + maxLength: 255, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 255, + oldNullable: true) + .Annotation("Relational:ColumnOrder", 30) + .OldAnnotation("Relational:ColumnOrder", 32); + + migrationBuilder.AlterColumn( + name: "Website", + table: "Artists", + type: "TEXT", + maxLength: 2048, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 2048, + oldNullable: true) + .Annotation("Relational:ColumnOrder", 3) + .OldAnnotation("Relational:ColumnOrder", 11); + + migrationBuilder.AlterColumn( + name: "UpdatedOnUtc", + table: "Artists", + type: "TEXT", + nullable: true, + oldClrType: typeof(DateTime), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 7) + .OldAnnotation("Relational:ColumnOrder", 15); + + migrationBuilder.AlterColumn( + name: "UpdatedBy", + table: "Artists", + type: "TEXT", + nullable: true, + oldClrType: typeof(Guid), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 8) + .OldAnnotation("Relational:ColumnOrder", 16); + + migrationBuilder.AlterColumn( + name: "MusicBrainzArtistId", + table: "Artists", + type: "TEXT", + nullable: true, + oldClrType: typeof(Guid), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 4) + .OldAnnotation("Relational:ColumnOrder", 12); + + migrationBuilder.AlterColumn( + name: "CreatedOnUtc", + table: "Artists", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT") + .Annotation("Relational:ColumnOrder", 5) + .OldAnnotation("Relational:ColumnOrder", 13); + + migrationBuilder.AlterColumn( + name: "CreatedBy", + table: "Artists", + type: "TEXT", + nullable: false, + oldClrType: typeof(Guid), + oldType: "TEXT") + .Annotation("Relational:ColumnOrder", 6) + .OldAnnotation("Relational:ColumnOrder", 14); + + migrationBuilder.AlterColumn( + name: "UpdatedOnUtc", + table: "Albums", + type: "TEXT", + nullable: true, + oldClrType: typeof(DateTime), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 30) + .OldAnnotation("Relational:ColumnOrder", 34); + + migrationBuilder.AlterColumn( + name: "UpdatedBy", + table: "Albums", + type: "TEXT", + nullable: true, + oldClrType: typeof(Guid), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 31) + .OldAnnotation("Relational:ColumnOrder", 35); + + migrationBuilder.AlterColumn( + name: "TotalTracks", + table: "Albums", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER") + .Annotation("Relational:ColumnOrder", 21) + .OldAnnotation("Relational:ColumnOrder", 22); + + migrationBuilder.AlterColumn( + name: "TotalDiscs", + table: "Albums", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 20) + .OldAnnotation("Relational:ColumnOrder", 21); + + migrationBuilder.AlterColumn( + name: "ReleaseVersion", + table: "Albums", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 11) + .OldAnnotation("Relational:ColumnOrder", 12); + + migrationBuilder.AlterColumn( + name: "ReleaseStatus", + table: "Albums", + type: "TEXT", + maxLength: 50, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 50, + oldNullable: true) + .Annotation("Relational:ColumnOrder", 19) + .OldAnnotation("Relational:ColumnOrder", 20); + + migrationBuilder.AlterColumn( + name: "ReleaseCountry", + table: "Albums", + type: "TEXT", + maxLength: 2, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 2, + oldNullable: true) + .Annotation("Relational:ColumnOrder", 10) + .OldAnnotation("Relational:ColumnOrder", 11); + + migrationBuilder.AlterColumn( + name: "ReReleaseYear", + table: "Albums", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 9) + .OldAnnotation("Relational:ColumnOrder", 10); + + migrationBuilder.AlterColumn( + name: "ReReleaseDate", + table: "Albums", + type: "TEXT", + nullable: true, + oldClrType: typeof(DateOnly), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 8) + .OldAnnotation("Relational:ColumnOrder", 9); + + migrationBuilder.AlterColumn( + name: "OriginalReleaseYear", + table: "Albums", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 7) + .OldAnnotation("Relational:ColumnOrder", 8); + + migrationBuilder.AlterColumn( + name: "OriginalReleaseDate", + table: "Albums", + type: "TEXT", + nullable: true, + oldClrType: typeof(DateOnly), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 6) + .OldAnnotation("Relational:ColumnOrder", 7); + + migrationBuilder.AlterColumn( + name: "OriginalLanguageNativeName", + table: "Albums", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 17) + .OldAnnotation("Relational:ColumnOrder", 18); + + migrationBuilder.AlterColumn( + name: "OriginalLanguageName", + table: "Albums", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 16) + .OldAnnotation("Relational:ColumnOrder", 17); + + migrationBuilder.AlterColumn( + name: "OriginalLanguageCode", + table: "Albums", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 15) + .OldAnnotation("Relational:ColumnOrder", 16); + + migrationBuilder.AlterColumn( + name: "MusicBrainzReleaseId", + table: "Albums", + type: "TEXT", + nullable: true, + oldClrType: typeof(Guid), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 25) + .OldAnnotation("Relational:ColumnOrder", 29); + + migrationBuilder.AlterColumn( + name: "MusicBrainzReleaseGroupId", + table: "Albums", + type: "TEXT", + nullable: true, + oldClrType: typeof(Guid), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 26) + .OldAnnotation("Relational:ColumnOrder", 30); + + migrationBuilder.AlterColumn( + name: "MusicBrainzReleaseArtistId", + table: "Albums", + type: "TEXT", + nullable: true, + oldClrType: typeof(Guid), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 27) + .OldAnnotation("Relational:ColumnOrder", 31); + + migrationBuilder.AlterColumn( + name: "MediaFormat", + table: "Albums", + type: "TEXT", + maxLength: 50, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 50, + oldNullable: true) + .Annotation("Relational:ColumnOrder", 22) + .OldAnnotation("Relational:ColumnOrder", 23); + + migrationBuilder.AlterColumn( + name: "LanguageNativeName", + table: "Albums", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 14) + .OldAnnotation("Relational:ColumnOrder", 15); + + migrationBuilder.AlterColumn( + name: "LanguageName", + table: "Albums", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 13) + .OldAnnotation("Relational:ColumnOrder", 14); + + migrationBuilder.AlterColumn( + name: "LanguageCode", + table: "Albums", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 12) + .OldAnnotation("Relational:ColumnOrder", 13); + + migrationBuilder.AlterColumn( + name: "CreatedOnUtc", + table: "Albums", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT") + .Annotation("Relational:ColumnOrder", 28) + .OldAnnotation("Relational:ColumnOrder", 32); + + migrationBuilder.AlterColumn( + name: "CreatedBy", + table: "Albums", + type: "TEXT", + nullable: false, + oldClrType: typeof(Guid), + oldType: "TEXT") + .Annotation("Relational:ColumnOrder", 29) + .OldAnnotation("Relational:ColumnOrder", 33); + + migrationBuilder.AlterColumn( + name: "Barcode", + table: "Albums", + type: "TEXT", + maxLength: 13, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 13, + oldNullable: true) + .Annotation("Relational:ColumnOrder", 23) + .OldAnnotation("Relational:ColumnOrder", 25); + + migrationBuilder.AlterColumn( + name: "ReleaseType", + table: "Albums", + type: "TEXT", + maxLength: 50, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 50, + oldNullable: true) + .Annotation("Relational:ColumnOrder", 18) + .OldAnnotation("Relational:ColumnOrder", 19); + } + } +} diff --git a/src/Lumina.DataAccess/Core/Repositories/BookLibrary/BookRepository.cs b/src/Lumina.DataAccess/Core/Repositories/BookLibrary/BookRepository.cs index f0fca470..b1490003 100644 --- a/src/Lumina.DataAccess/Core/Repositories/BookLibrary/BookRepository.cs +++ b/src/Lumina.DataAccess/Core/Repositories/BookLibrary/BookRepository.cs @@ -308,6 +308,27 @@ internal sealed class BookRepository : IBookRepository .FirstOrDefaultAsync(book => book.LibraryId == libraryId && book.Path == path, cancellationToken).ConfigureAwait(false); } + /// + /// Gets the subset of that is already used by a book of the library identified by . + /// + /// The Id of the library whose books are searched. + /// The book paths to check. + /// Cancellation token that can be used to stop the execution. + /// An containing either the paths that are already used, or an error. + public async Task>> GetExistingPathsAsync(Guid libraryId, IReadOnlyCollection paths, CancellationToken cancellationToken) + { + if (paths.Count == 0) + return Result.From>([]); + + // The stored paths are compared ordinally, matching the case sensitive comparison used by the unique index of the storage medium. + List distinctPaths = [.. paths.Distinct(StringComparer.Ordinal)]; + List existingPaths = await _luminaDbContext.Books + .Where(repositoryBook => repositoryBook.LibraryId == libraryId && distinctPaths.Contains(repositoryBook.Path)) + .Select(repositoryBook => repositoryBook.Path) + .ToListAsync(cancellationToken).ConfigureAwait(false); + return Result.From>(existingPaths); + } + /// /// Gets a page of the books of the media library identified by whose metadata has not been enriched yet, /// ordered by path, using keyset pagination. diff --git a/src/Lumina.DataAccess/Core/Repositories/Libraries/LibraryScanStagingResultsRepository.cs b/src/Lumina.DataAccess/Core/Repositories/Libraries/LibraryScanStagingResultsRepository.cs index 2c5c87fb..8a4ddcef 100644 --- a/src/Lumina.DataAccess/Core/Repositories/Libraries/LibraryScanStagingResultsRepository.cs +++ b/src/Lumina.DataAccess/Core/Repositories/Libraries/LibraryScanStagingResultsRepository.cs @@ -169,6 +169,29 @@ internal sealed class LibraryScanStagingResultsRepository : ILibraryScanStagingR return paths.ToList(); } + /// + /// Gets the paths of the media library scan staging results of the current scan that are new or changed, meaning they need their content hashed + /// and their metadata extracted. + /// + /// The unique identifier of the media library scan whose staging result paths are retrieved. + /// Cancellation token that can be used to stop the execution. + /// An containing either the paths of the staging results that need rehashing, or an error. + public async Task>> GetPathsNeedingRehashAsync(Guid scanId, CancellationToken cancellationToken) + { + await using SqliteConnection connection = await OpenConnectionAsync(cancellationToken).ConfigureAwait(false); + const string GET_PATHS_SQL = """ + SELECT Path + FROM LibraryScanStagingResults + WHERE LibraryScanId = @scanId + AND NeedsRehash = 1; + """; + + CommandDefinition command = new(GET_PATHS_SQL, new { scanId }, cancellationToken: cancellationToken); + + IEnumerable paths = await connection.QueryAsync(command).ConfigureAwait(false); + return paths.ToList(); + } + /// /// Updates the content hashes of the provided media library scan staging results. /// diff --git a/src/Lumina.DataAccess/Core/Repositories/MediaContributors/MediaContributorRepository.cs b/src/Lumina.DataAccess/Core/Repositories/MediaContributors/MediaContributorRepository.cs index ca219011..cddee8c2 100644 --- a/src/Lumina.DataAccess/Core/Repositories/MediaContributors/MediaContributorRepository.cs +++ b/src/Lumina.DataAccess/Core/Repositories/MediaContributors/MediaContributorRepository.cs @@ -2,6 +2,7 @@ using Lumina.Application.Common.DataAccess.Entities.MediaContributors; using Lumina.Application.Common.DataAccess.Repositories.MediaContributors; using Lumina.DataAccess.Core.UoW; +using Lumina.Domain.Common.Errors; using Lumina.Domain.Common.Primitives; using Microsoft.EntityFrameworkCore; using System; @@ -37,6 +38,19 @@ internal sealed class MediaContributorRepository : IMediaContributorRepository /// An representing either a successful operation, or an error. public async Task> InsertAsync(MediaContributorEntity contributor, CancellationToken cancellationToken) { + bool doesContributorExist = await _luminaDbContext.MediaContributors + .AnyAsync(repositoryContributor => repositoryContributor.Id == contributor.Id, cancellationToken: cancellationToken) + .ConfigureAwait(false); + if (doesContributorExist) + return Errors.MediaContributor.MediaContributorAlreadyExists; + + // A contributor is unique by its display name, so the same person can never be registered twice under different spellings of the same name. + bool doesContributorNameExist = await _luminaDbContext.MediaContributors + .AnyAsync(repositoryContributor => EF.Functions.Collate(repositoryContributor.DisplayName, "NOCASE") == contributor.DisplayName, cancellationToken: cancellationToken) + .ConfigureAwait(false); + if (doesContributorNameExist) + return Errors.MediaContributor.MediaContributorAlreadyExists; + _luminaDbContext.MediaContributors.Add(contributor); return Result.Created; } @@ -54,8 +68,19 @@ internal sealed class MediaContributorRepository : IMediaContributorRepository // the comparison is case-insensitive, so that "Stephen King" and "stephen king" are never treated as distinct contributors string normalizedDisplayName = displayName.ToLowerInvariant(); + // Contributors added earlier in the same unit of work are not returned by a database query, so the change tracker is consulted + // first; without this, the same contributor discovered for several items of the same save would be inserted more than once and + // violate the unique index on the display name. + MediaContributorEntity? trackedContributor = _luminaDbContext.MediaContributors.Local + .FirstOrDefault(contributor => contributor.DisplayName.ToLowerInvariant() == normalizedDisplayName); + if (trackedContributor is not null) + return trackedContributor; + + // The lookup must use the same case-insensitive collation as the unique index on the display name, so that a name whose case is + // not folded by the storage medium (for example one that starts with a non-ASCII uppercase letter) is still matched, instead of + // being inserted again and violating the unique index. MediaContributorEntity? existingContributor = await _luminaDbContext.MediaContributors - .FirstOrDefaultAsync(contributor => contributor.DisplayName.ToLower() == normalizedDisplayName, cancellationToken) + .FirstOrDefaultAsync(contributor => EF.Functions.Collate(contributor.DisplayName, "NOCASE") == displayName, cancellationToken) .ConfigureAwait(false); if (existingContributor is not null) return existingContributor; diff --git a/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/AlbumRepository.cs b/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/AlbumRepository.cs index a4d6a119..c0f21bbb 100644 --- a/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/AlbumRepository.cs +++ b/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/AlbumRepository.cs @@ -8,9 +8,12 @@ using Lumina.DataAccess.Common.Persistence; using Lumina.DataAccess.Core.UoW; using Lumina.Domain.Common.Errors; using Lumina.Domain.Common.Primitives; +using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary; +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -170,6 +173,24 @@ internal sealed class AlbumRepository : IAlbumRepository shouldReplace: (existingContributor, incomingContributor) => false, createNew: incomingContributor => incomingContributor); + // The types of the release are owned value objects whose value is also their identity, so a match means there is nothing to change. + CollectionReconciler.Reconcile( + foundAlbum.ReleaseTypes, + data.ReleaseTypes, + existingReleaseType => existingReleaseType.ReleaseType, + incomingReleaseType => incomingReleaseType.ReleaseType, + shouldReplace: (existingReleaseType, incomingReleaseType) => false, + createNew: incomingReleaseType => incomingReleaseType); + + // The catalog numbers of the release are owned value objects whose value is also their identity, so a match means there is nothing to change. + CollectionReconciler.Reconcile( + foundAlbum.CatalogNumbers, + data.CatalogNumbers, + existingCatalogNumber => existingCatalogNumber.CatalogNumber, + incomingCatalogNumber => incomingCatalogNumber.CatalogNumber, + shouldReplace: (existingCatalogNumber, incomingCatalogNumber) => false, + createNew: incomingCatalogNumber => incomingCatalogNumber); + return Result.Updated; } @@ -297,4 +318,152 @@ internal sealed class AlbumRepository : IAlbumRepository NumberOfPages = numberOfPages }; } + + /// + /// Gets the album of the artist identified by that has the provided . + /// + /// The Id of the artist whose album is retrieved. + /// The title of the album to retrieve. + /// Cancellation token that can be used to stop the execution. + /// An containing either the with the provided title, or an error. + public async Task> GetByTitleAsync(Guid artistId, string title, CancellationToken cancellationToken) + { + AlbumEntity? album = await _luminaDbContext.Albums + .FirstOrDefaultAsync(repositoryAlbum => repositoryAlbum.ArtistId == artistId && repositoryAlbum.Title == title, cancellationToken).ConfigureAwait(false); + return album; + } + + /// + /// Gets the album of the artist identified by that owns a track stored in the provided . + /// + /// The Id of the artist whose album is retrieved. + /// The file system path of the album directory the album owns. + /// Cancellation token that can be used to stop the execution. + /// An containing either the owning the directory, or an error. + public async Task> GetByTrackDirectoryAsync(Guid artistId, string directoryPath, CancellationToken cancellationToken) + { + // The trailing separator is part of the prefix, so a directory whose name is a prefix of another directory does not match it. + string directoryPrefix = directoryPath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar) + Path.DirectorySeparatorChar; + AlbumEntity? album = await _luminaDbContext.Albums + .FirstOrDefaultAsync(repositoryAlbum => repositoryAlbum.ArtistId == artistId + && repositoryAlbum.Tracks.Any(track => track.Path.StartsWith(directoryPrefix)), cancellationToken).ConfigureAwait(false); + return album; + } + + /// + /// Deletes the album identified by , together with its tracks and its contributions, by the database cascade. + /// + /// The Id of the album to delete. + /// Cancellation token that can be used to stop the execution. + /// An representing either a successful operation, or an error. + public async Task> DeleteByIdAsync(Guid id, CancellationToken cancellationToken) + { + AlbumEntity? album = await _luminaDbContext.Albums + .FirstOrDefaultAsync(repositoryAlbum => repositoryAlbum.Id == id, cancellationToken).ConfigureAwait(false); + if (album is null) + return Errors.Music.AlbumNotFound; + + _luminaDbContext.Albums.Remove(album); + return Result.Deleted; + } + + /// + /// Gets the number of albums of the media library identified by whose metadata has not been enriched yet. + /// + /// The Id of the media library whose albums are counted. + /// Cancellation token that can be used to stop the execution. + /// An containing either the number of albums needing their metadata enriched, or an error. + public async Task> GetAlbumsNeedingMetadataCountAsync(Guid libraryId, CancellationToken cancellationToken) + { + return await _luminaDbContext.Albums + .CountAsync(album => album.LibraryId == libraryId && album.MetadataStatus != MetadataStatus.Enriched, cancellationToken).ConfigureAwait(false); + } + + /// + /// Gets the number of albums of the media library identified by whose artwork has not been resolved yet. + /// + /// The Id of the media library whose albums are counted. + /// Cancellation token that can be used to stop the execution. + /// An containing either the number of albums needing their artwork resolved, or an error. + public async Task> GetAlbumsNeedingArtworkCountAsync(Guid libraryId, CancellationToken cancellationToken) + { + return await _luminaDbContext.Albums + .CountAsync(album => album.LibraryId == libraryId + && !_luminaDbContext.MusicArtwork.Any(musicArtwork => musicArtwork.OwnerType == MusicArtworkOwnerType.Album + && musicArtwork.OwnerId == album.Id + && (musicArtwork.Status == ArtworkStatus.Enriched || musicArtwork.Status == ArtworkStatus.NotAvailable)), cancellationToken).ConfigureAwait(false); + } + + /// + /// Gets a page of the albums of the media library identified by whose artwork has not been resolved yet, + /// together with their artist, ordered by Id, excluding the provided albums. + /// + /// The Id of the media library whose albums are retrieved. + /// The Ids of the albums that were already processed in the current run and must not be retrieved again. + /// The maximum number of albums to retrieve. + /// Cancellation token that can be used to stop the execution. + /// An containing either a page of albums needing their artwork resolved, or an error. + public async Task>> GetAlbumsNeedingArtworkAsync(Guid libraryId, IReadOnlyCollection excludedAlbumIds, int pageSize, CancellationToken cancellationToken) + { + List excludedIds = [.. excludedAlbumIds]; + return await _luminaDbContext.Albums + .AsNoTracking() + .Include(album => album.Artist) + .Where(album => album.LibraryId == libraryId + && !excludedIds.Contains(album.Id) + && !_luminaDbContext.MusicArtwork.Any(musicArtwork => musicArtwork.OwnerType == MusicArtworkOwnerType.Album + && musicArtwork.OwnerId == album.Id + && (musicArtwork.Status == ArtworkStatus.Enriched || musicArtwork.Status == ArtworkStatus.NotAvailable))) + .OrderBy(album => album.Id) + .Take(pageSize) + .ToListAsync(cancellationToken).ConfigureAwait(false); + } + + /// + /// Gets the file system path of one track of each of the albums identified by , keyed by the Id of the album. + /// + /// The Ids of the albums whose track path is retrieved. + /// Cancellation token that can be used to stop the execution. + /// An containing either the file system path of a track of each album, or an error. + public async Task>> GetFirstTrackPathsByAlbumIdsAsync(IReadOnlyCollection albumIds, CancellationToken cancellationToken) + { + List albumIdsList = [.. albumIds]; + if (albumIdsList.Count == 0) + return new Dictionary(); + + List rows = await _luminaDbContext.Tracks + .AsNoTracking() + .Where(track => albumIdsList.Contains(track.AlbumId)) + .OrderBy(track => track.AlbumId) + .ThenBy(track => track.Path) + .Select(track => new AlbumTrackPathRow(track.AlbumId, track.Path)) + .ToListAsync(cancellationToken).ConfigureAwait(false); + + // Only one track path is needed per album, so the first one, in the deterministic order above, is kept for each album. + Dictionary firstTrackPaths = []; + foreach (AlbumTrackPathRow row in rows) + firstTrackPaths.TryAdd(row.AlbumId, row.Path); + return firstTrackPaths; + } + + /// + /// Resets the metadata enrichment status of all the albums of the media library identified by . + /// + /// The Id of the media library whose albums are reset. + /// Cancellation token that can be used to stop the execution. + /// An representing either a successful operation, or an error. + public async Task> ResetMetadataStatusForLibraryAsync(Guid libraryId, CancellationToken cancellationToken) + { + await _luminaDbContext.Albums + .Where(album => album.LibraryId == libraryId) + .ExecuteUpdateAsync(setters => setters.SetProperty(album => album.MetadataStatus, MetadataStatus.Pending), cancellationToken).ConfigureAwait(false); + return Result.Updated; + } + + /// + /// The file system path of one track of an album, used to describe the album in an artwork lookup. + /// + /// The Id of the album the track belongs to. + /// The file system path of the track. + private sealed record AlbumTrackPathRow(Guid AlbumId, string Path); } diff --git a/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/ArtistRepository.cs b/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/ArtistRepository.cs index 7387003e..fea91e76 100644 --- a/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/ArtistRepository.cs +++ b/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/ArtistRepository.cs @@ -11,7 +11,9 @@ using Lumina.DataAccess.Core.Repositories.MusicLibrary.Specifications; using Lumina.DataAccess.Core.UoW; using Lumina.Domain.Common.Errors; using Lumina.Domain.Common.Primitives; +using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary; using Lumina.Domain.SharedKernel.Common.Enums.Common; +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; @@ -72,7 +74,7 @@ internal sealed class ArtistRepository : IArtistRepository // neither a stored row nor a name shared by several albums or tracks of the same request is tracked more than once. Result> resolveTagsResult = await SharedReferenceResolver.ResolveAsync( _luminaDbContext, - artist.Albums.SelectMany(album => album.Tags).Concat(artist.Albums.SelectMany(album => album.Tracks.SelectMany(track => track.Tags))), + artist.Tags.Concat(artist.Albums.SelectMany(album => album.Tags)).Concat(artist.Albums.SelectMany(album => album.Tracks.SelectMany(track => track.Tags))), Errors.Metadata.TagNameCannotBeEmpty, cancellationToken).ConfigureAwait(false); if (resolveTagsResult.IsFailure) @@ -80,12 +82,15 @@ internal sealed class ArtistRepository : IArtistRepository Result> resolveGenresResult = await SharedReferenceResolver.ResolveAsync( _luminaDbContext, - artist.Albums.SelectMany(album => album.Genres).Concat(artist.Albums.SelectMany(album => album.Tracks.SelectMany(track => track.Genres))), + artist.Genres.Concat(artist.Albums.SelectMany(album => album.Genres)).Concat(artist.Albums.SelectMany(album => album.Tracks.SelectMany(track => track.Genres))), Errors.Metadata.GenreNameCannotBeEmpty, cancellationToken).ConfigureAwait(false); if (resolveGenresResult.IsFailure) return resolveGenresResult.Errors; + artist.Tags = [.. SharedReferenceResolver.Normalize(artist.Tags, resolveTagsResult.Value)]; + artist.Genres = [.. SharedReferenceResolver.Normalize(artist.Genres, resolveGenresResult.Value)]; + foreach (AlbumEntity album in artist.Albums) { album.Tags = [.. SharedReferenceResolver.Normalize(album.Tags, resolveTagsResult.Value)]; @@ -113,6 +118,8 @@ internal sealed class ArtistRepository : IArtistRepository // The whole aggregate is loaded once, including every collection that the album and track repositories reconcile, so that those repositories can apply the // edit to the already tracked children instead of loading each album and each track again. ArtistEntity? foundArtist = await _luminaDbContext.Artists + .Include(repositoryArtist => repositoryArtist.Tags) + .Include(repositoryArtist => repositoryArtist.Genres) .Include(repositoryArtist => repositoryArtist.Contributors) .Include(repositoryArtist => repositoryArtist.Albums) .ThenInclude(album => album.Tags) @@ -160,6 +167,47 @@ internal sealed class ArtistRepository : IArtistRepository shouldReplace: (existingContributor, incomingContributor) => false, createNew: incomingContributor => incomingContributor); + // The tags and the genres of the artist are shared across the whole database, so the stored rows whose names already exist are reused. + Result reconcileTagsResult = await SharedReferenceResolver.ReconcileAsync(_luminaDbContext, foundArtist.Tags, data.Tags, Errors.Metadata.TagNameCannotBeEmpty, cancellationToken).ConfigureAwait(false); + if (reconcileTagsResult.IsFailure) + return reconcileTagsResult.Errors; + Result reconcileGenresResult = await SharedReferenceResolver.ReconcileAsync(_luminaDbContext, foundArtist.Genres, data.Genres, Errors.Metadata.GenreNameCannotBeEmpty, cancellationToken).ConfigureAwait(false); + if (reconcileGenresResult.IsFailure) + return reconcileGenresResult.Errors; + + // The ratings, the aliases and the identifiers of the artist are owned value objects with no identity anyone could reference, so a changed value is replaced as a whole. + CollectionReconciler.Reconcile( + foundArtist.Ratings, + data.Ratings, + existingRating => existingRating.Source?.ToString() ?? string.Empty, + incomingRating => incomingRating.Source?.ToString() ?? string.Empty, + shouldReplace: (existingRating, incomingRating) => !existingRating.Equals(incomingRating), + createNew: incomingRating => incomingRating); + + CollectionReconciler.Reconcile( + foundArtist.Aliases, + data.Aliases, + existingAlias => existingAlias.Name, + incomingAlias => incomingAlias.Name, + shouldReplace: (existingAlias, incomingAlias) => !existingAlias.Equals(incomingAlias), + createNew: incomingAlias => incomingAlias); + + CollectionReconciler.Reconcile( + foundArtist.Ipis, + data.Ipis, + existingIpi => existingIpi.Value, + incomingIpi => incomingIpi.Value, + shouldReplace: (existingIpi, incomingIpi) => false, + createNew: incomingIpi => incomingIpi); + + CollectionReconciler.Reconcile( + foundArtist.Isnis, + data.Isnis, + existingIsni => existingIsni.Value, + incomingIsni => incomingIsni.Value, + shouldReplace: (existingIsni, incomingIsni) => false, + createNew: incomingIsni => incomingIsni); + // A track is unique within its library by its file system path, so a track that is about to be inserted during this update can never reference a file // that is already registered, nor a file that another track of the same update already references. The check runs before anything is written. List newTrackPaths = [.. GetNewTrackPaths(foundArtist, data)]; @@ -171,19 +219,22 @@ internal sealed class ArtistRepository : IArtistRepository // and a name that is already stored is reused, before the album and track repositories reconcile their own collections. Result> resolveTagsResult = await SharedReferenceResolver.ResolveAsync( _luminaDbContext, - data.Albums.SelectMany(album => album.Tags).Concat(data.Albums.SelectMany(album => album.Tracks.SelectMany(track => track.Tags))), + data.Tags.Concat(data.Albums.SelectMany(album => album.Tags)).Concat(data.Albums.SelectMany(album => album.Tracks.SelectMany(track => track.Tags))), Errors.Metadata.TagNameCannotBeEmpty, cancellationToken).ConfigureAwait(false); if (resolveTagsResult.IsFailure) return resolveTagsResult.Errors; Result> resolveGenresResult = await SharedReferenceResolver.ResolveAsync( _luminaDbContext, - data.Albums.SelectMany(album => album.Genres).Concat(data.Albums.SelectMany(album => album.Tracks.SelectMany(track => track.Genres))), + data.Genres.Concat(data.Albums.SelectMany(album => album.Genres)).Concat(data.Albums.SelectMany(album => album.Tracks.SelectMany(track => track.Genres))), Errors.Metadata.GenreNameCannotBeEmpty, cancellationToken).ConfigureAwait(false); if (resolveGenresResult.IsFailure) return resolveGenresResult.Errors; + data.Tags = [.. SharedReferenceResolver.Normalize(data.Tags, resolveTagsResult.Value)]; + data.Genres = [.. SharedReferenceResolver.Normalize(data.Genres, resolveGenresResult.Value)]; + foreach (AlbumEntity dataAlbum in data.Albums) { dataAlbum.Tags = [.. SharedReferenceResolver.Normalize(dataAlbum.Tags, resolveTagsResult.Value)]; @@ -324,6 +375,8 @@ internal sealed class ArtistRepository : IArtistRepository if (shouldIncludeNavigationProperties) { query = query + .Include(artist => artist.Tags) + .Include(artist => artist.Genres) .Include(artist => artist.Contributors) .Include(artist => artist.Albums) .ThenInclude(album => album.Ratings) @@ -393,6 +446,8 @@ internal sealed class ArtistRepository : IArtistRepository if (shouldIncludeNavigationProperties) { artistsQuery = artistsQuery + .Include(artist => artist.Tags) + .Include(artist => artist.Genres) .Include(artist => artist.Contributors) .Include(artist => artist.Albums) .ThenInclude(album => album.Ratings) @@ -587,4 +642,155 @@ internal sealed class ArtistRepository : IArtistRepository : artistsQuery.OrderBy(artist => artist.Name).ThenBy(artist => artist.Id), }; } + + /// + /// Gets the artist of the library identified by that has the provided . + /// + /// The Id of the library whose artist is retrieved. + /// The name of the artist to retrieve. + /// Cancellation token that can be used to stop the execution. + /// An containing either the with the provided name, or an error. + public async Task> GetByNameAsync(Guid libraryId, string name, CancellationToken cancellationToken) + { + ArtistEntity? artist = await _luminaDbContext.Artists + .FirstOrDefaultAsync(repositoryArtist => repositoryArtist.LibraryId == libraryId && repositoryArtist.Name == name, cancellationToken).ConfigureAwait(false); + return artist; + } + + /// + /// Gets a page of the artists of the media library identified by whose metadata has not been enriched yet, + /// together with their albums and tracks and the collections needed to enrich them, ordered by name, using keyset pagination. + /// + /// The Id of the media library whose artists are retrieved. + /// The name of the last retrieved artist, used for keyset pagination. Pass to get the first page. + /// The maximum number of artists to retrieve. + /// Cancellation token that can be used to stop the execution. + /// An containing either a page of artists needing their metadata enriched, or an error. + public async Task>> GetArtistsNeedingMetadataAsync(Guid libraryId, string? lastName, int pageSize, CancellationToken cancellationToken) + { + return await _luminaDbContext.Artists + .Include(artist => artist.Area) + .Include(artist => artist.BeginArea) + .Include(artist => artist.EndArea) + .Include(artist => artist.Aliases) + .Include(artist => artist.Ipis) + .Include(artist => artist.Isnis) + .Include(artist => artist.Genres) + .Include(artist => artist.Tags) + .Include(artist => artist.Ratings) + .Include(artist => artist.Contributors) + .Include(artist => artist.Albums) + .ThenInclude(album => album.ReleaseTypes) + .Include(artist => artist.Albums) + .ThenInclude(album => album.Genres) + .Include(artist => artist.Albums) + .ThenInclude(album => album.Tags) + .Include(artist => artist.Albums) + .ThenInclude(album => album.Ratings) + .Include(artist => artist.Albums) + .ThenInclude(album => album.Contributors) + .Include(artist => artist.Albums) + .ThenInclude(album => album.Tracks) + .ThenInclude(track => track.Genres) + .Include(artist => artist.Albums) + .ThenInclude(album => album.Tracks) + .ThenInclude(track => track.Tags) + .Include(artist => artist.Albums) + .ThenInclude(album => album.Tracks) + .ThenInclude(track => track.Ratings) + .Include(artist => artist.Albums) + .ThenInclude(album => album.Tracks) + .ThenInclude(track => track.Moods) + .Include(artist => artist.Albums) + .ThenInclude(album => album.Tracks) + .ThenInclude(track => track.Isrcs) + .Include(artist => artist.Albums) + .ThenInclude(album => album.Tracks) + .ThenInclude(track => track.Contributors) + .Include(artist => artist.Albums) + .ThenInclude(album => album.Tracks) + .ThenInclude(track => track.WorkLanguages) + .Include(artist => artist.Albums) + .ThenInclude(album => album.Tracks) + .ThenInclude(track => track.WorkIswcs) + .AsSplitQuery() + .Where(artist => artist.LibraryId == libraryId + && (artist.MetadataStatus != MetadataStatus.Enriched + || artist.Albums.Any(album => album.MetadataStatus != MetadataStatus.Enriched) + || artist.Albums.Any(album => album.Tracks.Any(track => track.MetadataStatus != MetadataStatus.Enriched))) + && (lastName == null || artist.Name.CompareTo(lastName) > 0)) + .OrderBy(artist => artist.Name) + .Take(pageSize) + .ToListAsync(cancellationToken).ConfigureAwait(false); + } + + /// + /// Gets the number of artists of the media library identified by whose metadata has not been enriched yet. + /// + /// The Id of the media library whose artists are counted. + /// Cancellation token that can be used to stop the execution. + /// An containing either the number of artists needing their metadata enriched, or an error. + public async Task> GetArtistsNeedingMetadataCountAsync(Guid libraryId, CancellationToken cancellationToken) + { + return await _luminaDbContext.Artists + .CountAsync(artist => artist.LibraryId == libraryId + && (artist.MetadataStatus != MetadataStatus.Enriched + || artist.Albums.Any(album => album.MetadataStatus != MetadataStatus.Enriched) + || artist.Albums.Any(album => album.Tracks.Any(track => track.MetadataStatus != MetadataStatus.Enriched))), cancellationToken).ConfigureAwait(false); + } + + /// + /// Gets the number of artists of the media library identified by whose artwork has not been resolved yet. + /// + /// The Id of the media library whose artists are counted. + /// Cancellation token that can be used to stop the execution. + /// An containing either the number of artists needing their artwork resolved, or an error. + public async Task> GetArtistsNeedingArtworkCountAsync(Guid libraryId, CancellationToken cancellationToken) + { + return await _luminaDbContext.Artists + .CountAsync(artist => artist.LibraryId == libraryId + && !_luminaDbContext.MusicArtwork.Any(musicArtwork => musicArtwork.OwnerType == MusicArtworkOwnerType.Artist + && musicArtwork.OwnerId == artist.Id + && (musicArtwork.Status == ArtworkStatus.Enriched || musicArtwork.Status == ArtworkStatus.NotAvailable)), cancellationToken).ConfigureAwait(false); + } + + /// + /// Gets a page of the artists of the media library identified by whose artwork has not been resolved yet, + /// together with their albums and tracks, ordered by name, using keyset pagination. + /// + /// The Id of the media library whose artists are retrieved. + /// The name of the last retrieved artist, used for keyset pagination. Pass to get the first page. + /// The maximum number of artists to retrieve. + /// Cancellation token that can be used to stop the execution. + /// An containing either a page of artists needing their artwork resolved, or an error. + public async Task>> GetArtistsNeedingArtworkAsync(Guid libraryId, string? lastName, int pageSize, CancellationToken cancellationToken) + { + return await _luminaDbContext.Artists + .AsNoTracking() + .Include(artist => artist.Albums) + .ThenInclude(album => album.Tracks) + .AsSplitQuery() + .Where(artist => artist.LibraryId == libraryId + && !_luminaDbContext.MusicArtwork.Any(musicArtwork => musicArtwork.OwnerType == MusicArtworkOwnerType.Artist + && musicArtwork.OwnerId == artist.Id + && (musicArtwork.Status == ArtworkStatus.Enriched || musicArtwork.Status == ArtworkStatus.NotAvailable)) + && (lastName == null || artist.Name.CompareTo(lastName) > 0)) + .OrderBy(artist => artist.Name) + .Take(pageSize) + .ToListAsync(cancellationToken).ConfigureAwait(false); + } + + /// + /// Resets the metadata enrichment status of all the artists of the media library identified by . + /// + /// The Id of the media library whose artists are reset. + /// Cancellation token that can be used to stop the execution. + /// An representing either a successful operation, or an error. + public async Task> ResetMetadataStatusForLibraryAsync(Guid libraryId, CancellationToken cancellationToken) + { + await _luminaDbContext.Artists + .Where(artist => artist.LibraryId == libraryId) + .ExecuteUpdateAsync(setters => setters.SetProperty(artist => artist.MetadataStatus, MetadataStatus.Pending), cancellationToken).ConfigureAwait(false); + return Result.Updated; + } } diff --git a/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/MusicLibraryScanItemMetadataRepository.cs b/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/MusicLibraryScanItemMetadataRepository.cs new file mode 100644 index 00000000..f2810e93 --- /dev/null +++ b/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/MusicLibraryScanItemMetadataRepository.cs @@ -0,0 +1,74 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; +using Lumina.Application.Common.DataAccess.Repositories.MusicLibrary; +using Lumina.DataAccess.Core.UoW; +using Lumina.Domain.Common.Primitives; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +#endregion + +namespace Lumina.DataAccess.Core.Repositories.MusicLibrary; + +/// +/// Repository for the music metadata staged during a media library scan. +/// +internal sealed class MusicLibraryScanItemMetadataRepository : IMusicLibraryScanItemMetadataRepository +{ + private readonly LuminaDbContext _luminaDbContext; + + /// + /// Initializes a new instance of the class. + /// + /// Injected Entity Framework DbContext. + public MusicLibraryScanItemMetadataRepository(LuminaDbContext luminaDbContext) + { + _luminaDbContext = luminaDbContext; + } + + /// + /// Adds a range of staged music metadata items. + /// + /// The staged music metadata items to add. + /// Cancellation token that can be used to stop the execution. + /// An representing either a successful operation, or an error. + public Task> InsertRangeAsync(IReadOnlyCollection items, CancellationToken cancellationToken) + { + if (items.Count > 0) + _luminaDbContext.MusicLibraryScanItemMetadata.AddRange(items); + return Task.FromResult>(Result.Created); + } + + /// + /// Gets all the staged music metadata items of the media library scan identified by . + /// + /// The Id of the media library scan whose staged music metadata is retrieved. + /// Cancellation token that can be used to stop the execution. + /// An containing either a collection of , or an error. + public async Task>> GetByScanIdAsync(Guid scanId, CancellationToken cancellationToken) + { + IReadOnlyList items = await _luminaDbContext.MusicLibraryScanItemMetadata + .AsNoTracking() + .Where(musicMetadata => musicMetadata.LibraryScanId == scanId) + .OrderBy(musicMetadata => musicMetadata.Path) + .ToListAsync(cancellationToken).ConfigureAwait(false); + return Result.From(items); + } + + /// + /// Deletes all the staged music metadata items of the media library scan identified by . + /// + /// The Id of the media library scan whose staged music metadata is deleted. + /// Cancellation token that can be used to stop the execution. + /// An representing either a successful operation, or an error. + public async Task> DeleteByScanIdAsync(Guid scanId, CancellationToken cancellationToken) + { + await _luminaDbContext.MusicLibraryScanItemMetadata + .Where(musicMetadata => musicMetadata.LibraryScanId == scanId) + .ExecuteDeleteAsync(cancellationToken).ConfigureAwait(false); + return Result.Deleted; + } +} diff --git a/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/TrackRepository.cs b/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/TrackRepository.cs index de46fe87..4837ccf2 100644 --- a/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/TrackRepository.cs +++ b/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/TrackRepository.cs @@ -8,6 +8,7 @@ using Lumina.DataAccess.Common.Persistence; using Lumina.DataAccess.Core.UoW; using Lumina.Domain.Common.Errors; using Lumina.Domain.Common.Primitives; +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; @@ -175,6 +176,23 @@ internal sealed class TrackRepository : ITrackRepository shouldReplace: (existingIsrc, incomingIsrc) => false, createNew: incomingIsrc => incomingIsrc); + // The languages and the ISWCs of the work are owned value objects whose value is also their identity, so a match means there is nothing to change. + CollectionReconciler.Reconcile( + foundTrack.WorkLanguages, + data.WorkLanguages, + existingWorkLanguage => existingWorkLanguage.LanguageCode, + incomingWorkLanguage => incomingWorkLanguage.LanguageCode, + shouldReplace: (existingWorkLanguage, incomingWorkLanguage) => !existingWorkLanguage.Equals(incomingWorkLanguage), + createNew: incomingWorkLanguage => incomingWorkLanguage); + + CollectionReconciler.Reconcile( + foundTrack.WorkIswcs, + data.WorkIswcs, + existingWorkIswc => existingWorkIswc.Value, + incomingWorkIswc => incomingWorkIswc.Value, + shouldReplace: (existingWorkIswc, incomingWorkIswc) => false, + createNew: incomingWorkIswc => incomingWorkIswc); + return Result.Updated; } @@ -286,4 +304,107 @@ internal sealed class TrackRepository : ITrackRepository NumberOfPages = numberOfPages }; } + + /// + /// Gets the track of the library identified by that is stored at the provided . + /// + /// The Id of the library whose track is retrieved. + /// The file system path of the track to retrieve. + /// Cancellation token that can be used to stop the execution. + /// An containing either the stored at the provided path, or an error. + public async Task> GetByPathAsync(Guid libraryId, string path, CancellationToken cancellationToken) + { + TrackEntity? track = await _luminaDbContext.Tracks + .FirstOrDefaultAsync(repositoryTrack => repositoryTrack.LibraryId == libraryId && repositoryTrack.Path == path, cancellationToken).ConfigureAwait(false); + return track; + } + + /// + /// Deletes the track identified by , together with its owned collections and contributions, by the database cascade. + /// + /// The Id of the track to delete. + /// Cancellation token that can be used to stop the execution. + /// An representing either a successful operation, or an error. + public async Task> DeleteByIdAsync(Guid id, CancellationToken cancellationToken) + { + TrackEntity? track = await _luminaDbContext.Tracks + .FirstOrDefaultAsync(repositoryTrack => repositoryTrack.Id == id, cancellationToken).ConfigureAwait(false); + if (track is null) + return Errors.Music.TrackNotFound; + + _luminaDbContext.Tracks.Remove(track); + return Result.Deleted; + } + + /// + /// Resets the enrichment state of the tracks stored at the provided in the media library identified by + /// , together with their albums and artists. + /// + /// The Id of the media library whose tracks are reset. + /// The file system paths of the tracks whose enrichment state is reset. + /// Cancellation token that can be used to stop the execution. + /// An representing either a successful operation, or an error. + public async Task> ResetEnrichmentStateForPathsAsync(Guid libraryId, IReadOnlyCollection paths, CancellationToken cancellationToken) + { + List pathList = [.. paths]; + if (pathList.Count == 0) + return Result.Updated; + + // The tracks stored at the changed paths are reset, together with the albums and the artists they belong to, because the metadata of the whole release is re-evaluated. + List trackIds = await _luminaDbContext.Tracks + .Where(track => track.LibraryId == libraryId && pathList.Contains(track.Path)) + .Select(track => track.Id) + .ToListAsync(cancellationToken).ConfigureAwait(false); + if (trackIds.Count == 0) + return Result.Updated; + + List albumIds = await _luminaDbContext.Tracks + .Where(track => trackIds.Contains(track.Id)) + .Select(track => track.AlbumId) + .Distinct() + .ToListAsync(cancellationToken).ConfigureAwait(false); + List artistIds = await _luminaDbContext.Albums + .Where(album => albumIds.Contains(album.Id)) + .Select(album => album.ArtistId) + .Distinct() + .ToListAsync(cancellationToken).ConfigureAwait(false); + + await _luminaDbContext.Tracks + .Where(track => trackIds.Contains(track.Id)) + .ExecuteUpdateAsync(setters => setters.SetProperty(track => track.MetadataStatus, MetadataStatus.Pending), cancellationToken).ConfigureAwait(false); + await _luminaDbContext.Albums + .Where(album => albumIds.Contains(album.Id)) + .ExecuteUpdateAsync(setters => setters.SetProperty(album => album.MetadataStatus, MetadataStatus.Pending), cancellationToken).ConfigureAwait(false); + await _luminaDbContext.Artists + .Where(artist => artistIds.Contains(artist.Id)) + .ExecuteUpdateAsync(setters => setters.SetProperty(artist => artist.MetadataStatus, MetadataStatus.Pending), cancellationToken).ConfigureAwait(false); + + return Result.Updated; + } + + /// + /// Gets the number of tracks of the media library identified by whose metadata has not been enriched yet. + /// + /// The Id of the media library whose tracks are counted. + /// Cancellation token that can be used to stop the execution. + /// An containing either the number of tracks needing their metadata enriched, or an error. + public async Task> GetTracksNeedingMetadataCountAsync(Guid libraryId, CancellationToken cancellationToken) + { + return await _luminaDbContext.Tracks + .CountAsync(track => track.LibraryId == libraryId && track.MetadataStatus != MetadataStatus.Enriched, cancellationToken).ConfigureAwait(false); + } + + /// + /// Resets the metadata enrichment status of all the tracks of the media library identified by . + /// + /// The Id of the media library whose tracks are reset. + /// Cancellation token that can be used to stop the execution. + /// An representing either a successful operation, or an error. + public async Task> ResetMetadataStatusForLibraryAsync(Guid libraryId, CancellationToken cancellationToken) + { + await _luminaDbContext.Tracks + .Where(track => track.LibraryId == libraryId) + .ExecuteUpdateAsync(setters => setters.SetProperty(track => track.MetadataStatus, MetadataStatus.Pending), cancellationToken).ConfigureAwait(false); + return Result.Updated; + } } diff --git a/src/Lumina.DataAccess/Core/UoW/LuminaDbContext.cs b/src/Lumina.DataAccess/Core/UoW/LuminaDbContext.cs index f84beb77..fcbe9802 100644 --- a/src/Lumina.DataAccess/Core/UoW/LuminaDbContext.cs +++ b/src/Lumina.DataAccess/Core/UoW/LuminaDbContext.cs @@ -24,6 +24,8 @@ public class LuminaDbContext : DbContext public virtual DbSet Artists { get; set; } = null!; public virtual DbSet Albums { get; set; } = null!; public virtual DbSet Tracks { get; set; } = null!; + public virtual DbSet MusicArtwork { get; set; } = null!; + public virtual DbSet MusicLibraryScanItemMetadata { get; set; } = null!; public virtual DbSet Users { get; set; } = null!; public virtual DbSet UserSettings { get; set; } = null!; public virtual DbSet Libraries { get; set; } = null!; diff --git a/src/Lumina.DataAccess/Core/UoW/UnitOfWork.cs b/src/Lumina.DataAccess/Core/UoW/UnitOfWork.cs index a4064637..fd78d4bf 100644 --- a/src/Lumina.DataAccess/Core/UoW/UnitOfWork.cs +++ b/src/Lumina.DataAccess/Core/UoW/UnitOfWork.cs @@ -46,6 +46,8 @@ public class UnitOfWork : IUnitOfWork, IDisposable private IArtistRepository? _artistRepository; private IAlbumRepository? _albumRepository; private ITrackRepository? _trackRepository; + private IMusicArtworkRepository? _musicArtworkRepository; + private IMusicLibraryScanItemMetadataRepository? _musicLibraryScanItemMetadataRepository; private IMediaContributorRepository? _mediaContributorRepository; private IDirectoryScanFingerprintRepository? _directoryScanFingerprintRepository; private ILibraryRepository? _libraryRepository; @@ -159,6 +161,30 @@ public class UnitOfWork : IUnitOfWork, IDisposable } } + /// + /// Gets the repository for the artwork of the music library items. + /// + public IMusicArtworkRepository MusicArtworkRepository + { + get + { + _musicArtworkRepository ??= new MusicArtworkRepository(_luminaDbContext); + return _musicArtworkRepository; + } + } + + /// + /// Gets the repository for the music metadata staged during a media library scan. + /// + public IMusicLibraryScanItemMetadataRepository MusicLibraryScanItemMetadataRepository + { + get + { + _musicLibraryScanItemMetadataRepository ??= new MusicLibraryScanItemMetadataRepository(_luminaDbContext); + return _musicLibraryScanItemMetadataRepository; + } + } + public IMediaContributorRepository MediaContributorRepository { get diff --git a/src/Lumina.Domain/Common/Errors/Errors.MediaContributor.cs b/src/Lumina.Domain/Common/Errors/Errors.MediaContributor.cs index 87d4bf7b..7c71d685 100644 --- a/src/Lumina.Domain/Common/Errors/Errors.MediaContributor.cs +++ b/src/Lumina.Domain/Common/Errors/Errors.MediaContributor.cs @@ -22,6 +22,7 @@ public static partial class Errors public static Error ContributorsListCannotBeNull => Error.Validation(description: nameof(ContributorsListCannotBeNull)); public static Error MediaContributorIdCannotBeEmpty => Error.Validation(description: nameof(MediaContributorIdCannotBeEmpty)); public static Error MediaContributorNotFound => Error.NotFound(description: nameof(MediaContributorNotFound)); + public static Error MediaContributorAlreadyExists => Error.Conflict(description: nameof(MediaContributorAlreadyExists)); public static Error UnknownMediaContributorRole => Error.Validation(description: nameof(UnknownMediaContributorRole)); } } diff --git a/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/AlbumCatalogNumberEntityFixture.cs b/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/AlbumCatalogNumberEntityFixture.cs new file mode 100644 index 00000000..f6bf044f --- /dev/null +++ b/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/AlbumCatalogNumberEntityFixture.cs @@ -0,0 +1,39 @@ +#region ========================================================================= USING ===================================================================================== +using Bogus; +using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +#endregion + +namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; + +/// +/// Fixture class for the record. +/// +[ExcludeFromCodeCoverage] +public class AlbumCatalogNumberEntityFixture +{ + private readonly Faker _faker = new(); + + /// + /// Creates a random valid . + /// + /// Optional. The catalog number assigned by the label. + /// The created . + public AlbumCatalogNumberEntity Create( + string? catalogNumber = null) + { + return new AlbumCatalogNumberEntity(catalogNumber ?? _faker.Random.String2(_faker.Random.Number(1, 50))); + } + + /// + /// Creates a list of . + /// + /// The number of elements to create. + /// The created list. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/AlbumEntityFixture.cs b/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/AlbumEntityFixture.cs index e7c7b23b..511211c7 100644 --- a/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/AlbumEntityFixture.cs +++ b/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/AlbumEntityFixture.cs @@ -6,6 +6,7 @@ using Lumina.Application.Fixtures.Common.DataAccess.Entities.Common; using Lumina.Application.Fixtures.Common.Setup; using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary; using Lumina.Domain.SharedKernel.Common.Enums.Common; +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; @@ -24,6 +25,8 @@ public class AlbumEntityFixture private readonly TrackEntityFixture _trackEntityFixture = new(); private readonly TagEntityFixture _tagEntityFixture = new(); private readonly GenreEntityFixture _genreEntityFixture = new(); + private readonly AlbumReleaseTypeEntityFixture _albumReleaseTypeEntityFixture = new(); + private readonly AlbumCatalogNumberEntityFixture _albumCatalogNumberEntityFixture = new(); private readonly AlbumContributorEntityFixture _albumContributorEntityFixture = new(); private readonly AudioRatingEntityFixture _audioRatingEntityFixture = new(); @@ -71,10 +74,11 @@ public class AlbumEntityFixture /// Whether the release status should be included, or forced to . /// Whether the total number of discs should be included, or forced to . /// Whether the media format should be included, or forced to . - /// Whether the catalog number should be included, or forced to . + /// Whether the catalog number should be included, or forced to . /// Whether the MusicBrainz release identifier should be included, or forced to . /// Whether the MusicBrainz release group identifier should be included, or forced to . /// Whether the MusicBrainz release artist identifier should be included, or forced to . + /// Optional. The metadata enrichment status of the album. /// The created . public AlbumEntity Create( Guid? id = null, @@ -99,7 +103,7 @@ public class AlbumEntityFixture MusicReleaseStatus? releaseStatus = null, int? totalDiscs = null, MusicMediaFormat? mediaFormat = null, - string? catalogNumber = null, + List? catalogNumbers = null, Guid? musicBrainzReleaseId = null, Guid? musicBrainzReleaseGroupId = null, Guid? musicBrainzReleaseArtistId = null, @@ -118,10 +122,11 @@ public class AlbumEntityFixture bool includeReleaseStatus = true, bool includeTotalDiscs = true, bool includeMediaFormat = true, - bool includeCatalogNumber = true, + bool includeCatalogNumbers = true, bool includeMusicBrainzReleaseId = true, bool includeMusicBrainzReleaseGroupId = true, - bool includeMusicBrainzReleaseArtistId = true) + bool includeMusicBrainzReleaseArtistId = true, + MetadataStatus? metadataStatus = null) { Guid resolvedId = id ?? Guid.NewGuid(); Guid resolvedArtistId = artistId ?? Guid.NewGuid(); @@ -140,6 +145,7 @@ public class AlbumEntityFixture Id = resolvedId, ArtistId = resolvedArtistId, LibraryId = resolvedLibraryId, + MetadataStatus = metadataStatus ?? MetadataStatus.Pending, Title = default!, CreatedOnUtc = default, CreatedBy = default, @@ -147,6 +153,7 @@ public class AlbumEntityFixture }) .RuleFor(x => x.Title, f => title ?? f.Random.String2(f.Random.Number(1, 255))) .RuleFor(x => x.OriginalTitle, f => includeOriginalTitle ? (originalTitle ?? f.Random.String2(f.Random.Number(1, 255))) : null) + .RuleFor(x => x.ReleaseTitle, f => f.Random.String2(f.Random.Number(1, 255))) .RuleFor(x => x.Description, f => includeDescription ? (description ?? f.Random.String2(f.Random.Number(1, 2000))) : null) .RuleFor(x => x.OriginalReleaseDate, includeOriginalReleaseDate ? resolvedOriginalReleaseDate : (DateOnly?)null) .RuleFor(x => x.OriginalReleaseYear, includeOriginalReleaseYear ? resolvedOriginalReleaseYear : (int?)null) @@ -160,13 +167,13 @@ public class AlbumEntityFixture .RuleFor(x => x.OriginalLanguageCode, f => includeOriginalLanguage ? (originalLanguageCode ?? f.Random.String2(2)) : null) .RuleFor(x => x.OriginalLanguageName, f => includeOriginalLanguage ? (originalLanguageName ?? f.Random.String2(f.Random.Number(1, 50))) : null) .RuleFor(x => x.OriginalLanguageNativeName, f => includeOriginalLanguage ? (originalLanguageNativeName ?? f.Random.String2(f.Random.Number(1, 50))) : null) - .RuleFor(x => x.ReleaseType, f => includeReleaseType ? (releaseType ?? f.PickRandom()) : (MusicReleaseType?)null) + .RuleFor(x => x.ReleaseTypes, f => includeReleaseType ? [_albumReleaseTypeEntityFixture.Create(releaseType: releaseType)] : []) .RuleFor(x => x.ReleaseStatus, f => includeReleaseStatus ? (releaseStatus ?? f.PickRandom()) : (MusicReleaseStatus?)null) .RuleFor(x => x.TotalDiscs, includeTotalDiscs ? (totalDiscs ?? Random.Shared.Next(1, 3)) : (int?)null) .RuleFor(x => x.TotalTracks, resolvedTracks.Count) .RuleFor(x => x.MediaFormat, f => includeMediaFormat ? (mediaFormat ?? f.PickRandom()) : (MusicMediaFormat?)null) .RuleFor(x => x.Barcode, f => includeBarcode ? (barcode ?? f.Random.String2(f.Random.Number(12, 13), "0123456789")) : null) - .RuleFor(x => x.CatalogNumber, f => includeCatalogNumber ? (catalogNumber ?? f.Random.String2(f.Random.Number(1, 50))) : null) + .RuleFor(x => x.CatalogNumbers, f => includeCatalogNumbers ? [.. (catalogNumbers ?? [f.Random.String2(f.Random.Number(1, 50))]).Select(catalogNumber => _albumCatalogNumberEntityFixture.Create(catalogNumber: catalogNumber))] : []) .RuleFor(x => x.MusicBrainzReleaseId, f => includeMusicBrainzReleaseId ? (musicBrainzReleaseId ?? f.Random.Guid()) : (Guid?)null) .RuleFor(x => x.MusicBrainzReleaseGroupId, f => includeMusicBrainzReleaseGroupId ? (musicBrainzReleaseGroupId ?? f.Random.Guid()) : (Guid?)null) .RuleFor(x => x.MusicBrainzReleaseArtistId, f => includeMusicBrainzReleaseArtistId ? (musicBrainzReleaseArtistId ?? f.Random.Guid()) : (Guid?)null) diff --git a/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/AlbumReleaseTypeEntityFixture.cs b/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/AlbumReleaseTypeEntityFixture.cs new file mode 100644 index 00000000..38412d90 --- /dev/null +++ b/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/AlbumReleaseTypeEntityFixture.cs @@ -0,0 +1,40 @@ +#region ========================================================================= USING ===================================================================================== +using Bogus; +using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; +using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +#endregion + +namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; + +/// +/// Fixture class for the record. +/// +[ExcludeFromCodeCoverage] +public class AlbumReleaseTypeEntityFixture +{ + private readonly Faker _faker = new(); + + /// + /// Creates a random valid . + /// + /// Optional. The type of the release. + /// The created . + public AlbumReleaseTypeEntity Create( + MusicReleaseType? releaseType = null) + { + return new AlbumReleaseTypeEntity(releaseType ?? _faker.PickRandom()); + } + + /// + /// Creates a list of . + /// + /// The number of elements to create. + /// The created list. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/ArtistAliasEntityFixture.cs b/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/ArtistAliasEntityFixture.cs new file mode 100644 index 00000000..f891e2ea --- /dev/null +++ b/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/ArtistAliasEntityFixture.cs @@ -0,0 +1,78 @@ +#region ========================================================================= USING ===================================================================================== +using Bogus; +using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +#endregion + +namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; + +/// +/// Fixture class for the record. +/// +[ExcludeFromCodeCoverage] +public class ArtistAliasEntityFixture +{ + private const int MINIMUM_ALIAS_YEAR = 1900; + private const int MAXIMUM_ALIAS_YEAR = 2026; + + private readonly Faker _faker = new(); + + /// + /// Creates a random valid . + /// + /// Optional. The name of the alias. + /// Optional. The sort name of the alias. + /// Optional. The type of the alias. + /// Optional. The locale the alias is used in. + /// Optional. Whether this is the primary alias of the artist. + /// Optional. The date the alias began being used. + /// Optional. The date the alias stopped being used. + /// Optional. Whether the alias is no longer used. + /// Whether the sort name should be included, or forced to . + /// Whether the type should be included, or forced to . + /// Whether the locale should be included, or forced to . + /// Whether the begin date should be included, or forced to . + /// Whether the end date should be included, or forced to . + /// The created . + public ArtistAliasEntity Create( + string? name = null, + string? sortName = null, + string? type = null, + string? locale = null, + bool? isPrimary = null, + DateOnly? beginDate = null, + DateOnly? endDate = null, + bool? isEnded = null, + bool includeSortName = true, + bool includeType = true, + bool includeLocale = true, + bool includeBeginDate = true, + bool includeEndDate = true) + { + int beginYear = Random.Shared.Next(MINIMUM_ALIAS_YEAR, MAXIMUM_ALIAS_YEAR); + int endYear = Random.Shared.Next(beginYear, Math.Max(beginYear + 1, MAXIMUM_ALIAS_YEAR)); + + return new ArtistAliasEntity( + name ?? _faker.Name.FullName(), + includeSortName ? (sortName ?? _faker.Name.FullName()) : null, + includeType ? (type ?? _faker.Random.ArrayElement(["Artist name", "Search hint"])) : null, + includeLocale ? (locale ?? _faker.Random.String2(2)) : null, + isPrimary ?? _faker.Random.Bool(), + includeBeginDate ? (beginDate ?? new DateOnly(beginYear, 1, 1)) : null, + includeEndDate ? (endDate ?? new DateOnly(endYear, 1, 1)) : null, + isEnded ?? _faker.Random.Bool()); + } + + /// + /// Creates a list of . + /// + /// The number of elements to create. + /// The created list. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/ArtistIpiEntityFixture.cs b/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/ArtistIpiEntityFixture.cs new file mode 100644 index 00000000..20bfb519 --- /dev/null +++ b/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/ArtistIpiEntityFixture.cs @@ -0,0 +1,39 @@ +#region ========================================================================= USING ===================================================================================== +using Bogus; +using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +#endregion + +namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; + +/// +/// Fixture class for the record. +/// +[ExcludeFromCodeCoverage] +public class ArtistIpiEntityFixture +{ + private readonly Faker _faker = new(); + + /// + /// Creates a random valid . + /// + /// Optional. The value of the IPI code. + /// The created . + public ArtistIpiEntity Create( + string? value = null) + { + return new ArtistIpiEntity(value ?? _faker.Random.String2(_faker.Random.Number(1, 20), "0123456789")); + } + + /// + /// Creates a list of . + /// + /// The number of elements to create. + /// The created list. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/ArtistIsniEntityFixture.cs b/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/ArtistIsniEntityFixture.cs new file mode 100644 index 00000000..7cbf2fcb --- /dev/null +++ b/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/ArtistIsniEntityFixture.cs @@ -0,0 +1,39 @@ +#region ========================================================================= USING ===================================================================================== +using Bogus; +using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +#endregion + +namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; + +/// +/// Fixture class for the record. +/// +[ExcludeFromCodeCoverage] +public class ArtistIsniEntityFixture +{ + private readonly Faker _faker = new(); + + /// + /// Creates a random valid . + /// + /// Optional. The value of the ISNI code. + /// The created . + public ArtistIsniEntity Create( + string? value = null) + { + return new ArtistIsniEntity(value ?? _faker.Random.String2(_faker.Random.Number(1, 20), "0123456789X")); + } + + /// + /// Creates a list of . + /// + /// The number of elements to create. + /// The created list. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/MusicAreaEntityFixture.cs b/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/MusicAreaEntityFixture.cs new file mode 100644 index 00000000..8389106e --- /dev/null +++ b/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/MusicAreaEntityFixture.cs @@ -0,0 +1,64 @@ +#region ========================================================================= USING ===================================================================================== +using Bogus; +using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +#endregion + +namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; + +/// +/// Fixture class for the record. +/// +[ExcludeFromCodeCoverage] +public class MusicAreaEntityFixture +{ + private readonly Faker _faker = new(); + + /// + /// Creates a random valid . + /// + /// Optional. The MusicBrainz identifier of the area. + /// Optional. The name of the area. + /// Optional. The sort name of the area. + /// Optional. The disambiguation comment of the area. + /// Optional. The MusicBrainz type of the area. + /// Optional. The ISO 3166 code of the area. + /// Whether the sort name should be included, or forced to . + /// Whether the disambiguation should be included, or forced to . + /// Whether the type should be included, or forced to . + /// Whether the ISO 3166 code should be included, or forced to . + /// The created . + public MusicAreaEntity Create( + Guid? musicBrainzAreaId = null, + string? name = null, + string? sortName = null, + string? disambiguation = null, + string? type = null, + string? iso3166Code = null, + bool includeSortName = true, + bool includeDisambiguation = true, + bool includeType = true, + bool includeIso3166Code = true) + { + return new MusicAreaEntity( + musicBrainzAreaId ?? _faker.Random.Guid(), + name ?? _faker.Address.Country(), + includeSortName ? (sortName ?? _faker.Address.Country()) : null, + includeDisambiguation ? (disambiguation ?? _faker.Lorem.Sentence()) : null, + includeType ? (type ?? _faker.Random.ArrayElement(["Country", "City", "Area"])) : null, + includeIso3166Code ? (iso3166Code ?? _faker.Address.CountryCode()) : null); + } + + /// + /// Creates a list of . + /// + /// The number of elements to create. + /// The created list. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/MusicLibraryScanItemMetadataEntityFixture.cs b/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/MusicLibraryScanItemMetadataEntityFixture.cs new file mode 100644 index 00000000..f5baffc3 --- /dev/null +++ b/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/MusicLibraryScanItemMetadataEntityFixture.cs @@ -0,0 +1,102 @@ +#region ========================================================================= USING ===================================================================================== +using Bogus; +using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; +using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary; +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +#endregion + +namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; + +/// +/// Fixture class for the class. +/// +[ExcludeFromCodeCoverage] +public class MusicLibraryScanItemMetadataEntityFixture +{ + private readonly Faker _faker = new(); + + /// + /// Creates a random valid . + /// + /// Optional. The Id of the staged metadata. + /// Optional. The Id of the media library scan the staged metadata belongs to. + /// Optional. The Id of the media library the staged metadata belongs to. + /// Optional. The file system path of the music file. + /// Optional. The name of the artist. + /// Optional. The name of the release. + /// Optional. The title of the track. + /// Optional. The number of the track on its disc. + /// Optional. The number of the disc the track belongs to. + /// Optional. The MusicBrainz identifier of the artist. + /// Optional. The MusicBrainz identifier of the release artist. + /// Optional. The MusicBrainz identifier of the release group. + /// Optional. The MusicBrainz identifier of the release. + /// Optional. The MusicBrainz identifier of the recording. + /// Optional. The MusicBrainz identifier of the track. + /// Optional. The MusicBrainz identifier of the work. + /// Optional. The title of the work. + /// Whether the MusicBrainz identifiers and the work title should be included, or forced to . + /// The created . + public MusicLibraryScanItemMetadataEntity Create( + Guid? id = null, + Guid? libraryScanId = null, + Guid? libraryId = null, + string? path = null, + string? artistName = null, + string? releaseName = null, + string? trackTitle = null, + int? trackNumber = null, + int? discNumber = null, + Guid? musicBrainzArtistId = null, + Guid? musicBrainzReleaseArtistId = null, + Guid? musicBrainzReleaseGroupId = null, + Guid? musicBrainzReleaseId = null, + Guid? musicBrainzRecordingId = null, + Guid? musicBrainzTrackId = null, + Guid? musicBrainzWorkId = null, + string? workTitle = null, + bool includeMusicBrainzTags = true) + { + return new MusicLibraryScanItemMetadataEntity + { + Id = id ?? Guid.NewGuid(), + LibraryScanId = libraryScanId ?? Guid.NewGuid(), + LibraryId = libraryId ?? Guid.NewGuid(), + Path = path ?? _faker.System.FilePath(), + ArtistName = artistName ?? _faker.Name.FullName(), + ReleaseType = _faker.PickRandom(), + ReleaseYear = Random.Shared.Next(1900, 2026), + ReleaseName = releaseName ?? _faker.Music.Genre(), + TrackTitle = trackTitle ?? _faker.Music.Genre(), + TrackNumber = trackNumber ?? _faker.Random.Int(1, 20), + DiscNumber = discNumber ?? _faker.Random.Int(1, 3), + DurationInSeconds = Random.Shared.Next(60, 7200), + SampleRate = _faker.PickRandom(44100, 48000, 96000), + Channels = _faker.PickRandom(1, 2, 6), + BitDepth = Random.Shared.Next(8, 32), + AudioCodec = _faker.PickRandom("FLAC", "MP3", "AAC", "ALAC"), + Bitrate = Random.Shared.Next(96, 1411), + MusicBrainzArtistId = includeMusicBrainzTags ? musicBrainzArtistId ?? Guid.NewGuid() : null, + MusicBrainzReleaseArtistId = includeMusicBrainzTags ? musicBrainzReleaseArtistId ?? Guid.NewGuid() : null, + MusicBrainzReleaseGroupId = includeMusicBrainzTags ? musicBrainzReleaseGroupId ?? Guid.NewGuid() : null, + MusicBrainzReleaseId = includeMusicBrainzTags ? musicBrainzReleaseId ?? Guid.NewGuid() : null, + MusicBrainzRecordingId = includeMusicBrainzTags ? musicBrainzRecordingId ?? Guid.NewGuid() : null, + MusicBrainzTrackId = includeMusicBrainzTags ? musicBrainzTrackId ?? Guid.NewGuid() : null, + MusicBrainzWorkId = includeMusicBrainzTags ? musicBrainzWorkId ?? Guid.NewGuid() : null, + WorkTitle = includeMusicBrainzTags ? workTitle ?? _faker.Music.Genre() : null + }; + } + + /// + /// Creates a list of . + /// + /// The number of elements to create. + /// The created list. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/TrackEntityFixture.cs b/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/TrackEntityFixture.cs index 3b039dc2..2fda1e88 100644 --- a/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/TrackEntityFixture.cs +++ b/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/TrackEntityFixture.cs @@ -6,6 +6,7 @@ using Lumina.Application.Fixtures.Common.DataAccess.Entities.Common; using Lumina.Application.Fixtures.Common.Setup; using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary; using Lumina.Domain.SharedKernel.Common.Enums.Common; +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; @@ -46,6 +47,7 @@ public class TrackEntityFixture /// Whether the original release year should be included, or forced to . /// Whether the re-release date should be included, or forced to . /// Whether the re-release year should be included, or forced to . + /// Optional. The metadata enrichment status of the track. /// The created . public TrackEntity Create( Guid? id = null, @@ -62,7 +64,8 @@ public class TrackEntityFixture bool includeOriginalReleaseDate = true, bool includeOriginalReleaseYear = true, bool includeReReleaseDate = true, - bool includeReReleaseYear = true) + bool includeReReleaseYear = true, + MetadataStatus? metadataStatus = null) { Guid resolvedId = id ?? Guid.NewGuid(); Guid resolvedAlbumId = albumId ?? Guid.NewGuid(); @@ -80,6 +83,7 @@ public class TrackEntityFixture Id = resolvedId, AlbumId = resolvedAlbumId, LibraryId = resolvedLibraryId, + MetadataStatus = metadataStatus ?? MetadataStatus.Pending, Path = default!, Title = default!, CreatedOnUtc = default, @@ -113,7 +117,9 @@ public class TrackEntityFixture .RuleFor(x => x.Script, f => f.Random.String2(f.Random.Number(1, 50))) .RuleFor(x => x.Key, f => f.PickRandom()) .RuleFor(x => x.Bpm, Random.Shared.Next(40, 240)) - .RuleFor(x => x.Work, f => f.Music.Genre()) + .RuleFor(x => x.IsVideo, f => f.Random.Bool()) + .RuleFor(x => x.WorkTitle, f => f.Music.Genre()) + .RuleFor(x => x.WorkType, f => f.Music.Genre()) .RuleFor(x => x.MusicBrainzRecordingId, f => f.Random.Guid()) .RuleFor(x => x.MusicBrainzTrackId, f => f.Random.Guid()) .RuleFor(x => x.MusicBrainzWorkId, f => f.Random.Guid()) diff --git a/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/TrackWorkIswcEntityFixture.cs b/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/TrackWorkIswcEntityFixture.cs new file mode 100644 index 00000000..a69c59d9 --- /dev/null +++ b/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/TrackWorkIswcEntityFixture.cs @@ -0,0 +1,39 @@ +#region ========================================================================= USING ===================================================================================== +using Bogus; +using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +#endregion + +namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; + +/// +/// Fixture class for the record. +/// +[ExcludeFromCodeCoverage] +public class TrackWorkIswcEntityFixture +{ + private readonly Faker _faker = new(); + + /// + /// Creates a random valid . + /// + /// Optional. The value of the ISWC. + /// The created . + public TrackWorkIswcEntity Create( + string? value = null) + { + return new TrackWorkIswcEntity(value ?? $"T{_faker.Random.AlphaNumeric(10)}"); + } + + /// + /// Creates a list of . + /// + /// The number of elements to create. + /// The created list. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/TrackWorkLanguageEntityFixture.cs b/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/TrackWorkLanguageEntityFixture.cs new file mode 100644 index 00000000..607df8e6 --- /dev/null +++ b/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/TrackWorkLanguageEntityFixture.cs @@ -0,0 +1,48 @@ +#region ========================================================================= USING ===================================================================================== +using Bogus; +using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +#endregion + +namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; + +/// +/// Fixture class for the record. +/// +[ExcludeFromCodeCoverage] +public class TrackWorkLanguageEntityFixture +{ + private readonly Faker _faker = new(); + + /// + /// Creates a random valid . + /// + /// Optional. The ISO 639-1 two-letter language code. + /// Optional. The full name of the language in English. + /// Optional. The native name of the language. + /// Whether the native name should be included, or forced to . + /// The created . + public TrackWorkLanguageEntity Create( + string? languageCode = null, + string? languageName = null, + string? nativeName = null, + bool includeNativeName = true) + { + return new TrackWorkLanguageEntity( + languageCode ?? _faker.PickRandom("en", "fr", "de", "es", "it", "ja", "ko", "zh", "pt", "ru"), + languageName ?? _faker.Lorem.Word(), + includeNativeName ? (nativeName ?? _faker.Lorem.Word()) : null); + } + + /// + /// Creates a list of . + /// + /// The number of elements to create. + /// The created list. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/WrittenContentLibrary/BookLibrary/BookEntityFixture.cs b/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/WrittenContentLibrary/BookLibrary/BookEntityFixture.cs index c8edfd88..2fa6e5b2 100644 --- a/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/WrittenContentLibrary/BookLibrary/BookEntityFixture.cs +++ b/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/WrittenContentLibrary/BookLibrary/BookEntityFixture.cs @@ -1,8 +1,9 @@ #region ========================================================================= USING ===================================================================================== using Bogus; -using Lumina.Application.Common.DataAccess.Entities.Common; using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary; -using Lumina.Application.Fixtures.Common.Setup;using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary; +using Lumina.Application.Fixtures.Common.DataAccess.Entities.Common; +using Lumina.Application.Fixtures.Common.Setup; +using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary; using Lumina.Domain.SharedKernel.Common.Enums.Common; using System; using System.Collections.Generic; @@ -19,6 +20,10 @@ namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Wr public class BookEntityFixture { private readonly Faker _faker = new(); + private readonly TagEntityFixture _tagEntityFixture = new(); + private readonly GenreEntityFixture _genreEntityFixture = new(); + private readonly IsbnEntityFixture _isbnEntityFixture = new(); + private readonly BookRatingEntityFixture _bookRatingEntityFixture = new(); /// /// Creates a random valid . @@ -60,8 +65,8 @@ public class BookEntityFixture .RuleFor(x => x.OriginalLanguageCode, f => f.Random.String2(2)) .RuleFor(x => x.OriginalLanguageName, f => f.Random.String2(f.Random.Number(1, 50))) .RuleFor(x => x.OriginalLanguageNativeName, f => f.Random.String2(f.Random.Number(1, 50))) - .RuleFor(x => x.Tags, f => includeMetadata ? [.. CreateTags(f.Random.Number(1, 5))] : []) - .RuleFor(x => x.Genres, f => includeMetadata ? [.. CreateGenres(f.Random.Number(1, 5))] : []) + .RuleFor(x => x.Tags, f => includeMetadata ? [.. _tagEntityFixture.CreateMany(f.Random.Number(1, 5))] : []) + .RuleFor(x => x.Genres, f => includeMetadata ? [.. _genreEntityFixture.CreateMany(f.Random.Number(1, 5))] : []) .RuleFor(x => x.Publisher, f => f.Random.String2(f.Random.Number(1, 100))) .RuleFor(x => x.PageCount, Random.Shared.Next(100, 300)) .RuleFor(x => x.Format, f => f.PickRandom()) @@ -76,8 +81,8 @@ public class BookEntityFixture .RuleFor(x => x.GoogleBooksId, CreateGoogleBooksId) .RuleFor(x => x.BarnesAndNobleId, f => f.Random.String2(10, "0123456789")) .RuleFor(x => x.AppleBooksId, f => $"id{f.Random.Number(1, 999999)}") - .RuleFor(x => x.ISBNs, f => includeMetadata ? CreateIsbns(f.Random.Number(1, 5)) : []) - .RuleFor(x => x.Ratings, f => includeMetadata ? CreateBookRatings(f.Random.Number(1, 5)) : []) + .RuleFor(x => x.ISBNs, f => includeMetadata ? _isbnEntityFixture.CreateMany(f.Random.Number(1, 5)) : []) + .RuleFor(x => x.Ratings, f => includeMetadata ? _bookRatingEntityFixture.CreateMany(f.Random.Number(1, 5)) : []) .RuleFor(x => x.CreatedOnUtc, f => f.Date.Past()) .RuleFor(x => x.UpdatedOnUtc, f => f.Date.Recent()) .Generate(); @@ -93,30 +98,6 @@ public class BookEntityFixture return [.. Enumerable.Range(0, count).Select(_ => Create())]; } - /// - /// Creates a list of tag entities with random data. - /// - /// The number of tags to create. - /// A list of randomly generated tag entities. - private static List CreateTags(int count) - { - return new Faker() - .CustomInstantiator(f => new TagEntity(f.Random.String2(f.Random.Number(1, 50)))) - .Generate(count); - } - - /// - /// Creates a list of genre entities with random data. - /// - /// The number of genres to create. - /// A list of randomly generated genre entities. - private static List CreateGenres(int count) - { - return new Faker() - .CustomInstantiator(f => new GenreEntity(f.Random.String2(f.Random.Number(1, 50)))) - .Generate(count); - } - /// /// Creates a valid Library of Congress Control Number (LCCN). /// @@ -172,73 +153,4 @@ public class BookEntityFixture const string VALID_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; return new string([.. Enumerable.Repeat(VALID_CHARS, 12).Select(s => s[f.Random.Number(VALID_CHARS.Length - 1)])]); } - - /// - /// Creates a list of ISBN entities with random data. - /// - /// The number of ISBNs to create. - /// A list of randomly generated ISBN entities. - private static List CreateIsbns(int count) - { - return new Faker() - .CustomInstantiator(f => - { - string isbnValue = CreateIsbn(f); - return new IsbnEntity(isbnValue, isbnValue.Length > 13 ? IsbnFormat.Isbn13 : IsbnFormat.Isbn10); - }) - .Generate(count); - } - - /// - /// Creates a valid ISBN (International Standard Book Number). - /// - /// The Faker instance used for generating random data. - /// A properly formatted ISBN-10 or ISBN-13 string with valid checksum. - private static string CreateIsbn(Faker f) - { - bool isIsbn13 = f.Random.Bool(); - if (isIsbn13) - { - string prefix = f.Random.Bool() ? "978" : "979"; - string group = f.Random.Number(0, 99999).ToString().PadLeft(5, '0'); - string publisher = f.Random.Number(0, 999999).ToString().PadLeft(6, '0'); - string title = f.Random.Number(0, 99).ToString().PadLeft(2, '0'); - string isbn = $"{prefix}{group[..1]}{publisher}{title}"; - int sum = 0; - for (int i = 0; i < 12; i++) - sum += (i % 2 == 0 ? 1 : 3) * int.Parse(isbn[i].ToString()); - int checkDigit = (10 - (sum % 10)) % 10; - return $"{prefix}-{group[..1]}-{publisher}-{title}-{checkDigit}"; - } - else - { - int[] digits = new int[9]; - for (int i = 0; i < 9; i++) - digits[i] = f.Random.Number(0, 9); - int sum = 0; - for (int i = 0; i < 9; i++) - sum += (10 - i) * digits[i]; - int checkDigit = (11 - (sum % 11)) % 11; - string checkChar = checkDigit == 10 ? "X" : checkDigit.ToString(); - return $"{digits[0]}-{digits[1]}{digits[2]}-{digits[3]}{digits[4]}{digits[5]}{digits[6]}{digits[7]}{digits[8]}-{checkChar}"; - } - } - - /// - /// Creates a list of book rating entities with random data. - /// - /// The number of ratings to create. - /// A list of randomly generated book rating entities. - private static List CreateBookRatings(int count) - { - return new Faker() - .CustomInstantiator(f => new BookRatingEntity( - f.Random.Decimal(1, 5), - 5, - f.PickRandom(), - f.Random.Number(1, 1000) - )) - .Generate(count); - } - } diff --git a/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/WrittenContentLibrary/BookLibrary/IsbnEntityFixture.cs b/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/WrittenContentLibrary/BookLibrary/IsbnEntityFixture.cs index 0ad25a7d..729cfa40 100644 --- a/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/WrittenContentLibrary/BookLibrary/IsbnEntityFixture.cs +++ b/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/MediaLibrary/WrittenContentLibrary/BookLibrary/IsbnEntityFixture.cs @@ -18,20 +18,22 @@ public class IsbnEntityFixture private readonly Faker _faker = new(); /// - /// Creates a random valid . + /// Creates a random valid , with a value that satisfies the ISBN checksum and a format that matches it. /// /// Optional. The ISBN value. /// Optional. The format of the ISBN. /// Whether the value should be included, or forced to . + /// Whether the format should be included, or forced to . /// The created . public IsbnEntity Create( - string? value = null, - IsbnFormat? format = null, - bool includeValue = true) + string? value = null, + IsbnFormat? format = null, + bool includeValue = true, + bool includeFormat = true) { - return new IsbnEntity( - includeValue ? value ?? _faker.Random.String2(13, "0123456789") : null, - format); + string? resolvedValue = includeValue ? value ?? CreateValidIsbn13() : null; + IsbnFormat? resolvedFormat = includeFormat ? format ?? InferFormat(resolvedValue) : null; + return new IsbnEntity(resolvedValue, resolvedFormat); } /// @@ -43,4 +45,33 @@ public class IsbnEntityFixture { return [.. Enumerable.Range(0, count).Select(_ => Create())]; } + + /// + /// Infers the format of an ISBN from the number of digits of its value. + /// + /// The ISBN value whose format is inferred. + /// The inferred ISBN format. + private static IsbnFormat InferFormat(string? value) + { + if (string.IsNullOrWhiteSpace(value)) + return IsbnFormat.Isbn13; + + int digitCount = value.Count(char.IsLetterOrDigit); + return digitCount is 10 ? IsbnFormat.Isbn10 : IsbnFormat.Isbn13; + } + + /// + /// Generates a random ISBN-13 value with a valid check digit. + /// + /// A valid ISBN-13 value of 13 digits. + private string CreateValidIsbn13() + { + string prefix = _faker.Random.Bool() ? "978" : "979"; + string firstTwelveDigits = prefix + _faker.Random.String2(9, "0123456789"); + int sum = 0; + for (int index = 0; index < 12; index++) + sum += index % 2 == 0 ? firstTwelveDigits[index] - '0' : 3 * (firstTwelveDigits[index] - '0'); + int checkDigit = (10 - (sum % 10)) % 10; + return firstTwelveDigits + checkDigit; + } } diff --git a/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/Repositories/MediaContributors/MediaContributorRepositoryTests.cs b/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/Repositories/MediaContributors/MediaContributorRepositoryTests.cs new file mode 100644 index 00000000..9571ecae --- /dev/null +++ b/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/Repositories/MediaContributors/MediaContributorRepositoryTests.cs @@ -0,0 +1,49 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Application.Common.DataAccess.Entities.MediaContributors; +using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaContributors; +using Lumina.DataAccess.Core.Repositories.MediaContributors; +using Lumina.DataAccess.Core.UoW; +using Lumina.Domain.Common.Errors; +using Lumina.Domain.Common.Primitives; +using Microsoft.Data.Sqlite; +using Microsoft.EntityFrameworkCore; +using System; +using System.Diagnostics.CodeAnalysis; +using System.Threading; +using System.Threading.Tasks; +#endregion + +namespace Lumina.DataAccess.IntegrationTests.Core.Repositories.MediaContributors; + +/// +/// Contains integration tests for the class, exercising it against a real SQLite database. +/// +[ExcludeFromCodeCoverage] +public class MediaContributorRepositoryTests +{ + private readonly MediaContributorEntityFixture _mediaContributorEntityFixture = new(); + + [Fact] + public async Task InsertAsync_WhenContributorWithSameDisplayNameInDifferentCaseExists_ShouldReturnError() + { + // Arrange + using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-mediacontributorrepo-{Guid.NewGuid()};Mode=Memory;Cache=Shared"); + anchorConnection.Open(); + using LuminaDbContext context = new(new DbContextOptionsBuilder().UseSqlite(anchorConnection.ConnectionString).Options); + context.Database.EnsureCreated(); + MediaContributorRepository sut = new(context); + + MediaContributorEntity existingContributor = _mediaContributorEntityFixture.Create(displayName: "Stephen King"); + context.MediaContributors.Add(existingContributor); + await context.SaveChangesAsync(); + context.ChangeTracker.Clear(); + + // Act + // The comparison is case-insensitive, matching the unique index on the display name. + Result result = await sut.InsertAsync(_mediaContributorEntityFixture.Create(displayName: "stephen king"), CancellationToken.None); + + // Assert + Assert.True(result.IsFailure); + Assert.Equal(Errors.MediaContributor.MediaContributorAlreadyExists, result.FirstError); + } +} diff --git a/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/UoW/LuminaDbContextTests.cs b/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/UoW/LuminaDbContextTests.cs index b46416e8..7a2e5df1 100644 --- a/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/UoW/LuminaDbContextTests.cs +++ b/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/UoW/LuminaDbContextTests.cs @@ -1,4 +1,5 @@ #region ========================================================================= USING ===================================================================================== +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary; using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary; using Lumina.DataAccess.Core.UoW; @@ -47,7 +48,7 @@ public class LuminaDbContextTests : IDisposable // Assert // The count assertion fails when a table is added or removed, reminding to update the assertions below. - Assert.Equal(46, tableNames.Length); + Assert.Equal(62, tableNames.Length); Assert.Contains("Books", tableNames); Assert.Contains("Users", tableNames); Assert.Contains("UserSettings", tableNames); @@ -69,6 +70,7 @@ public class LuminaDbContextTests : IDisposable Assert.Contains("Tags", tableNames); Assert.Contains("Genres", tableNames); Assert.Contains("LibraryContentLocations", tableNames); + Assert.Contains("LibraryPathTemplateParts", tableNames); Assert.Contains("BookTags", tableNames); Assert.Contains("BookGenres", tableNames); Assert.Contains("BookRatings", tableNames); @@ -81,19 +83,31 @@ public class LuminaDbContextTests : IDisposable Assert.Contains("ScheduledJobExecutions", tableNames); Assert.Contains("SchedulerDisplayPreferences", tableNames); Assert.Contains("Artists", tableNames); + Assert.Contains("ArtistAliases", tableNames); + Assert.Contains("ArtistIpis", tableNames); + Assert.Contains("ArtistIsnis", tableNames); + Assert.Contains("ArtistTags", tableNames); + Assert.Contains("ArtistGenres", tableNames); + Assert.Contains("ArtistRatings", tableNames); Assert.Contains("Albums", tableNames); - Assert.Contains("Tracks", tableNames); - Assert.Contains("ArtistContributors", tableNames); - Assert.Contains("AlbumContributors", tableNames); + Assert.Contains("AlbumReleaseTypes", tableNames); + Assert.Contains("AlbumCatalogNumbers", tableNames); Assert.Contains("AlbumGenres", tableNames); Assert.Contains("AlbumRatings", tableNames); Assert.Contains("AlbumTags", tableNames); + Assert.Contains("Tracks", tableNames); Assert.Contains("TrackContributors", tableNames); Assert.Contains("TrackGenres", tableNames); Assert.Contains("TrackIsrcs", tableNames); Assert.Contains("TrackMoods", tableNames); Assert.Contains("TrackRatings", tableNames); Assert.Contains("TrackTags", tableNames); + Assert.Contains("TrackWorkLanguages", tableNames); + Assert.Contains("TrackWorkIswcs", tableNames); + Assert.Contains("ArtistContributors", tableNames); + Assert.Contains("AlbumContributors", tableNames); + Assert.Contains("MusicArtwork", tableNames); + Assert.Contains("MusicLibraryScanItemMetadata", tableNames); } [Fact] diff --git a/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/Configuration/AlbumConfigurationTests.cs b/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/Configuration/AlbumConfigurationTests.cs index 56797eba..d156dab8 100644 --- a/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/Configuration/AlbumConfigurationTests.cs +++ b/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/Configuration/AlbumConfigurationTests.cs @@ -70,11 +70,11 @@ public class AlbumConfigurationTests : IDisposable IProperty originalTitleProperty = entityType.GetProperty(nameof(AlbumEntity.OriginalTitle)); IProperty descriptionProperty = entityType.GetProperty(nameof(AlbumEntity.Description)); IProperty releaseCountryProperty = entityType.GetProperty(nameof(AlbumEntity.ReleaseCountry)); - IProperty releaseTypeProperty = entityType.GetProperty(nameof(AlbumEntity.ReleaseType)); + IProperty releaseTypeProperty = entityType.FindNavigation(nameof(AlbumEntity.ReleaseTypes))!.TargetEntityType.GetProperty(nameof(AlbumReleaseTypeEntity.ReleaseType)); IProperty releaseStatusProperty = entityType.GetProperty(nameof(AlbumEntity.ReleaseStatus)); IProperty mediaFormatProperty = entityType.GetProperty(nameof(AlbumEntity.MediaFormat)); IProperty barcodeProperty = entityType.GetProperty(nameof(AlbumEntity.Barcode)); - IProperty catalogNumberProperty = entityType.GetProperty(nameof(AlbumEntity.CatalogNumber)); + IProperty catalogNumberProperty = entityType.FindNavigation(nameof(AlbumEntity.CatalogNumbers))!.TargetEntityType.GetProperty(nameof(AlbumCatalogNumberEntity.CatalogNumber)); IProperty languageCodeProperty = entityType.GetProperty(nameof(AlbumEntity.LanguageCode)); // Assert @@ -87,7 +87,7 @@ public class AlbumConfigurationTests : IDisposable Assert.Equal(typeof(ReleaseCountry?), releaseCountryProperty.ClrType); Assert.Equal("TEXT", releaseCountryProperty.GetColumnType()); Assert.Equal(2, releaseCountryProperty.GetMaxLength()); - Assert.Equal(typeof(MusicReleaseType?), releaseTypeProperty.ClrType); + Assert.Equal(typeof(MusicReleaseType), releaseTypeProperty.ClrType); Assert.Equal("TEXT", releaseTypeProperty.GetColumnType()); Assert.Equal(50, releaseTypeProperty.GetMaxLength()); Assert.Equal(typeof(MusicReleaseStatus?), releaseStatusProperty.ClrType); diff --git a/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/Configuration/BookConfigurationTests.cs b/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/Configuration/BookConfigurationTests.cs index 9b6a2766..0e44873b 100644 --- a/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/Configuration/BookConfigurationTests.cs +++ b/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/Configuration/BookConfigurationTests.cs @@ -1,4 +1,5 @@ #region ========================================================================= USING ===================================================================================== +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary; using Lumina.DataAccess.Core.UoW; using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary; diff --git a/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/Configuration/MusicLibraryScanItemMetadataConfigurationTests.cs b/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/Configuration/MusicLibraryScanItemMetadataConfigurationTests.cs new file mode 100644 index 00000000..9a7b6d52 --- /dev/null +++ b/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/Configuration/MusicLibraryScanItemMetadataConfigurationTests.cs @@ -0,0 +1,163 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; +using Lumina.DataAccess.Core.UoW; +using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +#endregion + +namespace Lumina.DataAccess.UnitTests.Common.Configuration; + +/// +/// Contains unit tests for the class. +/// +[ExcludeFromCodeCoverage] +public class MusicLibraryScanItemMetadataConfigurationTests : IDisposable +{ + private readonly LuminaDbContext _context; + + /// + /// Initializes a new instance of the class. + /// + public MusicLibraryScanItemMetadataConfigurationTests() + { + _context = new LuminaDbContext(new DbContextOptionsBuilder().UseSqlite("Data Source=:memory:").Options); + } + + [Fact] + public void Configure_WhenApplied_ShouldSetTableNameAndKey() + { + // Arrange + IEntityType entityType = _context.Model.FindEntityType(typeof(MusicLibraryScanItemMetadataEntity))!; + + // Act + string? tableName = entityType.GetTableName(); + IReadOnlyList keyProperties = entityType.FindPrimaryKey()!.Properties; + + // Assert + Assert.Equal("MusicLibraryScanItemMetadata", tableName); + Assert.Equal(["Id"], keyProperties.Select(property => property.Name)); + } + + [Fact] + public void Configure_WhenApplied_ShouldNotGenerateTheIdValue() + { + // Arrange + IEntityType entityType = _context.Model.FindEntityType(typeof(MusicLibraryScanItemMetadataEntity))!; + + // Act + IProperty idProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.Id)); + + // Assert + Assert.Equal(ValueGenerated.Never, idProperty.ValueGenerated); + } + + [Fact] + public void Configure_WhenApplied_ShouldConfigureRequiredScalarProperties() + { + // Arrange + IEntityType entityType = _context.Model.FindEntityType(typeof(MusicLibraryScanItemMetadataEntity))!; + + // Act + IProperty libraryScanIdProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.LibraryScanId)); + IProperty libraryIdProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.LibraryId)); + IProperty pathProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.Path)); + + // Assert + Assert.False(libraryScanIdProperty.IsNullable); + Assert.False(libraryIdProperty.IsNullable); + Assert.False(pathProperty.IsNullable); + Assert.Equal(2048, pathProperty.GetMaxLength()); + } + + [Fact] + public void Configure_WhenApplied_ShouldConfigureOptionalScalarProperties() + { + // Arrange + IEntityType entityType = _context.Model.FindEntityType(typeof(MusicLibraryScanItemMetadataEntity))!; + + // Act + IProperty artistNameProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.ArtistName)); + IProperty releaseTypeProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.ReleaseType)); + IProperty releaseYearProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.ReleaseYear)); + IProperty releaseNameProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.ReleaseName)); + IProperty trackTitleProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.TrackTitle)); + IProperty audioCodecProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.AudioCodec)); + IProperty workTitleProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.WorkTitle)); + IProperty acoustIdProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.AcoustId)); + + // Assert + Assert.True(artistNameProperty.IsNullable); + Assert.Equal(255, artistNameProperty.GetMaxLength()); + Assert.True(releaseTypeProperty.IsNullable); + Assert.Equal(typeof(MusicReleaseType?), releaseTypeProperty.ClrType); + Assert.Equal("TEXT", releaseTypeProperty.GetColumnType()); + Assert.Equal(50, releaseTypeProperty.GetMaxLength()); + Assert.True(releaseYearProperty.IsNullable); + Assert.Equal(255, releaseNameProperty.GetMaxLength()); + Assert.Equal(255, trackTitleProperty.GetMaxLength()); + Assert.Equal(50, audioCodecProperty.GetMaxLength()); + Assert.Equal(255, workTitleProperty.GetMaxLength()); + Assert.Equal(64, acoustIdProperty.GetMaxLength()); + } + + [Fact] + public void Configure_WhenApplied_ShouldConfigureReplayGainDecimalPrecision() + { + // Arrange + IEntityType entityType = _context.Model.FindEntityType(typeof(MusicLibraryScanItemMetadataEntity))!; + + // Act + IProperty trackGainProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.ReplayGainTrackGain)); + IProperty trackPeakProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.ReplayGainTrackPeak)); + IProperty albumGainProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.ReplayGainAlbumGain)); + IProperty albumPeakProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.ReplayGainAlbumPeak)); + + // Assert + Assert.Equal("decimal(8,2)", trackGainProperty.GetColumnType()); + Assert.Equal("decimal(8,6)", trackPeakProperty.GetColumnType()); + Assert.Equal("decimal(8,2)", albumGainProperty.GetColumnType()); + Assert.Equal("decimal(8,6)", albumPeakProperty.GetColumnType()); + } + + [Fact] + public void Configure_WhenApplied_ShouldConfigureMoodsAsPrimitiveCollection() + { + // Arrange + IEntityType entityType = _context.Model.FindEntityType(typeof(MusicLibraryScanItemMetadataEntity))!; + + // Act + IProperty moodsProperty = entityType.GetProperty(nameof(MusicLibraryScanItemMetadataEntity.Moods)); + + // Assert + Assert.True(moodsProperty.IsPrimitiveCollection); + } + + [Fact] + public void Configure_WhenApplied_ShouldConfigureUniqueScanIdPathIndex() + { + // Arrange + IEntityType entityType = _context.Model.FindEntityType(typeof(MusicLibraryScanItemMetadataEntity))!; + + // Act + List indexes = [.. entityType.GetIndexes()]; + + // Assert + IIndex uniqueIndex = Assert.Single(indexes, index => index.IsUnique); + Assert.Equal( + [nameof(MusicLibraryScanItemMetadataEntity.LibraryScanId), nameof(MusicLibraryScanItemMetadataEntity.Path)], + uniqueIndex.Properties.Select(property => property.Name)); + } + + /// + /// Disposes the database context. + /// + public void Dispose() + { + _context.Dispose(); + } +} diff --git a/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/Configuration/TrackConfigurationTests.cs b/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/Configuration/TrackConfigurationTests.cs index 2cbb25e2..87c6a673 100644 --- a/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/Configuration/TrackConfigurationTests.cs +++ b/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/Configuration/TrackConfigurationTests.cs @@ -72,7 +72,7 @@ public class TrackConfigurationTests : IDisposable IProperty scriptProperty = entityType.GetProperty(nameof(TrackEntity.Script)); IProperty keyProperty = entityType.GetProperty(nameof(TrackEntity.Key)); IProperty audioCodecProperty = entityType.GetProperty(nameof(TrackEntity.AudioCodec)); - IProperty workProperty = entityType.GetProperty(nameof(TrackEntity.Work)); + IProperty workProperty = entityType.GetProperty(nameof(TrackEntity.WorkTitle)); // Assert Assert.False(pathProperty.IsNullable); @@ -118,9 +118,11 @@ public class TrackConfigurationTests : IDisposable List ownedTypes = [.. _context.Model.GetEntityTypes().Where(ownedType => ownedType.IsOwned() && ownedType.FindOwnership()?.PrincipalEntityType.Name == entityType.Name)]; // Assert - Assert.Equal(3, ownedTypes.Count); + Assert.Equal(5, ownedTypes.Count); Assert.Contains(ownedTypes, ownedType => ownedType.ClrType == typeof(TrackMoodEntity) && ownedType.GetTableName() == "TrackMoods"); Assert.Contains(ownedTypes, ownedType => ownedType.ClrType == typeof(TrackIsrcEntity) && ownedType.GetTableName() == "TrackIsrcs"); + Assert.Contains(ownedTypes, ownedType => ownedType.ClrType == typeof(TrackWorkLanguageEntity) && ownedType.GetTableName() == "TrackWorkLanguages"); + Assert.Contains(ownedTypes, ownedType => ownedType.ClrType == typeof(TrackWorkIswcEntity) && ownedType.GetTableName() == "TrackWorkIswcs"); Assert.Contains(ownedTypes, ownedType => ownedType.ClrType == typeof(AudioRatingEntity) && ownedType.GetTableName() == "TrackRatings"); } diff --git a/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/BookLibrary/BookRepositoryTests.cs b/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/BookLibrary/BookRepositoryTests.cs index c4375abc..709ccecd 100644 --- a/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/BookLibrary/BookRepositoryTests.cs +++ b/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/BookLibrary/BookRepositoryTests.cs @@ -314,6 +314,74 @@ public class BookRepositoryTests Assert.Null(result.Value); } + [Fact] + public async Task GetExistingPathsAsync_WhenPathsIsEmpty_ShouldReturnAnEmptyCollection() + { + // Arrange + IReadOnlyCollection paths = []; + + // Act + Result> result = await _sut.GetExistingPathsAsync(Guid.NewGuid(), paths, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + Assert.Empty(result.Value); + } + + [Fact] + public async Task GetExistingPathsAsync_WhenCalled_ShouldReturnOnlyThePathsUsedByBooksOfTheLibrary() + { + // Arrange + Guid libraryId = Guid.NewGuid(); + BookEntity bookOfLibrary = _bookEntityFixture.Create(libraryId: libraryId, path: "/books/tolkien/the-hobbit.epub"); + BookEntity bookOfAnotherLibrary = _bookEntityFixture.Create(libraryId: Guid.NewGuid(), path: "/books/tolkien/the-lord-of-the-rings.epub"); + _mockContext.Books.AddRange(bookOfLibrary, bookOfAnotherLibrary); + await _mockContext.SaveChangesAsync(); + + // Act + Result> result = await _sut.GetExistingPathsAsync(libraryId, ["/books/tolkien/the-hobbit.epub", "/books/tolkien/the-lord-of-the-rings.epub"], CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + string existingPath = Assert.Single(result.Value); + Assert.Equal("/books/tolkien/the-hobbit.epub", existingPath); + } + + [Fact] + public async Task GetExistingPathsAsync_WhenInputContainsDuplicatePaths_ShouldDeDuplicateTheResult() + { + // Arrange + Guid libraryId = Guid.NewGuid(); + BookEntity book = _bookEntityFixture.Create(libraryId: libraryId, path: "/books/tolkien/the-hobbit.epub"); + _mockContext.Books.Add(book); + await _mockContext.SaveChangesAsync(); + + // Act + Result> result = await _sut.GetExistingPathsAsync(libraryId, ["/books/tolkien/the-hobbit.epub", "/books/tolkien/the-hobbit.epub", "/books/tolkien/the-hobbit.epub"], CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + Assert.Single(result.Value); + Assert.Equal("/books/tolkien/the-hobbit.epub", result.Value.First()); + } + + [Fact] + public async Task GetExistingPathsAsync_WhenPathDiffersOnlyByCase_ShouldNotReportItAsExisting() + { + // Arrange + Guid libraryId = Guid.NewGuid(); + BookEntity book = _bookEntityFixture.Create(libraryId: libraryId, path: "/Books/Tolkien/The-Hobbit.epub"); + _mockContext.Books.Add(book); + await _mockContext.SaveChangesAsync(); + + // Act + Result> result = await _sut.GetExistingPathsAsync(libraryId, ["/books/tolkien/the-hobbit.epub"], CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + Assert.Empty(result.Value); + } + [Fact] public async Task GetBooksNeedingMetadataAsync_WhenCalled_ShouldReturnOnlyBooksWhoseMetadataIsNotEnriched() { diff --git a/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MediaContributors/MediaContributorRepositoryTests.cs b/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MediaContributors/MediaContributorRepositoryTests.cs index 641fa0b8..1e3ec47a 100644 --- a/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MediaContributors/MediaContributorRepositoryTests.cs +++ b/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MediaContributors/MediaContributorRepositoryTests.cs @@ -4,6 +4,7 @@ using Lumina.Application.Common.DataAccess.Entities.MediaContributors; using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaContributors; using Lumina.DataAccess.Core.Repositories.MediaContributors; using Lumina.DataAccess.Core.UoW; +using Lumina.Domain.Common.Errors; using Lumina.Domain.Common.Primitives; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.ChangeTracking; @@ -91,6 +92,42 @@ public class MediaContributorRepositoryTests Assert.Single(_mockContext.ChangeTracker.Entries()); } + [Fact] + public async Task FindOrCreateByDisplayNameAsync_WhenExistingNameStartsWithNonAsciiUppercase_ShouldReturnTheExistingContributor() + { + // Arrange + // The storage medium folds only ASCII case, so a name starting with a non-ASCII uppercase letter would previously not be found by the lookup + // and would be inserted again, violating the unique index on the display name. + MediaContributorEntity existingContributor = _mediaContributorEntityFixture.Create(displayName: "Лев Ошанин"); + _mockContext.MediaContributors.Add(existingContributor); + await _mockContext.SaveChangesAsync(); + + // Act + Result result = await _sut.FindOrCreateByDisplayNameAsync("Лев Ошанин", null, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + Assert.Equal(existingContributor.Id, result.Value.Id); + Assert.Single(_mockContext.ChangeTracker.Entries()); + } + + [Fact] + public async Task FindOrCreateByDisplayNameAsync_WhenContributorWasAddedButNotSaved_ShouldReturnTheTrackedContributor() + { + // Arrange + Result firstResult = await _sut.FindOrCreateByDisplayNameAsync("Bob Ludwig", null, CancellationToken.None); + Assert.False(firstResult.IsFailure); + + // Act + Result secondResult = await _sut.FindOrCreateByDisplayNameAsync("BOB LUDWIG", null, CancellationToken.None); + + // Assert + Assert.False(secondResult.IsFailure); + // The contributor added earlier in the same unit of work is tracked, so it is returned instead of a duplicate being added. + Assert.Equal(firstResult.Value.Id, secondResult.Value.Id); + Assert.Single(_mockContext.ChangeTracker.Entries(), entityEntry => entityEntry.State == EntityState.Added); + } + [Fact] public async Task GetByIdsAsync_WhenCalled_ShouldReturnOnlyTheContributorsWithTheProvidedIds() { @@ -128,4 +165,21 @@ public class MediaContributorRepositoryTests .FirstOrDefault(entityEntry => entityEntry.State == EntityState.Added && entityEntry.Entity.Id == contributor.Id); Assert.NotNull(addedContributor); } + + [Fact] + public async Task InsertAsync_WhenContributorWithSameIdAlreadyExists_ShouldReturnError() + { + // Arrange + MediaContributorEntity existingContributor = _mediaContributorEntityFixture.Create(); + _mockContext.MediaContributors.Add(existingContributor); + await _mockContext.SaveChangesAsync(); + MediaContributorEntity contributor = _mediaContributorEntityFixture.Create(id: existingContributor.Id); + + // Act + Result result = await _sut.InsertAsync(contributor, CancellationToken.None); + + // Assert + Assert.True(result.IsFailure); + Assert.Equal(Errors.MediaContributor.MediaContributorAlreadyExists, result.FirstError); + } } diff --git a/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MusicLibrary/AlbumRepositoryTests.cs b/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MusicLibrary/AlbumRepositoryTests.cs index 23b27f7d..0666fcf4 100644 --- a/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MusicLibrary/AlbumRepositoryTests.cs +++ b/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MusicLibrary/AlbumRepositoryTests.cs @@ -14,6 +14,7 @@ using Lumina.Domain.Common.Errors; using Lumina.Domain.Common.Primitives; using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary; using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors; +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.ChangeTracking; using NSubstitute; @@ -499,6 +500,32 @@ public class AlbumRepositoryTests Assert.Single(_mockContext.Set().Where(genre => genre.Name == "ExistingGenre")); } + [Fact] + public async Task UpdateAsync_WhenCatalogNumbersChange_ShouldAddTheNewAndRemoveTheMissingOnes() + { + // Arrange + AlbumEntity storedAlbum = _albumEntityFixture.Create(includeTracks: false, includeMetadata: false, catalogNumbers: ["EMC 3006", "OC 062 o 94519"]); + _mockContext.Albums.Add(storedAlbum); + await _mockContext.SaveChangesAsync(); + + AlbumEntity data = _albumEntityFixture.Create(id: storedAlbum.Id, includeTracks: false, includeMetadata: false, catalogNumbers: ["EMC 3006", "EMTC 104"]); + + // Act + Result result = await _sut.UpdateAsync(data, CancellationToken.None); + await _mockContext.SaveChangesAsync(); + + // Assert + Assert.False(result.IsFailure); + AlbumEntity? retrievedAlbum = await _mockContext.Albums + .Include(album => album.CatalogNumbers) + .FirstOrDefaultAsync(album => album.Id == storedAlbum.Id); + Assert.NotNull(retrievedAlbum); + Assert.Equal(2, retrievedAlbum!.CatalogNumbers.Count); + Assert.Contains(retrievedAlbum.CatalogNumbers, catalogNumber => catalogNumber.CatalogNumber == "EMC 3006"); + Assert.Contains(retrievedAlbum.CatalogNumbers, catalogNumber => catalogNumber.CatalogNumber == "EMTC 104"); + Assert.DoesNotContain(retrievedAlbum.CatalogNumbers, catalogNumber => catalogNumber.CatalogNumber == "OC 062 o 94519"); + } + [Fact] public async Task GetByIdAsync_WhenAlbumExists_ShouldReturnTheAlbum() { @@ -714,6 +741,26 @@ public class AlbumRepositoryTests Assert.Equal(12, row.TotalTracks); } + [Fact] + public async Task GetAlbumsNeedingMetadataCountAsync_WhenAlbumsHaveMixedMetadataStatuses_ShouldCountOnlyTheNotEnrichedOnesOfTheLibrary() + { + // Arrange + Guid libraryId = Guid.NewGuid(); + AlbumEntity pendingAlbum = _albumEntityFixture.Create(libraryId: libraryId, includeTracks: false, includeMetadata: false, metadataStatus: MetadataStatus.Pending); + AlbumEntity failedAlbum = _albumEntityFixture.Create(libraryId: libraryId, includeTracks: false, includeMetadata: false, metadataStatus: MetadataStatus.Failed); + AlbumEntity enrichedAlbum = _albumEntityFixture.Create(libraryId: libraryId, includeTracks: false, includeMetadata: false, metadataStatus: MetadataStatus.Enriched); + AlbumEntity albumOfAnotherLibrary = _albumEntityFixture.Create(includeTracks: false, includeMetadata: false, metadataStatus: MetadataStatus.Pending); + _mockContext.Albums.AddRange(pendingAlbum, failedAlbum, enrichedAlbum, albumOfAnotherLibrary); + await _mockContext.SaveChangesAsync(); + + // Act + Result result = await _sut.GetAlbumsNeedingMetadataCountAsync(libraryId, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + Assert.Equal(2, result.Value); + } + /// /// Creates an album that belongs to the artist identified by , with every related collection populated deterministically. /// diff --git a/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MusicLibrary/ArtistRepositoryTests.cs b/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MusicLibrary/ArtistRepositoryTests.cs index add56a0c..38dd1bf3 100644 --- a/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MusicLibrary/ArtistRepositoryTests.cs +++ b/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MusicLibrary/ArtistRepositoryTests.cs @@ -16,6 +16,7 @@ using Lumina.Domain.Common.Primitives; using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary; using Lumina.Domain.SharedKernel.Common.Enums.Common; using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors; +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.ChangeTracking; using System; @@ -1118,6 +1119,104 @@ public class ArtistRepositoryTests Assert.Equal(expectedRowCount, page.Data.Count); } + [Fact] + public async Task GetArtistsNeedingMetadataAsync_WhenAnArtistAndAllItsDescendantsAreEnriched_ShouldNotReturnIt() + { + // Arrange + Guid libraryId = Guid.NewGuid(); + ArtistEntity enriched = CreateArtistWithFullAggregate(); + enriched.LibraryId = libraryId; + MarkEnriched(enriched); + ArtistEntity pending = _artistEntityFixture.Create(libraryId: libraryId, name: "Pending Artist", includeAlbums: false, includeContributors: false); + _mockContext.Artists.AddRange(enriched, pending); + await _mockContext.SaveChangesAsync(); + + // Act + Result> result = await _sut.GetArtistsNeedingMetadataAsync(libraryId, null, 10, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + ArtistEntity onlyArtist = Assert.Single(result.Value); + Assert.Equal(pending.Id, onlyArtist.Id); + } + + [Fact] + public async Task GetArtistsNeedingMetadataAsync_WhenATrackIsNotEnriched_ShouldReturnTheArtist() + { + // Arrange + Guid libraryId = Guid.NewGuid(); + ArtistEntity artist = CreateArtistWithFullAggregate(); + artist.LibraryId = libraryId; + MarkEnriched(artist); + artist.Albums[0].Tracks[0].MetadataStatus = MetadataStatus.Pending; + _mockContext.Artists.Add(artist); + await _mockContext.SaveChangesAsync(); + + // Act + Result> result = await _sut.GetArtistsNeedingMetadataAsync(libraryId, null, 10, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + ArtistEntity onlyArtist = Assert.Single(result.Value); + Assert.Equal(artist.Id, onlyArtist.Id); + } + + [Fact] + public async Task GetArtistsNeedingMetadataAsync_WhenLastNameIsProvided_ShouldReturnOnlyArtistsAfterIt() + { + // Arrange + Guid libraryId = Guid.NewGuid(); + ArtistEntity alpha = _artistEntityFixture.Create(libraryId: libraryId, name: "Alpha", includeAlbums: false, includeContributors: false); + ArtistEntity beta = _artistEntityFixture.Create(libraryId: libraryId, name: "Beta", includeAlbums: false, includeContributors: false); + ArtistEntity gamma = _artistEntityFixture.Create(libraryId: libraryId, name: "Gamma", includeAlbums: false, includeContributors: false); + _mockContext.Artists.AddRange(alpha, beta, gamma); + await _mockContext.SaveChangesAsync(); + + // Act + Result> result = await _sut.GetArtistsNeedingMetadataAsync(libraryId, "Beta", 10, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + ArtistEntity onlyArtist = Assert.Single(result.Value); + Assert.Equal(gamma.Id, onlyArtist.Id); + } + + [Fact] + public async Task GetArtistsNeedingMetadataCountAsync_ShouldCountArtistsWithPendingMetadataIncludingDescendants() + { + // Arrange + Guid libraryId = Guid.NewGuid(); + ArtistEntity enriched = CreateArtistWithFullAggregate(); + enriched.LibraryId = libraryId; + MarkEnriched(enriched); + ArtistEntity pending = _artistEntityFixture.Create(libraryId: libraryId, includeAlbums: false, includeContributors: false); + ArtistEntity otherLibrary = _artistEntityFixture.Create(includeAlbums: false, includeContributors: false); + _mockContext.Artists.AddRange(enriched, pending, otherLibrary); + await _mockContext.SaveChangesAsync(); + + // Act + Result result = await _sut.GetArtistsNeedingMetadataCountAsync(libraryId, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + Assert.Equal(1, result.Value); + } + + /// + /// Marks the provided artist, its albums and its tracks as enriched. + /// + /// The artist whose metadata enrichment status is set. + private static void MarkEnriched(ArtistEntity artist) + { + artist.MetadataStatus = MetadataStatus.Enriched; + foreach (AlbumEntity album in artist.Albums) + { + album.MetadataStatus = MetadataStatus.Enriched; + foreach (TrackEntity track in album.Tracks) + track.MetadataStatus = MetadataStatus.Enriched; + } + } + /// /// Creates an artist that owns an album which in turn owns a track, with every related collection of the aggregate populated deterministically. /// diff --git a/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MusicLibrary/MusicLibraryScanItemMetadataRepositoryTests.cs b/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MusicLibrary/MusicLibraryScanItemMetadataRepositoryTests.cs new file mode 100644 index 00000000..b9c417ed --- /dev/null +++ b/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MusicLibrary/MusicLibraryScanItemMetadataRepositoryTests.cs @@ -0,0 +1,130 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; +using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; +using Lumina.DataAccess.Core.Repositories.MusicLibrary; +using Lumina.DataAccess.Core.UoW; +using Lumina.Domain.Common.Primitives; +using Microsoft.Data.Sqlite; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +#endregion + +namespace Lumina.DataAccess.UnitTests.Core.Repositories.MusicLibrary; + +/// +/// Contains unit tests for the class. +/// +[ExcludeFromCodeCoverage] +public class MusicLibraryScanItemMetadataRepositoryTests : IDisposable +{ + private readonly SqliteConnection _connection; + private readonly LuminaDbContext _context; + private readonly MusicLibraryScanItemMetadataRepository _sut; + private readonly MusicLibraryScanItemMetadataEntityFixture _musicLibraryScanItemMetadataEntityFixture = new(); + + /// + /// Initializes a new instance of the class. + /// + public MusicLibraryScanItemMetadataRepositoryTests() + { + // the repository deletes in bulk, which translates to SQL, so it can only be exercised against a real SQLite database + _connection = new SqliteConnection("Data Source=:memory:"); + _connection.Open(); + _context = new LuminaDbContext(new DbContextOptionsBuilder().UseSqlite(_connection).Options); + _context.Database.EnsureCreated(); + _sut = new MusicLibraryScanItemMetadataRepository(_context); + } + + [Fact] + public async Task InsertRangeAsync_WhenCalledWithItems_ShouldAddThemToContextAndReturnCreated() + { + // Arrange + List items = _musicLibraryScanItemMetadataEntityFixture.CreateMany(3); + + // Act + Result result = await _sut.InsertRangeAsync(items, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + Assert.Equal(Result.Created, result.Value); + await _context.SaveChangesAsync(); + Assert.Equal(3, await _context.MusicLibraryScanItemMetadata.CountAsync()); + } + + [Fact] + public async Task InsertRangeAsync_WhenCollectionIsEmpty_ShouldReturnCreatedWithoutAddingAnyItems() + { + // Act + Result result = await _sut.InsertRangeAsync([], CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + Assert.Equal(Result.Created, result.Value); + await _context.SaveChangesAsync(); + Assert.Empty(await _context.MusicLibraryScanItemMetadata.ToListAsync()); + } + + [Fact] + public async Task GetByScanIdAsync_WhenCalled_ShouldReturnOnlyTheItemsOfTheScanOrderedByPath() + { + // Arrange + Guid scanId = Guid.NewGuid(); + MusicLibraryScanItemMetadataEntity bicycleItem = _musicLibraryScanItemMetadataEntityFixture.Create(libraryScanId: scanId, path: "/music/queen/bicycle-race.flac"); + MusicLibraryScanItemMetadataEntity bohemianItem = _musicLibraryScanItemMetadataEntityFixture.Create(libraryScanId: scanId, path: "/music/queen/bohemian-rhapsody.flac"); + MusicLibraryScanItemMetadataEntity itemOfAnotherScan = _musicLibraryScanItemMetadataEntityFixture.Create(path: "/music/queen/dont-stop-me-now.flac"); + _context.MusicLibraryScanItemMetadata.AddRange(bicycleItem, bohemianItem, itemOfAnotherScan); + await _context.SaveChangesAsync(); + + // Act + Result> result = await _sut.GetByScanIdAsync(scanId, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + Assert.Equal([bicycleItem.Id, bohemianItem.Id], result.Value.Select(item => item.Id)); + } + + [Fact] + public async Task GetByScanIdAsync_WhenNoItemsExistForTheScan_ShouldReturnAnEmptyCollection() + { + // Act + Result> result = await _sut.GetByScanIdAsync(Guid.NewGuid(), CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + Assert.Empty(result.Value); + } + + [Fact] + public async Task DeleteByScanIdAsync_WhenCalled_ShouldDeleteOnlyTheItemsOfTheScan() + { + // Arrange + Guid scanId = Guid.NewGuid(); + MusicLibraryScanItemMetadataEntity itemOfScan = _musicLibraryScanItemMetadataEntityFixture.Create(libraryScanId: scanId, path: "/music/queen/bohemian-rhapsody.flac"); + MusicLibraryScanItemMetadataEntity itemOfAnotherScan = _musicLibraryScanItemMetadataEntityFixture.Create(path: "/music/queen/love-of-my-life.flac"); + _context.MusicLibraryScanItemMetadata.AddRange(itemOfScan, itemOfAnotherScan); + await _context.SaveChangesAsync(); + + // Act + Result result = await _sut.DeleteByScanIdAsync(scanId, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + Assert.Equal(Result.Deleted, result.Value); + MusicLibraryScanItemMetadataEntity remainingItem = Assert.Single(await _context.MusicLibraryScanItemMetadata.ToListAsync()); + Assert.Equal(itemOfAnotherScan.Id, remainingItem.Id); + } + + /// + /// Disposes the database context and its underlying connection. + /// + public void Dispose() + { + _context.Dispose(); + _connection.Dispose(); + } +} diff --git a/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MusicLibrary/TrackRepositoryTests.cs b/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MusicLibrary/TrackRepositoryTests.cs index 7b12913e..71a4ab0d 100644 --- a/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MusicLibrary/TrackRepositoryTests.cs +++ b/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MusicLibrary/TrackRepositoryTests.cs @@ -13,6 +13,7 @@ using Lumina.Domain.Common.Errors; using Lumina.Domain.Common.Primitives; using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary; using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors; +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.ChangeTracking; using System; @@ -792,4 +793,24 @@ public class TrackRepositoryTests Assert.Equal(9, row.TrackNumber); Assert.Equal(3, row.DiscNumber); } + + [Fact] + public async Task GetTracksNeedingMetadataCountAsync_WhenTracksHaveMixedMetadataStatuses_ShouldCountOnlyTheNotEnrichedOnesOfTheLibrary() + { + // Arrange + Guid libraryId = Guid.NewGuid(); + TrackEntity pendingTrack = _trackEntityFixture.Create(libraryId: libraryId, includeMetadata: false, metadataStatus: MetadataStatus.Pending); + TrackEntity failedTrack = _trackEntityFixture.Create(libraryId: libraryId, includeMetadata: false, metadataStatus: MetadataStatus.Failed); + TrackEntity enrichedTrack = _trackEntityFixture.Create(libraryId: libraryId, includeMetadata: false, metadataStatus: MetadataStatus.Enriched); + TrackEntity trackOfAnotherLibrary = _trackEntityFixture.Create(includeMetadata: false, metadataStatus: MetadataStatus.Pending); + _mockContext.Tracks.AddRange(pendingTrack, failedTrack, enrichedTrack, trackOfAnotherLibrary); + await _mockContext.SaveChangesAsync(); + + // Act + Result result = await _sut.GetTracksNeedingMetadataCountAsync(libraryId, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + Assert.Equal(2, result.Value); + } }