mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
Merge pull request #291 from BinaryAlley/feature/migrate-entity-identifiers-to-guid-v7
Migrates persisted identifiers to GUID version 7
This commit is contained in:
80 files changed
+305
-129
No files matched your search
+86
@@ -0,0 +1,86 @@
|
|||||||
|
# Architecture Decision Record (ADR): 0020 - Use GUID Version 7 for Persisted Identifiers
|
||||||
|
|
||||||
|
## Status
|
||||||
|
**Accepted** (2026-11-16)
|
||||||
|
|
||||||
|
## Context
|
||||||
|
|
||||||
|
Persisted entity identifiers were generated with `Guid.NewGuid()`, which produces a version 4 GUID with 122 random bits and no ordering. SQLite stores the identifiers as upper case, hyphenated TEXT values, and the primary key is the index key, so random identifiers scatter inserts across the index instead of appending to it.
|
||||||
|
|
||||||
|
Identifiers are minted in several places:
|
||||||
|
|
||||||
|
- Domain value object factories, mappings, and aggregate methods that create domain event identifiers.
|
||||||
|
- Application command handlers that build repository entities.
|
||||||
|
- Data access repositories and the data seed service.
|
||||||
|
- Infrastructure media library scan jobs, provider configuration storage, scheduler execution, and theme synchronization.
|
||||||
|
- Entity Framework Core, for keys configured with `ValueGeneratedOnAdd`, including real keys such as `PermissionEntity.Id` and `RoleEntity.Id`, and shadow keys of owned collections such as `AlbumReleaseTypes.Id`.
|
||||||
|
- Two bulk inserts that generate their identifiers in SQLite to keep a single statement.
|
||||||
|
|
||||||
|
A search for `Guid.NewGuid` cannot see the Entity Framework Core and SQL paths. Those paths would otherwise keep producing version 4 identifiers while the rest of the solution moves to version 7.
|
||||||
|
|
||||||
|
## Decision
|
||||||
|
|
||||||
|
Persisted entity and domain event identifiers are created with `Guid.CreateVersion7()`, which embeds a Unix timestamp in milliseconds in the most significant bits and makes the identifiers time ordered.
|
||||||
|
|
||||||
|
The decision applies to Domain, Application, DataAccess, and Infrastructure:
|
||||||
|
|
||||||
|
- Every identifier factory and every code path that mints an entity or domain event identifier in application code calls `Guid.CreateVersion7()` directly.
|
||||||
|
- Every Entity Framework Core property of type `Guid` with `ValueGenerated.OnAdd` is assigned the `GuidV7ValueGenerator` in `LuminaDbContext.OnModelCreating`. The loop covers real keys and owned collection shadow keys, so the data seed service can keep leaving seeded permission and role identifiers unset.
|
||||||
|
- Existing rows keep their version 4 identifiers. This is a forward-only change, and no primary key or foreign key is rewritten.
|
||||||
|
|
||||||
|
The following identifiers intentionally remain outside the version 7 strategy:
|
||||||
|
|
||||||
|
- **Opaque playback delivery handles** in `PlaybackDeliveryHandleService` stay version 4. The handle is deliberately unguessable and must not reveal when it was created, and version 7 embeds the creation time and leaves fewer random bits.
|
||||||
|
- **Plugin identifiers** in `PluginDetectionSyncJob.DerivePluginId` are derived with SHA-256 from the plugin assembly file name, so a plugin that fails to load keeps the same row across restarts. A derived, stable value is required, not a time ordered one.
|
||||||
|
- **The SYSTEM audit user identifier** in `UpdateAuditableEntitiesInterceptor` is the fixed sentinel `11111111-1111-1111-1111-111111111111`.
|
||||||
|
- **The bulk insert paths** in `PlaylistRepository.InsertScopeEntriesAsync` and `LibraryScanSnapshotRepository.ApplySnapshotSwapAsync` generate random version 4 GUIDs in SQLite. Generating the identifiers in C# would materialize the rows and defeat the single statement insert. SQLite cannot produce a version 7 GUID inside those statements without a custom function.
|
||||||
|
- **Temporary file names, cache reservation and deletion names, theme work directories, and UI script identifiers** are not persisted identifiers, so they stay version 4.
|
||||||
|
|
||||||
|
## Consequences
|
||||||
|
|
||||||
|
### Positive Outcomes
|
||||||
|
|
||||||
|
| Aspect | Benefit |
|
||||||
|
|---|---|
|
||||||
|
| Index locality | Time ordered keys append to the primary key index instead of scattering across it |
|
||||||
|
| Diagnostics | The creation time is recoverable from a persisted identifier |
|
||||||
|
| Coverage | Entity Framework Core keys and owned collection shadow keys follow the same strategy as the code that assigns identifiers explicitly |
|
||||||
|
| Consistency | The solution has one strategy for persisted identifiers, with the exceptions recorded above |
|
||||||
|
| Compatibility | The identifier type and storage format are unchanged, so no schema migration is required |
|
||||||
|
|
||||||
|
### Risks and Tradeoffs
|
||||||
|
|
||||||
|
| Risk | Mitigation Strategy |
|
||||||
|
|---|---|
|
||||||
|
| The creation time is embedded in the identifier | Do not use version 7 identifiers where the creation time must remain secret |
|
||||||
|
| Version 7 has fewer random bits than version 4 | Keep version 4 for opaque security handles, and never treat an identifier as a secret |
|
||||||
|
| Existing rows keep version 4 identifiers | Do not use identifier order as a chronology across the migration boundary; use `CreatedOnUtc` |
|
||||||
|
| The two SQL bulk insert paths keep version 4 identifiers | The exception is documented in this ADR and in both repositories, so it is not changed accidentally |
|
||||||
|
| Version 7 ordering depends on the system clock | Clock skew can break ordering, but not uniqueness; do not depend on strict ordering across machines |
|
||||||
|
| Entity Framework Core could seed a new key with version 4 again | `LuminaDbContext` applies the generator to every `Guid` property configured with `ValueGenerated.OnAdd`, including owned shadow keys |
|
||||||
|
|
||||||
|
## Alternatives Considered
|
||||||
|
|
||||||
|
### 1. Keep version 4 identifiers
|
||||||
|
|
||||||
|
Keep `Guid.NewGuid()` everywhere and accept random primary key inserts.
|
||||||
|
|
||||||
|
**Rejected**: random keys scatter inserts across the SQLite primary key index, which is the write path of every media library scan and every catalogue edit.
|
||||||
|
|
||||||
|
### 2. Generate sequential or COMB GUIDs in application code
|
||||||
|
|
||||||
|
Implement a custom monotonic GUID generator that places a timestamp or counter in the version 4 layout.
|
||||||
|
|
||||||
|
**Rejected**: it requires custom generation and ordering logic that must be maintained and tested, while .NET provides a standard time ordered version 7 GUID.
|
||||||
|
|
||||||
|
### 3. Generate version 7 identifiers in SQL for the bulk inserts
|
||||||
|
|
||||||
|
Construct the version 7 timestamp and random fields inside the bulk SQL statements.
|
||||||
|
|
||||||
|
**Rejected**: SQLite has no built-in version 7 GUID function, and adding a custom function or extension for these two paths would add deployment and portability constraints. The single statement inserts keep their version 4 identifiers and the exception is documented.
|
||||||
|
|
||||||
|
### 4. Rewrite existing identifiers to version 7
|
||||||
|
|
||||||
|
Migrate every stored primary key and foreign key to a version 7 value.
|
||||||
|
|
||||||
|
**Rejected**: rewriting primary keys means rewriting every foreign key that references them, with a high risk of corruption and downtime, for no benefit to existing rows.
|
||||||
@@ -34,6 +34,7 @@ This project enforces many style rules via `.editorconfig` as build errors, so t
|
|||||||
- **`<inheritdoc/>`**: avoid on classes implementing interface members. Developers usually work in the implementing class and should see documentation there directly, without having to open the interface.
|
- **`<inheritdoc/>`**: avoid on classes implementing interface members. Developers usually work in the implementing class and should see documentation there directly, without having to open the interface.
|
||||||
- **Boolean naming**: boolean fields, properties, and methods returning booleans must start with a verb implying true/false: `is`, `are`, `should`, `has`, `was`, `can`, etc.
|
- **Boolean naming**: boolean fields, properties, and methods returning booleans must start with a verb implying true/false: `is`, `are`, `should`, `has`, `was`, `can`, etc.
|
||||||
- **Error handling**: rule violations return `Result<T>`. Never throw exceptions unless explicitly justified (e.g. startup/configuration code). Flag any `throw` outside that context.
|
- **Error handling**: rule violations return `Result<T>`. Never throw exceptions unless explicitly justified (e.g. startup/configuration code). Flag any `throw` outside that context.
|
||||||
|
- **Identifier generation**: persisted entity and domain event identifiers are created with `Guid.CreateVersion7()`, never `Guid.NewGuid()`, so inserts stay time ordered. Entity Framework Core keys configured with `ValueGeneratedOnAdd` receive the same generator through `LuminaDbContext`. Version 4 remains correct only for opaque security handles, temporary file or cache names, fixed sentinel identifiers such as the SYSTEM audit user, stable derived identifiers such as the SHA-256 plugin identifier, and the SQL bulk insert paths recorded in [ADR-0020](../architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0020.md).
|
||||||
|
|
||||||
## Review priority
|
## Review priority
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -66,7 +66,7 @@ public static class AlbumMapping
|
|||||||
MusicBrainzReleaseArtistId = domainEntity.MusicBrainzReleaseArtistId.HasValue ? domainEntity.MusicBrainzReleaseArtistId.Value.Value : null,
|
MusicBrainzReleaseArtistId = domainEntity.MusicBrainzReleaseArtistId.HasValue ? domainEntity.MusicBrainzReleaseArtistId.Value.Value : null,
|
||||||
Contributors = [.. domainEntity.Contributors.Select(contributor => new AlbumContributorEntity
|
Contributors = [.. domainEntity.Contributors.Select(contributor => new AlbumContributorEntity
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
AlbumId = domainEntity.Id.Value,
|
AlbumId = domainEntity.Id.Value,
|
||||||
MediaContributorId = contributor.ContributorId.Value,
|
MediaContributorId = contributor.ContributorId.Value,
|
||||||
Role = contributor.Role,
|
Role = contributor.Role,
|
||||||
|
|||||||
+1
-1
@@ -48,7 +48,7 @@ public static class ArtistMapping
|
|||||||
Ratings = [.. domainEntity.Ratings.ToRepositoryEntities()],
|
Ratings = [.. domainEntity.Ratings.ToRepositoryEntities()],
|
||||||
Contributors = [.. domainEntity.Contributors.Select(contributor => new ArtistContributorEntity
|
Contributors = [.. domainEntity.Contributors.Select(contributor => new ArtistContributorEntity
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
ArtistId = domainEntity.Id.Value,
|
ArtistId = domainEntity.Id.Value,
|
||||||
MediaContributorId = contributor.ContributorId.Value,
|
MediaContributorId = contributor.ContributorId.Value,
|
||||||
Role = contributor.Role,
|
Role = contributor.Role,
|
||||||
|
|||||||
+1
-1
@@ -72,7 +72,7 @@ public static class TrackMapping
|
|||||||
MusicBrainzWorkId = domainEntity.Work.HasValue ? domainEntity.Work.Value.MusicBrainzWorkId.Value : null,
|
MusicBrainzWorkId = domainEntity.Work.HasValue ? domainEntity.Work.Value.MusicBrainzWorkId.Value : null,
|
||||||
Contributors = [.. domainEntity.Contributors.Select(contributor => new TrackContributorEntity
|
Contributors = [.. domainEntity.Contributors.Select(contributor => new TrackContributorEntity
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
TrackId = domainEntity.Id.Value,
|
TrackId = domainEntity.Id.Value,
|
||||||
MediaContributorId = contributor.ContributorId.Value,
|
MediaContributorId = contributor.ContributorId.Value,
|
||||||
Role = contributor.Role,
|
Role = contributor.Role,
|
||||||
|
|||||||
+2
-2
@@ -60,7 +60,7 @@ public static class BookMapping
|
|||||||
ISBNs = [.. domainEntity.ISBNs.ToRepositoryEntities()],
|
ISBNs = [.. domainEntity.ISBNs.ToRepositoryEntities()],
|
||||||
Contributors = [.. domainEntity.Contributors.Select(contributor => new BookContributorEntity
|
Contributors = [.. domainEntity.Contributors.Select(contributor => new BookContributorEntity
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
BookId = domainEntity.Id.Value,
|
BookId = domainEntity.Id.Value,
|
||||||
MediaContributorId = contributor.ContributorId.Value,
|
MediaContributorId = contributor.ContributorId.Value,
|
||||||
Role = contributor.Role,
|
Role = contributor.Role,
|
||||||
@@ -115,6 +115,6 @@ public static class BookMapping
|
|||||||
entity.BarnesAndNobleId = domainEntity.BarnesAndNobleId.HasValue ? domainEntity.BarnesAndNobleId.Value : null;
|
entity.BarnesAndNobleId = domainEntity.BarnesAndNobleId.HasValue ? domainEntity.BarnesAndNobleId.Value : null;
|
||||||
entity.AppleBooksId = domainEntity.AppleBooksId.HasValue ? domainEntity.AppleBooksId.Value : null;
|
entity.AppleBooksId = domainEntity.AppleBooksId.HasValue ? domainEntity.AppleBooksId.Value : null;
|
||||||
entity.UpdatedOnUtc = DateTime.UtcNow;
|
entity.UpdatedOnUtc = DateTime.UtcNow;
|
||||||
entity.UpdatedBy = Guid.NewGuid();
|
entity.UpdatedBy = Guid.CreateVersion7();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -29,7 +29,7 @@ public static class UpdateBookCoverCommandMapping
|
|||||||
{
|
{
|
||||||
return new BookArtworkEntity
|
return new BookArtworkEntity
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
BookId = bookId,
|
BookId = bookId,
|
||||||
ArtworkType = ArtworkType.Cover,
|
ArtworkType = ArtworkType.Cover,
|
||||||
Ordinal = 0,
|
Ordinal = 0,
|
||||||
|
|||||||
+2
-2
@@ -97,7 +97,7 @@ public class SetupApplicationCommandHandler : ICommandHandler<SetupApplicationCo
|
|||||||
return Errors.Authorization.AdminAccountAlreadyCreated;
|
return Errors.Authorization.AdminAccountAlreadyCreated;
|
||||||
// No users are present, register the admin one.
|
// No users are present, register the admin one.
|
||||||
string? totpSecret = null;
|
string? totpSecret = null;
|
||||||
Guid id = Guid.NewGuid();
|
Guid id = Guid.CreateVersion7();
|
||||||
UserEntity user = new()
|
UserEntity user = new()
|
||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
@@ -158,7 +158,7 @@ public class SetupApplicationCommandHandler : ICommandHandler<SetupApplicationCo
|
|||||||
return getScheduledJobsResult.Errors;
|
return getScheduledJobsResult.Errors;
|
||||||
foreach (ScheduledJobEntity scheduledJob in getScheduledJobsResult.Value.Data)
|
foreach (ScheduledJobEntity scheduledJob in getScheduledJobsResult.Value.Data)
|
||||||
if (scheduledJob.Status == ScheduledJobStatus.Active)
|
if (scheduledJob.Status == ScheduledJobStatus.Active)
|
||||||
_domainEventsQueue.Enqueue(new ScheduledJobCycleStartedDomainEvent(Guid.NewGuid(), ScheduledJobId.Create(scheduledJob.Id), DateTime.UtcNow));
|
_domainEventsQueue.Enqueue(new ScheduledJobCycleStartedDomainEvent(Guid.CreateVersion7(), ScheduledJobId.Create(scheduledJob.Id), DateTime.UtcNow));
|
||||||
|
|
||||||
// TODO: insert the default admin profile preferences when they are implemented.
|
// TODO: insert the default admin profile preferences when they are implemented.
|
||||||
// If 2FA was enabled during registration, the TOTP secret needs to be delivered to the client unhashed, so it can be displayed.
|
// If 2FA was enabled during registration, the TOTP secret needs to be delivered to the client unhashed, so it can be displayed.
|
||||||
|
|||||||
+1
-1
@@ -101,7 +101,7 @@ public class AddPlaylistEntryCommandHandler : ICommandHandler<AddPlaylistEntryCo
|
|||||||
if (!Playlist.CanContain(getPlaylistResult.Value.Type, PlaylistMediaItemType.MusicTrack))
|
if (!Playlist.CanContain(getPlaylistResult.Value.Type, PlaylistMediaItemType.MusicTrack))
|
||||||
return DomainErrors.Playlists.PlaylistDoesNotAcceptMediaItems;
|
return DomainErrors.Playlists.PlaylistDoesNotAcceptMediaItems;
|
||||||
|
|
||||||
Guid entryId = Guid.NewGuid();
|
Guid entryId = Guid.CreateVersion7();
|
||||||
DateTime updatedOnUtc = DateTime.UtcNow;
|
DateTime updatedOnUtc = DateTime.UtcNow;
|
||||||
Result<PlaylistBulkAddResultDto> addEntryResult = await _unitOfWork.PlaylistRepository
|
Result<PlaylistBulkAddResultDto> addEntryResult = await _unitOfWork.PlaylistRepository
|
||||||
.AddEntriesAsync(playlistId, userId, [trackId], PlaylistMediaItemType.MusicTrack, [entryId], updatedOnUtc, cancellationToken).ConfigureAwait(false);
|
.AddEntriesAsync(playlistId, userId, [trackId], PlaylistMediaItemType.MusicTrack, [entryId], updatedOnUtc, cancellationToken).ConfigureAwait(false);
|
||||||
|
|||||||
+1
-1
@@ -67,7 +67,7 @@ public class UpdateSchedulerDisplayPreferencesCommandHandler : ICommandHandler<U
|
|||||||
// Upsert the display preferences of the scheduler page of the current user.
|
// Upsert the display preferences of the scheduler page of the current user.
|
||||||
SchedulerDisplayPreferencesEntity displayPreferences = new()
|
SchedulerDisplayPreferencesEntity displayPreferences = new()
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
UserId = userId,
|
UserId = userId,
|
||||||
JobTypeFilter = command.JobTypeFilter,
|
JobTypeFilter = command.JobTypeFilter,
|
||||||
DisplayTimeSpan = command.DisplayTimeSpan,
|
DisplayTimeSpan = command.DisplayTimeSpan,
|
||||||
|
|||||||
+1
-1
@@ -118,7 +118,7 @@ public class InstallThemeCommandHandler : ICommandHandler<InstallThemeCommand, R
|
|||||||
{
|
{
|
||||||
themeEntity = new ThemeEntity
|
themeEntity = new ThemeEntity
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
ThemeId = manifest.Id,
|
ThemeId = manifest.Id,
|
||||||
Name = manifest.Name,
|
Name = manifest.Name,
|
||||||
Description = manifest.Description,
|
Description = manifest.Description,
|
||||||
|
|||||||
+1
-1
@@ -82,7 +82,7 @@ public class RegisterUserCommandHandler : ICommandHandler<RegisterUserCommand, R
|
|||||||
|
|
||||||
// Build the account, hashing the password and URI escaping it the same way as the stored form.
|
// Build the account, hashing the password and URI escaping it the same way as the stored form.
|
||||||
string? totpSecret = null;
|
string? totpSecret = null;
|
||||||
Guid id = Guid.NewGuid();
|
Guid id = Guid.CreateVersion7();
|
||||||
UserEntity user = new()
|
UserEntity user = new()
|
||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||||
|
using Microsoft.EntityFrameworkCore.ValueGeneration;
|
||||||
|
using System;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace Lumina.DataAccess.Common.ValueGeneration;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generates time ordered version 7 GUIDs for identifier properties whose values are assigned by the persistence layer.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class GuidV7ValueGenerator : ValueGenerator<Guid>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the generated values are temporary.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>The generated identifiers are stored permanently, so they are not temporary values.</remarks>
|
||||||
|
public override bool GeneratesTemporaryValues => false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generates the next time ordered identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entry">The tracked entity entry that owns the property.</param>
|
||||||
|
/// <returns>A new version 7 GUID.</returns>
|
||||||
|
public override Guid Next(EntityEntry entry)
|
||||||
|
{
|
||||||
|
return Guid.CreateVersion7();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -105,6 +105,8 @@ internal sealed class LibraryScanSnapshotRepository : ILibraryScanSnapshotReposi
|
|||||||
|
|
||||||
// The Id of the inserted rows is generated in SQL as a random 16 byte value formatted as upper case hex (hex(randomblob(16))), which the storage layer parses as a Guid;
|
// The Id of the inserted rows is generated in SQL as a random 16 byte value formatted as upper case hex (hex(randomblob(16))), which the storage layer parses as a Guid;
|
||||||
// generating the Ids in code would defeat the purpose of these single statement bulk inserts.
|
// generating the Ids in code would defeat the purpose of these single statement bulk inserts.
|
||||||
|
// These Ids are random version 4 values rather than the version 7 values used elsewhere, because SQLite cannot produce a version 7 GUID
|
||||||
|
// inside this statement. See docs/technical/architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0020.md for details.
|
||||||
|
|
||||||
// Add an audit entry for every media library scan snapshot item that is no longer present in the current scan, meaning it was deleted from the storage medium.
|
// Add an audit entry for every media library scan snapshot item that is no longer present in the current scan, meaning it was deleted from the storage medium.
|
||||||
const string AUDIT_DELETED_SQL = """
|
const string AUDIT_DELETED_SQL = """
|
||||||
|
|||||||
+1
-1
@@ -87,7 +87,7 @@ internal sealed class MediaContributorRepository : IMediaContributorRepository
|
|||||||
|
|
||||||
MediaContributorEntity contributor = new()
|
MediaContributorEntity contributor = new()
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
DisplayName = displayName,
|
DisplayName = displayName,
|
||||||
LegalName = legalName,
|
LegalName = legalName,
|
||||||
CreatedOnUtc = DateTime.UtcNow,
|
CreatedOnUtc = DateTime.UtcNow,
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ internal sealed class MusicArtworkRepository : IMusicArtworkRepository
|
|||||||
{
|
{
|
||||||
_luminaDbContext.MusicArtwork.Add(new MusicArtworkEntity
|
_luminaDbContext.MusicArtwork.Add(new MusicArtworkEntity
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
OwnerType = ownerType,
|
OwnerType = ownerType,
|
||||||
OwnerId = ownerId,
|
OwnerId = ownerId,
|
||||||
ArtworkType = ArtworkType.Cover,
|
ArtworkType = ArtworkType.Cover,
|
||||||
|
|||||||
@@ -517,7 +517,7 @@ internal sealed class PlaylistRepository : IPlaylistRepository
|
|||||||
if (index > 0)
|
if (index > 0)
|
||||||
insertSql.Append(", ");
|
insertSql.Append(", ");
|
||||||
insertSql.Append($"(@Id{index}, @PlaylistId{index}, @MediaItemId{index}, @mediaItemType, @Position{index}, @createdOnUtc, @createdBy)");
|
insertSql.Append($"(@Id{index}, @PlaylistId{index}, @MediaItemId{index}, @mediaItemType, @Position{index}, @createdOnUtc, @createdBy)");
|
||||||
Guid entryId = entryIds is null ? Guid.NewGuid() : entryIds[offset + index];
|
Guid entryId = entryIds is null ? Guid.CreateVersion7() : entryIds[offset + index];
|
||||||
parameters.Add($"Id{index}", ToStorageId(entryId));
|
parameters.Add($"Id{index}", ToStorageId(entryId));
|
||||||
parameters.Add($"PlaylistId{index}", playlistIdText);
|
parameters.Add($"PlaylistId{index}", playlistIdText);
|
||||||
parameters.Add($"MediaItemId{index}", ToStorageId(mediaItemIds[offset + index]));
|
parameters.Add($"MediaItemId{index}", ToStorageId(mediaItemIds[offset + index]));
|
||||||
@@ -562,6 +562,8 @@ internal sealed class PlaylistRepository : IPlaylistRepository
|
|||||||
{
|
{
|
||||||
// The entry Ids are generated by SQLite in the same upper case, hyphenated TEXT form the Entity Framework provider stores. Generating
|
// The entry Ids are generated by SQLite in the same upper case, hyphenated TEXT form the Entity Framework provider stores. Generating
|
||||||
// them inside the statement is what lets the scope stay a single insert instead of being materialized in C# just to assign Ids.
|
// them inside the statement is what lets the scope stay a single insert instead of being materialized in C# just to assign Ids.
|
||||||
|
// They are random version 4 values rather than the version 7 values used elsewhere, because SQLite cannot produce a version 7 GUID
|
||||||
|
// inside this statement. See docs/technical/architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0020.md for details.
|
||||||
// The positions are computed by the same ordering the artist and album pages use, so the playlist receives catalogue order directly.
|
// The positions are computed by the same ordering the artist and album pages use, so the playlist receives catalogue order directly.
|
||||||
// ROW_NUMBER() produces the dense rank, and multiplying it by POSITION_STEP keeps the stored keys sparse.
|
// ROW_NUMBER() produces the dense rank, and multiplying it by POSITION_STEP keeps the stored keys sparse.
|
||||||
StringBuilder insertSql = new("""
|
StringBuilder insertSql = new("""
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ public class DataSeedService : IDataSeedService
|
|||||||
{
|
{
|
||||||
return new ScheduledJobEntity
|
return new ScheduledJobEntity
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
Name = name,
|
Name = name,
|
||||||
TaskType = taskType,
|
TaskType = taskType,
|
||||||
ScheduleType = scheduleType,
|
ScheduleType = scheduleType,
|
||||||
|
|||||||
@@ -11,7 +11,10 @@ using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
|||||||
using Lumina.Application.Common.DataAccess.Entities.Scheduling;
|
using Lumina.Application.Common.DataAccess.Entities.Scheduling;
|
||||||
using Lumina.Application.Common.DataAccess.Entities.Themes;
|
using Lumina.Application.Common.DataAccess.Entities.Themes;
|
||||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||||
|
using Lumina.DataAccess.Common.ValueGeneration;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using System;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
namespace Lumina.DataAccess.Core.UoW;
|
namespace Lumina.DataAccess.Core.UoW;
|
||||||
@@ -210,6 +213,14 @@ public class LuminaDbContext : DbContext
|
|||||||
// Find all the entity configurations in the assembly and apply them.
|
// Find all the entity configurations in the assembly and apply them.
|
||||||
modelBuilder.ApplyConfigurationsFromAssembly(typeof(LuminaDbContext).Assembly);
|
modelBuilder.ApplyConfigurationsFromAssembly(typeof(LuminaDbContext).Assembly);
|
||||||
|
|
||||||
|
// The relational provider seeds its Guid value generators from Guid.NewGuid, so replace them with a time ordered generator for every
|
||||||
|
// identifier that the persistence layer assigns itself. This covers real keys, such as PermissionEntity.Id, and the shadow keys of
|
||||||
|
// owned collections, such as AlbumReleaseTypes.Id.
|
||||||
|
foreach (IMutableEntityType entityType in modelBuilder.Model.GetEntityTypes())
|
||||||
|
foreach (IMutableProperty property in entityType.GetProperties())
|
||||||
|
if (property.ClrType == typeof(Guid) && property.ValueGenerated == ValueGenerated.OnAdd)
|
||||||
|
property.SetValueGeneratorFactory((generatedProperty, declaringType) => new GuidV7ValueGenerator());
|
||||||
|
|
||||||
base.OnModelCreating(modelBuilder);
|
base.OnModelCreating(modelBuilder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -27,7 +27,7 @@ public sealed class LibraryId : EntityId<Guid>
|
|||||||
/// <returns>The created <see cref="LibraryId"/> instance.</returns>
|
/// <returns>The created <see cref="LibraryId"/> instance.</returns>
|
||||||
public static LibraryId CreateUnique()
|
public static LibraryId CreateUnique()
|
||||||
{
|
{
|
||||||
return new LibraryId(Guid.NewGuid());
|
return new LibraryId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ public sealed class MediaContributorId : EntityId<Guid>
|
|||||||
/// <returns>The created <see cref="MediaContributorId"/> instance.</returns>
|
/// <returns>The created <see cref="MediaContributorId"/> instance.</returns>
|
||||||
public static MediaContributorId CreateUnique()
|
public static MediaContributorId CreateUnique()
|
||||||
{
|
{
|
||||||
return new MediaContributorId(Guid.NewGuid());
|
return new MediaContributorId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ public sealed class AlbumId : EntityId<Guid>
|
|||||||
/// <returns>The created <see cref="AlbumId"/> instance.</returns>
|
/// <returns>The created <see cref="AlbumId"/> instance.</returns>
|
||||||
public static AlbumId CreateUnique()
|
public static AlbumId CreateUnique()
|
||||||
{
|
{
|
||||||
return new AlbumId(Guid.NewGuid());
|
return new AlbumId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ public sealed class ArtistId : EntityId<Guid>
|
|||||||
/// <returns>The created <see cref="ArtistId"/> instance.</returns>
|
/// <returns>The created <see cref="ArtistId"/> instance.</returns>
|
||||||
public static ArtistId CreateUnique()
|
public static ArtistId CreateUnique()
|
||||||
{
|
{
|
||||||
return new ArtistId(Guid.NewGuid());
|
return new ArtistId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ public sealed class TrackId : EntityId<Guid>
|
|||||||
/// <returns>The created <see cref="TrackId"/> instance.</returns>
|
/// <returns>The created <see cref="TrackId"/> instance.</returns>
|
||||||
public static TrackId CreateUnique()
|
public static TrackId CreateUnique()
|
||||||
{
|
{
|
||||||
return new TrackId(Guid.NewGuid());
|
return new TrackId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ public sealed class MediaItemId : EntityId<Guid>
|
|||||||
/// <returns>The created <see cref="MediaItemId"/> instance.</returns>
|
/// <returns>The created <see cref="MediaItemId"/> instance.</returns>
|
||||||
public static MediaItemId CreateUnique()
|
public static MediaItemId CreateUnique()
|
||||||
{
|
{
|
||||||
return new MediaItemId(Guid.NewGuid());
|
return new MediaItemId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ public sealed class UserId : EntityId<Guid>
|
|||||||
/// <returns>The created <see cref="UserId"/> instance.</returns>
|
/// <returns>The created <see cref="UserId"/> instance.</returns>
|
||||||
public static UserId CreateUnique()
|
public static UserId CreateUnique()
|
||||||
{
|
{
|
||||||
return new UserId(Guid.NewGuid());
|
return new UserId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+2
-2
@@ -89,7 +89,7 @@ public sealed class Favorite : AggregateRoot<FavoriteId>
|
|||||||
Optional<DateTime>.None());
|
Optional<DateTime>.None());
|
||||||
|
|
||||||
favorite._domainEvents.Add(new FavoriteAddedDomainEvent(
|
favorite._domainEvents.Add(new FavoriteAddedDomainEvent(
|
||||||
Guid.NewGuid(),
|
Guid.CreateVersion7(),
|
||||||
favorite.Id,
|
favorite.Id,
|
||||||
userId,
|
userId,
|
||||||
mediaItemId,
|
mediaItemId,
|
||||||
@@ -135,7 +135,7 @@ public sealed class Favorite : AggregateRoot<FavoriteId>
|
|||||||
_domainEvents.Clear();
|
_domainEvents.Clear();
|
||||||
IsRemoved = true;
|
IsRemoved = true;
|
||||||
_domainEvents.Add(new FavoriteRemovedDomainEvent(
|
_domainEvents.Add(new FavoriteRemovedDomainEvent(
|
||||||
Guid.NewGuid(),
|
Guid.CreateVersion7(),
|
||||||
Id,
|
Id,
|
||||||
UserId,
|
UserId,
|
||||||
MediaItemId,
|
MediaItemId,
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ public sealed class FavoriteId : EntityId<Guid>
|
|||||||
/// <returns>The created <see cref="FavoriteId"/> instance.</returns>
|
/// <returns>The created <see cref="FavoriteId"/> instance.</returns>
|
||||||
public static FavoriteId CreateUnique()
|
public static FavoriteId CreateUnique()
|
||||||
{
|
{
|
||||||
return new FavoriteId(Guid.NewGuid());
|
return new FavoriteId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+2
-2
@@ -289,7 +289,7 @@ public class Library : AggregateRoot<LibraryId>
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void Save()
|
public void Save()
|
||||||
{
|
{
|
||||||
_domainEvents.Add(new LibrarySavedDomainEvent(Guid.NewGuid(), this, DateTime.UtcNow));
|
_domainEvents.Add(new LibrarySavedDomainEvent(Guid.CreateVersion7(), this, DateTime.UtcNow));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -312,7 +312,7 @@ public class Library : AggregateRoot<LibraryId>
|
|||||||
|
|
||||||
// Only add the delete event if it has not been added already.
|
// Only add the delete event if it has not been added already.
|
||||||
if (!_domainEvents.Any(domainEvent => domainEvent is LibraryDeletedDomainEvent))
|
if (!_domainEvents.Any(domainEvent => domainEvent is LibraryDeletedDomainEvent))
|
||||||
_domainEvents.Add(new LibraryDeletedDomainEvent(Guid.NewGuid(), this, DateTime.UtcNow));
|
_domainEvents.Add(new LibraryDeletedDomainEvent(Guid.CreateVersion7(), this, DateTime.UtcNow));
|
||||||
|
|
||||||
// TODO: perhaps trigger events for removing content related to the removed library (media metadata, etc.).
|
// TODO: perhaps trigger events for removing content related to the removed library (media metadata, etc.).
|
||||||
return Result.Deleted;
|
return Result.Deleted;
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ public sealed class LibraryId : EntityId<Guid>
|
|||||||
/// <returns>The created <see cref="LibraryId"/> instance.</returns>
|
/// <returns>The created <see cref="LibraryId"/> instance.</returns>
|
||||||
public static LibraryId CreateUnique()
|
public static LibraryId CreateUnique()
|
||||||
{
|
{
|
||||||
return new LibraryId(Guid.NewGuid());
|
return new LibraryId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+3
-3
@@ -94,7 +94,7 @@ public class LibraryScan : AggregateRoot<ScanId>
|
|||||||
if (_pastScans.Any(libraryScan => libraryScan.Status == LibraryScanJobStatus.Running || libraryScan.Status == LibraryScanJobStatus.Pending))
|
if (_pastScans.Any(libraryScan => libraryScan.Status == LibraryScanJobStatus.Running || libraryScan.Status == LibraryScanJobStatus.Pending))
|
||||||
return Errors.LibraryScanning.LibraryAlreadyBeingScanned;
|
return Errors.LibraryScanning.LibraryAlreadyBeingScanned;
|
||||||
|
|
||||||
_domainEvents.Add(new LibraryScanQueuedDomainEvent(Guid.NewGuid(), Id, UserId, LibraryId, DateTime.UtcNow));
|
_domainEvents.Add(new LibraryScanQueuedDomainEvent(Guid.CreateVersion7(), Id, UserId, LibraryId, DateTime.UtcNow));
|
||||||
|
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
@@ -114,7 +114,7 @@ public class LibraryScan : AggregateRoot<ScanId>
|
|||||||
if (_pastScans.Any(libraryScan => libraryScan.Status == LibraryScanJobStatus.Running || libraryScan.Status == LibraryScanJobStatus.Pending))
|
if (_pastScans.Any(libraryScan => libraryScan.Status == LibraryScanJobStatus.Running || libraryScan.Status == LibraryScanJobStatus.Pending))
|
||||||
return Errors.LibraryScanning.LibraryAlreadyBeingScanned;
|
return Errors.LibraryScanning.LibraryAlreadyBeingScanned;
|
||||||
|
|
||||||
_domainEvents.Add(new LibraryScanStartedDomainEvent(Guid.NewGuid(), this, DateTime.UtcNow));
|
_domainEvents.Add(new LibraryScanStartedDomainEvent(Guid.CreateVersion7(), this, DateTime.UtcNow));
|
||||||
|
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
@@ -145,7 +145,7 @@ public class LibraryScan : AggregateRoot<ScanId>
|
|||||||
else
|
else
|
||||||
return Errors.LibraryScanning.CanOnlyCancelPendingOrRunningScans;
|
return Errors.LibraryScanning.CanOnlyCancelPendingOrRunningScans;
|
||||||
|
|
||||||
_domainEvents.Add(new LibraryScanCancelledDomainEvent(Guid.NewGuid(), Id, LibraryId, DateTime.UtcNow));
|
_domainEvents.Add(new LibraryScanCancelledDomainEvent(Guid.CreateVersion7(), Id, LibraryId, DateTime.UtcNow));
|
||||||
|
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ public sealed class ScanId : EntityId<Guid>
|
|||||||
/// <returns>The created <see cref="ScanId"/> instance.</returns>
|
/// <returns>The created <see cref="ScanId"/> instance.</returns>
|
||||||
public static ScanId CreateUnique()
|
public static ScanId CreateUnique()
|
||||||
{
|
{
|
||||||
return new ScanId(Guid.NewGuid());
|
return new ScanId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ public sealed class LibraryId : EntityId<Guid>
|
|||||||
/// <returns>The created <see cref="LibraryId"/> instance.</returns>
|
/// <returns>The created <see cref="LibraryId"/> instance.</returns>
|
||||||
public static LibraryId CreateUnique()
|
public static LibraryId CreateUnique()
|
||||||
{
|
{
|
||||||
return new LibraryId(Guid.NewGuid());
|
return new LibraryId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ public sealed class MediaItemId : EntityId<Guid>
|
|||||||
/// <returns>The created <see cref="MediaItemId"/> instance.</returns>
|
/// <returns>The created <see cref="MediaItemId"/> instance.</returns>
|
||||||
public static MediaItemId CreateUnique()
|
public static MediaItemId CreateUnique()
|
||||||
{
|
{
|
||||||
return new MediaItemId(Guid.NewGuid());
|
return new MediaItemId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ public sealed class UserId : EntityId<Guid>
|
|||||||
/// <returns>The created <see cref="UserId"/> instance.</returns>
|
/// <returns>The created <see cref="UserId"/> instance.</returns>
|
||||||
public static UserId CreateUnique()
|
public static UserId CreateUnique()
|
||||||
{
|
{
|
||||||
return new UserId(Guid.NewGuid());
|
return new UserId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+6
-6
@@ -171,7 +171,7 @@ public sealed class MediaConsumptionRecord : AggregateRoot<MediaConsumptionRecor
|
|||||||
0);
|
0);
|
||||||
|
|
||||||
record._domainEvents.Add(new MediaConsumptionStartedDomainEvent(
|
record._domainEvents.Add(new MediaConsumptionStartedDomainEvent(
|
||||||
Guid.NewGuid(),
|
Guid.CreateVersion7(),
|
||||||
record.Id,
|
record.Id,
|
||||||
userId,
|
userId,
|
||||||
libraryId,
|
libraryId,
|
||||||
@@ -216,7 +216,7 @@ public sealed class MediaConsumptionRecord : AggregateRoot<MediaConsumptionRecor
|
|||||||
0);
|
0);
|
||||||
|
|
||||||
record._domainEvents.Add(new MediaConsumptionStartedDomainEvent(
|
record._domainEvents.Add(new MediaConsumptionStartedDomainEvent(
|
||||||
Guid.NewGuid(),
|
Guid.CreateVersion7(),
|
||||||
record.Id,
|
record.Id,
|
||||||
userId,
|
userId,
|
||||||
libraryId,
|
libraryId,
|
||||||
@@ -224,7 +224,7 @@ public sealed class MediaConsumptionRecord : AggregateRoot<MediaConsumptionRecor
|
|||||||
mediaKind,
|
mediaKind,
|
||||||
occurredOnUtc));
|
occurredOnUtc));
|
||||||
record._domainEvents.Add(new MediaConsumptionCompletedDomainEvent(
|
record._domainEvents.Add(new MediaConsumptionCompletedDomainEvent(
|
||||||
Guid.NewGuid(),
|
Guid.CreateVersion7(),
|
||||||
record.Id,
|
record.Id,
|
||||||
userId,
|
userId,
|
||||||
libraryId,
|
libraryId,
|
||||||
@@ -341,7 +341,7 @@ public sealed class MediaConsumptionRecord : AggregateRoot<MediaConsumptionRecor
|
|||||||
LastActivityOnUtc = occurredOnUtc;
|
LastActivityOnUtc = occurredOnUtc;
|
||||||
UpdatedOnUtc = Optional<DateTime>.Some(occurredOnUtc);
|
UpdatedOnUtc = Optional<DateTime>.Some(occurredOnUtc);
|
||||||
_domainEvents.Add(new MediaConsumptionProgressedDomainEvent(
|
_domainEvents.Add(new MediaConsumptionProgressedDomainEvent(
|
||||||
Guid.NewGuid(),
|
Guid.CreateVersion7(),
|
||||||
Id,
|
Id,
|
||||||
UserId,
|
UserId,
|
||||||
LibraryId,
|
LibraryId,
|
||||||
@@ -393,7 +393,7 @@ public sealed class MediaConsumptionRecord : AggregateRoot<MediaConsumptionRecor
|
|||||||
LastActivityOnUtc = occurredOnUtc;
|
LastActivityOnUtc = occurredOnUtc;
|
||||||
UpdatedOnUtc = Optional<DateTime>.Some(occurredOnUtc);
|
UpdatedOnUtc = Optional<DateTime>.Some(occurredOnUtc);
|
||||||
_domainEvents.Add(new MediaConsumptionCompletedDomainEvent(
|
_domainEvents.Add(new MediaConsumptionCompletedDomainEvent(
|
||||||
Guid.NewGuid(),
|
Guid.CreateVersion7(),
|
||||||
Id,
|
Id,
|
||||||
UserId,
|
UserId,
|
||||||
LibraryId,
|
LibraryId,
|
||||||
@@ -445,7 +445,7 @@ public sealed class MediaConsumptionRecord : AggregateRoot<MediaConsumptionRecor
|
|||||||
LastActivityOnUtc = occurredOnUtc;
|
LastActivityOnUtc = occurredOnUtc;
|
||||||
UpdatedOnUtc = Optional<DateTime>.Some(occurredOnUtc);
|
UpdatedOnUtc = Optional<DateTime>.Some(occurredOnUtc);
|
||||||
_domainEvents.Add(new MediaConsumptionStoppedDomainEvent(
|
_domainEvents.Add(new MediaConsumptionStoppedDomainEvent(
|
||||||
Guid.NewGuid(),
|
Guid.CreateVersion7(),
|
||||||
Id,
|
Id,
|
||||||
UserId,
|
UserId,
|
||||||
LibraryId,
|
LibraryId,
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ public sealed class MediaConsumptionRecordId : EntityId<Guid>
|
|||||||
/// <returns>The created <see cref="MediaConsumptionRecordId"/> instance.</returns>
|
/// <returns>The created <see cref="MediaConsumptionRecordId"/> instance.</returns>
|
||||||
public static MediaConsumptionRecordId CreateUnique()
|
public static MediaConsumptionRecordId CreateUnique()
|
||||||
{
|
{
|
||||||
return new MediaConsumptionRecordId(Guid.NewGuid());
|
return new MediaConsumptionRecordId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ public sealed class MediaResumePointId : EntityId<Guid>
|
|||||||
/// <returns>The created <see cref="MediaResumePointId"/> instance.</returns>
|
/// <returns>The created <see cref="MediaResumePointId"/> instance.</returns>
|
||||||
public static MediaResumePointId CreateUnique()
|
public static MediaResumePointId CreateUnique()
|
||||||
{
|
{
|
||||||
return new MediaResumePointId(Guid.NewGuid());
|
return new MediaResumePointId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+1
-1
@@ -26,7 +26,7 @@ public sealed class MediaContributorId : EntityId<Guid>
|
|||||||
public static MediaContributorId CreateUnique()
|
public static MediaContributorId CreateUnique()
|
||||||
{
|
{
|
||||||
// TODO: enforce invariants.
|
// TODO: enforce invariants.
|
||||||
return new MediaContributorId(Guid.NewGuid());
|
return new MediaContributorId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+1
-1
@@ -30,7 +30,7 @@ public sealed class MediaItemId : EntityId<Guid>
|
|||||||
/// <returns>The created <see cref="MediaItemId"/> instance.</returns>
|
/// <returns>The created <see cref="MediaItemId"/> instance.</returns>
|
||||||
public static MediaItemId CreateUnique()
|
public static MediaItemId CreateUnique()
|
||||||
{
|
{
|
||||||
return new MediaItemId(Guid.NewGuid());
|
return new MediaItemId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ public sealed class UserId : EntityId<Guid>
|
|||||||
/// <returns>The created <see cref="UserId"/> instance.</returns>
|
/// <returns>The created <see cref="UserId"/> instance.</returns>
|
||||||
public static UserId CreateUnique()
|
public static UserId CreateUnique()
|
||||||
{
|
{
|
||||||
return new UserId(Guid.NewGuid());
|
return new UserId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+3
-3
@@ -108,7 +108,7 @@ public sealed class Playlist : AggregateRoot<PlaylistId>
|
|||||||
Optional<DateTime>.None());
|
Optional<DateTime>.None());
|
||||||
|
|
||||||
playlist._domainEvents.Add(new PlaylistCreatedDomainEvent(
|
playlist._domainEvents.Add(new PlaylistCreatedDomainEvent(
|
||||||
Guid.NewGuid(),
|
Guid.CreateVersion7(),
|
||||||
playlist.Id,
|
playlist.Id,
|
||||||
userId,
|
userId,
|
||||||
name,
|
name,
|
||||||
@@ -168,7 +168,7 @@ public sealed class Playlist : AggregateRoot<PlaylistId>
|
|||||||
Description = description;
|
Description = description;
|
||||||
DateTime occurredOnUtc = DateTime.UtcNow;
|
DateTime occurredOnUtc = DateTime.UtcNow;
|
||||||
_domainEvents.Add(new PlaylistDetailsUpdatedDomainEvent(
|
_domainEvents.Add(new PlaylistDetailsUpdatedDomainEvent(
|
||||||
Guid.NewGuid(),
|
Guid.CreateVersion7(),
|
||||||
Id,
|
Id,
|
||||||
UserId,
|
UserId,
|
||||||
name,
|
name,
|
||||||
@@ -189,7 +189,7 @@ public sealed class Playlist : AggregateRoot<PlaylistId>
|
|||||||
_domainEvents.Clear();
|
_domainEvents.Clear();
|
||||||
IsDeleted = true;
|
IsDeleted = true;
|
||||||
_domainEvents.Add(new PlaylistDeletedDomainEvent(
|
_domainEvents.Add(new PlaylistDeletedDomainEvent(
|
||||||
Guid.NewGuid(),
|
Guid.CreateVersion7(),
|
||||||
Id,
|
Id,
|
||||||
UserId,
|
UserId,
|
||||||
DateTime.UtcNow));
|
DateTime.UtcNow));
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ public sealed class PlaylistEntryId : EntityId<Guid>
|
|||||||
/// <returns>The created <see cref="PlaylistEntryId"/> instance.</returns>
|
/// <returns>The created <see cref="PlaylistEntryId"/> instance.</returns>
|
||||||
public static PlaylistEntryId CreateUnique()
|
public static PlaylistEntryId CreateUnique()
|
||||||
{
|
{
|
||||||
return new PlaylistEntryId(Guid.NewGuid());
|
return new PlaylistEntryId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ public sealed class PlaylistId : EntityId<Guid>
|
|||||||
/// <returns>The created <see cref="PlaylistId"/> instance.</returns>
|
/// <returns>The created <see cref="PlaylistId"/> instance.</returns>
|
||||||
public static PlaylistId CreateUnique()
|
public static PlaylistId CreateUnique()
|
||||||
{
|
{
|
||||||
return new PlaylistId(Guid.NewGuid());
|
return new PlaylistId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ public sealed class UserId : EntityId<Guid>
|
|||||||
/// <returns>The created <see cref="UserId"/> instance.</returns>
|
/// <returns>The created <see cref="UserId"/> instance.</returns>
|
||||||
public static UserId CreateUnique()
|
public static UserId CreateUnique()
|
||||||
{
|
{
|
||||||
return new UserId(Guid.NewGuid());
|
return new UserId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+9
-9
@@ -125,7 +125,7 @@ public class ScheduledJob : AggregateRoot<ScheduledJobId>
|
|||||||
{
|
{
|
||||||
if (Status != ScheduledJobStatus.Added)
|
if (Status != ScheduledJobStatus.Added)
|
||||||
return Errors.Scheduling.ScheduledJobCycleAlreadyStarted;
|
return Errors.Scheduling.ScheduledJobCycleAlreadyStarted;
|
||||||
_domainEvents.Add(new ScheduledJobAddedDomainEvent(Guid.NewGuid(), Id, DateTime.UtcNow));
|
_domainEvents.Add(new ScheduledJobAddedDomainEvent(Guid.CreateVersion7(), Id, DateTime.UtcNow));
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +139,7 @@ public class ScheduledJob : AggregateRoot<ScheduledJobId>
|
|||||||
return Errors.Scheduling.ScheduledJobCycleAlreadyStarted;
|
return Errors.Scheduling.ScheduledJobCycleAlreadyStarted;
|
||||||
|
|
||||||
Status = ScheduledJobStatus.Active;
|
Status = ScheduledJobStatus.Active;
|
||||||
_domainEvents.Add(new ScheduledJobCycleStartedDomainEvent(Guid.NewGuid(), Id, DateTime.UtcNow));
|
_domainEvents.Add(new ScheduledJobCycleStartedDomainEvent(Guid.CreateVersion7(), Id, DateTime.UtcNow));
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,10 +159,10 @@ public class ScheduledJob : AggregateRoot<ScheduledJobId>
|
|||||||
if (previousStatus == ScheduledJobStatus.Running)
|
if (previousStatus == ScheduledJobStatus.Running)
|
||||||
{
|
{
|
||||||
LastCompletedOnUtc = Optional<DateTime>.Some(DateTime.UtcNow);
|
LastCompletedOnUtc = Optional<DateTime>.Some(DateTime.UtcNow);
|
||||||
_domainEvents.Add(new ScheduledJobExecutionStoppedDomainEvent(Guid.NewGuid(), Id, DateTime.UtcNow));
|
_domainEvents.Add(new ScheduledJobExecutionStoppedDomainEvent(Guid.CreateVersion7(), Id, DateTime.UtcNow));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
_domainEvents.Add(new ScheduledJobCycleStoppedDomainEvent(Guid.NewGuid(), Id, DateTime.UtcNow));
|
_domainEvents.Add(new ScheduledJobCycleStoppedDomainEvent(Guid.CreateVersion7(), Id, DateTime.UtcNow));
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,7 +174,7 @@ public class ScheduledJob : AggregateRoot<ScheduledJobId>
|
|||||||
{
|
{
|
||||||
if (Status == ScheduledJobStatus.Running)
|
if (Status == ScheduledJobStatus.Running)
|
||||||
return Errors.Scheduling.ScheduledJobAlreadyRunning;
|
return Errors.Scheduling.ScheduledJobAlreadyRunning;
|
||||||
_domainEvents.Add(new ScheduledJobFiredDomainEvent(Guid.NewGuid(), Id, DateTime.UtcNow));
|
_domainEvents.Add(new ScheduledJobFiredDomainEvent(Guid.CreateVersion7(), Id, DateTime.UtcNow));
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,7 +184,7 @@ public class ScheduledJob : AggregateRoot<ScheduledJobId>
|
|||||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||||
public Result<Success> Remove()
|
public Result<Success> Remove()
|
||||||
{
|
{
|
||||||
_domainEvents.Add(new ScheduledJobRemovedDomainEvent(Guid.NewGuid(), Id, DateTime.UtcNow));
|
_domainEvents.Add(new ScheduledJobRemovedDomainEvent(Guid.CreateVersion7(), Id, DateTime.UtcNow));
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,11 +198,11 @@ public class ScheduledJob : AggregateRoot<ScheduledJobId>
|
|||||||
if (Status == ScheduledJobStatus.Running)
|
if (Status == ScheduledJobStatus.Running)
|
||||||
return Errors.Scheduling.ScheduledJobAlreadyRunning;
|
return Errors.Scheduling.ScheduledJobAlreadyRunning;
|
||||||
|
|
||||||
Guid runId = Guid.NewGuid();
|
Guid runId = Guid.CreateVersion7();
|
||||||
_currentExecutionRunId = Optional<Guid>.Some(runId);
|
_currentExecutionRunId = Optional<Guid>.Some(runId);
|
||||||
Status = ScheduledJobStatus.Running;
|
Status = ScheduledJobStatus.Running;
|
||||||
LastStartedOnUtc = Optional<DateTime>.Some(DateTime.UtcNow);
|
LastStartedOnUtc = Optional<DateTime>.Some(DateTime.UtcNow);
|
||||||
_domainEvents.Add(new ScheduledJobExecutionStartedDomainEvent(Guid.NewGuid(), Id, runId, TaskType, isCycleRun, DateTime.UtcNow));
|
_domainEvents.Add(new ScheduledJobExecutionStartedDomainEvent(Guid.CreateVersion7(), Id, runId, TaskType, isCycleRun, DateTime.UtcNow));
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,7 +223,7 @@ public class ScheduledJob : AggregateRoot<ScheduledJobId>
|
|||||||
// A cycle run returns the scheduled job to its active state, where it waits for the next execution; a one time execution finishes the scheduled job.
|
// A cycle run returns the scheduled job to its active state, where it waits for the next execution; a one time execution finishes the scheduled job.
|
||||||
Status = isCycleRun ? ScheduledJobStatus.Active : ScheduledJobStatus.Completed;
|
Status = isCycleRun ? ScheduledJobStatus.Active : ScheduledJobStatus.Completed;
|
||||||
LastCompletedOnUtc = Optional<DateTime>.Some(DateTime.UtcNow);
|
LastCompletedOnUtc = Optional<DateTime>.Some(DateTime.UtcNow);
|
||||||
_domainEvents.Add(new ScheduledJobExecutionCompletedDomainEvent(Guid.NewGuid(), Id, runId, TaskType, isCycleRun, DateTime.UtcNow));
|
_domainEvents.Add(new ScheduledJobExecutionCompletedDomainEvent(Guid.CreateVersion7(), Id, runId, TaskType, isCycleRun, DateTime.UtcNow));
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -27,7 +27,7 @@ public sealed class ScheduledJobId : EntityId<Guid>
|
|||||||
/// <returns>The created <see cref="ScheduledJobId"/> instance.</returns>
|
/// <returns>The created <see cref="ScheduledJobId"/> instance.</returns>
|
||||||
public static ScheduledJobId CreateUnique()
|
public static ScheduledJobId CreateUnique()
|
||||||
{
|
{
|
||||||
return new ScheduledJobId(Guid.NewGuid());
|
return new ScheduledJobId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ public sealed class UserId : EntityId<Guid>
|
|||||||
/// <returns>The created <see cref="UserId"/> instance.</returns>
|
/// <returns>The created <see cref="UserId"/> instance.</returns>
|
||||||
public static UserId CreateUnique()
|
public static UserId CreateUnique()
|
||||||
{
|
{
|
||||||
return new UserId(Guid.NewGuid());
|
return new UserId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ public sealed class UserSettingsId : EntityId<Guid>
|
|||||||
/// <returns>The created <see cref="UserSettingsId"/> instance.</returns>
|
/// <returns>The created <see cref="UserSettingsId"/> instance.</returns>
|
||||||
public static UserSettingsId CreateUnique()
|
public static UserSettingsId CreateUnique()
|
||||||
{
|
{
|
||||||
return new UserSettingsId(Guid.NewGuid());
|
return new UserSettingsId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@ public sealed class MovieId : EntityId<Guid>
|
|||||||
public static MovieId CreateUnique()
|
public static MovieId CreateUnique()
|
||||||
{
|
{
|
||||||
// TODO: enforce invariants.
|
// TODO: enforce invariants.
|
||||||
return new MovieId(Guid.NewGuid());
|
return new MovieId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+1
-1
@@ -26,7 +26,7 @@ public sealed class EpisodeId : EntityId<Guid>
|
|||||||
public static EpisodeId CreateUnique()
|
public static EpisodeId CreateUnique()
|
||||||
{
|
{
|
||||||
// TODO: enforce invariants.
|
// TODO: enforce invariants.
|
||||||
return new EpisodeId(Guid.NewGuid());
|
return new EpisodeId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+1
-1
@@ -26,7 +26,7 @@ public sealed class SeasonId : EntityId<Guid>
|
|||||||
public static SeasonId CreateUnique()
|
public static SeasonId CreateUnique()
|
||||||
{
|
{
|
||||||
// TODO: enforce invariants.
|
// TODO: enforce invariants.
|
||||||
return new SeasonId(Guid.NewGuid());
|
return new SeasonId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+1
-1
@@ -26,7 +26,7 @@ public sealed class TvShowId : EntityId<Guid>
|
|||||||
public static TvShowId CreateUnique()
|
public static TvShowId CreateUnique()
|
||||||
{
|
{
|
||||||
// TODO: enforce invariants.
|
// TODO: enforce invariants.
|
||||||
return new TvShowId(Guid.NewGuid());
|
return new TvShowId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ public sealed class BookId : EntityId<Guid>
|
|||||||
/// <returns>The created <see cref="BookId"/> instance.</returns>
|
/// <returns>The created <see cref="BookId"/> instance.</returns>
|
||||||
public static BookId CreateUnique()
|
public static BookId CreateUnique()
|
||||||
{
|
{
|
||||||
return new BookId(Guid.NewGuid());
|
return new BookId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+1
-1
@@ -33,7 +33,7 @@ public sealed class BookSeriesId : ValueObject
|
|||||||
/// <returns>The created <see cref="BookSeriesId"/> instance.</returns>
|
/// <returns>The created <see cref="BookSeriesId"/> instance.</returns>
|
||||||
public static BookSeriesId CreateUnique()
|
public static BookSeriesId CreateUnique()
|
||||||
{
|
{
|
||||||
return new BookSeriesId(Guid.NewGuid());
|
return new BookSeriesId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ public sealed class LibraryId : EntityId<Guid>
|
|||||||
/// <returns>The created <see cref="LibraryId"/> instance.</returns>
|
/// <returns>The created <see cref="LibraryId"/> instance.</returns>
|
||||||
public static LibraryId CreateUnique()
|
public static LibraryId CreateUnique()
|
||||||
{
|
{
|
||||||
return new LibraryId(Guid.NewGuid());
|
return new LibraryId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ public sealed class MediaContributorId : EntityId<Guid>
|
|||||||
/// <returns>The created <see cref="MediaContributorId"/> instance.</returns>
|
/// <returns>The created <see cref="MediaContributorId"/> instance.</returns>
|
||||||
public static MediaContributorId CreateUnique()
|
public static MediaContributorId CreateUnique()
|
||||||
{
|
{
|
||||||
return new MediaContributorId(Guid.NewGuid());
|
return new MediaContributorId(Guid.CreateVersion7());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+1
@@ -61,6 +61,7 @@ internal sealed class PlaybackDeliveryHandleService : IPlaybackDeliveryHandleSer
|
|||||||
EnforceGlobalLimit();
|
EnforceGlobalLimit();
|
||||||
|
|
||||||
// The handle is a random opaque value, not a derived one, so it cannot be computed from the track or the file by a caller.
|
// The handle is a random opaque value, not a derived one, so it cannot be computed from the track or the file by a caller.
|
||||||
|
// It stays a version 4 GUID on purpose: version 7 embeds the creation time and leaves fewer random bits for an unguessable handle.
|
||||||
string deliveryId = Guid.NewGuid().ToString("N");
|
string deliveryId = Guid.NewGuid().ToString("N");
|
||||||
DateTimeOffset expiresAtUtc = now.Add(s_deliveryLifetime);
|
DateTimeOffset expiresAtUtc = now.Add(s_deliveryLifetime);
|
||||||
_deliveries[deliveryId] = new StoredDelivery(delivery, signature, expiresAtUtc);
|
_deliveries[deliveryId] = new StoredDelivery(delivery, signature, expiresAtUtc);
|
||||||
|
|||||||
+4
-4
@@ -169,7 +169,7 @@ internal sealed class MusicFileSystemDiscoveryJob : MediaLibraryScanJob, IMusicF
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This job finished, increment the number of processed jobs progress.
|
// This job finished, increment the number of processed jobs progress.
|
||||||
await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.CreateVersion7(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||||
Status = LibraryScanJobStatus.Completed;
|
Status = LibraryScanJobStatus.Completed;
|
||||||
|
|
||||||
// Call each linked child with the obtained payload.
|
// Call each linked child with the obtained payload.
|
||||||
@@ -248,7 +248,7 @@ internal sealed class MusicFileSystemDiscoveryJob : MediaLibraryScanJob, IMusicF
|
|||||||
|
|
||||||
fingerprintBatch.Add(new DirectoryScanFingerprintEntity()
|
fingerprintBatch.Add(new DirectoryScanFingerprintEntity()
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
LibraryId = LibraryId.Value,
|
LibraryId = LibraryId.Value,
|
||||||
Path = currentDirectory.Path,
|
Path = currentDirectory.Path,
|
||||||
LastWriteTimeUtc = currentLastWriteTimeUtc
|
LastWriteTimeUtc = currentLastWriteTimeUtc
|
||||||
@@ -386,7 +386,7 @@ internal sealed class MusicFileSystemDiscoveryJob : MediaLibraryScanJob, IMusicF
|
|||||||
|
|
||||||
return new LibraryScanStagingResultsEntity()
|
return new LibraryScanStagingResultsEntity()
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
LibraryScanId = ScanId.Value,
|
LibraryScanId = ScanId.Value,
|
||||||
Path = filePath.Path,
|
Path = filePath.Path,
|
||||||
Size = size,
|
Size = size,
|
||||||
@@ -414,7 +414,7 @@ internal sealed class MusicFileSystemDiscoveryJob : MediaLibraryScanJob, IMusicF
|
|||||||
return scanJobProgressResult.Errors;
|
return scanJobProgressResult.Errors;
|
||||||
|
|
||||||
await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent(
|
await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent(
|
||||||
Guid.NewGuid(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
Guid.CreateVersion7(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -626,7 +626,7 @@ internal sealed class MusicMediaLibraryScanArtworkEnricher : IMediaLibraryScanAr
|
|||||||
{
|
{
|
||||||
return new MusicArtworkEntity
|
return new MusicArtworkEntity
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
OwnerType = ownerType,
|
OwnerType = ownerType,
|
||||||
OwnerId = ownerId,
|
OwnerId = ownerId,
|
||||||
ArtworkType = artworkType,
|
ArtworkType = artworkType,
|
||||||
@@ -659,7 +659,7 @@ internal sealed class MusicMediaLibraryScanArtworkEnricher : IMediaLibraryScanAr
|
|||||||
return scanJobProgressResult.Errors;
|
return scanJobProgressResult.Errors;
|
||||||
|
|
||||||
await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent(
|
await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent(
|
||||||
Guid.NewGuid(), libraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
Guid.CreateVersion7(), libraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -257,7 +257,7 @@ internal sealed class MusicMediaLibraryScanItemMaterializer : IMediaLibraryScanI
|
|||||||
{
|
{
|
||||||
return new ArtistEntity
|
return new ArtistEntity
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
LibraryId = libraryId,
|
LibraryId = libraryId,
|
||||||
Name = name,
|
Name = name,
|
||||||
MusicBrainzArtistId = musicBrainzArtistId,
|
MusicBrainzArtistId = musicBrainzArtistId,
|
||||||
@@ -284,7 +284,7 @@ internal sealed class MusicMediaLibraryScanItemMaterializer : IMediaLibraryScanI
|
|||||||
MusicLibraryScanItemMetadataEntity firstStagedItem = stagedItems[0];
|
MusicLibraryScanItemMetadataEntity firstStagedItem = stagedItems[0];
|
||||||
return new AlbumEntity
|
return new AlbumEntity
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
ArtistId = artistId,
|
ArtistId = artistId,
|
||||||
LibraryId = libraryId,
|
LibraryId = libraryId,
|
||||||
Title = title,
|
Title = title,
|
||||||
@@ -311,7 +311,7 @@ internal sealed class MusicMediaLibraryScanItemMaterializer : IMediaLibraryScanI
|
|||||||
{
|
{
|
||||||
return new TrackEntity
|
return new TrackEntity
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
AlbumId = albumId,
|
AlbumId = albumId,
|
||||||
LibraryId = libraryId,
|
LibraryId = libraryId,
|
||||||
Path = stagedItem.Path,
|
Path = stagedItem.Path,
|
||||||
|
|||||||
+1
-1
@@ -586,7 +586,7 @@ internal sealed class MusicMediaLibraryScanMetadataEnricher : IMediaLibraryScanM
|
|||||||
return scanJobProgressResult.Errors;
|
return scanJobProgressResult.Errors;
|
||||||
|
|
||||||
await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent(
|
await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent(
|
||||||
Guid.NewGuid(), libraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
Guid.CreateVersion7(), libraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -154,7 +154,7 @@ internal sealed class MusicMetadataExtractionJob : MediaLibraryScanJob, IMusicMe
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This job finished, increment the number of processed jobs progress.
|
// This job finished, increment the number of processed jobs progress.
|
||||||
await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.CreateVersion7(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||||
Status = LibraryScanJobStatus.Completed;
|
Status = LibraryScanJobStatus.Completed;
|
||||||
|
|
||||||
// Call each linked child with the obtained payload.
|
// Call each linked child with the obtained payload.
|
||||||
@@ -319,7 +319,7 @@ internal sealed class MusicMetadataExtractionJob : MediaLibraryScanJob, IMusicMe
|
|||||||
|
|
||||||
return new MusicLibraryScanItemMetadataEntity
|
return new MusicLibraryScanItemMetadataEntity
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
LibraryScanId = ScanId.Value,
|
LibraryScanId = ScanId.Value,
|
||||||
LibraryId = LibraryId.Value,
|
LibraryId = LibraryId.Value,
|
||||||
Path = path,
|
Path = path,
|
||||||
@@ -563,7 +563,7 @@ internal sealed class MusicMetadataExtractionJob : MediaLibraryScanJob, IMusicMe
|
|||||||
return scanJobProgressResult.Errors;
|
return scanJobProgressResult.Errors;
|
||||||
|
|
||||||
await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent(
|
await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent(
|
||||||
Guid.NewGuid(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
Guid.CreateVersion7(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -76,11 +76,11 @@ internal sealed class MediaLibraryScanArtworkEnrichmentJob : MediaLibraryScanJob
|
|||||||
await artworkEnricher.EnrichAsync(LibraryId, ScanId, UserId, cancellationToken).ConfigureAwait(false);
|
await artworkEnricher.EnrichAsync(LibraryId, ScanId, UserId, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
// Increment the number of completed jobs progress.
|
// Increment the number of completed jobs progress.
|
||||||
await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.CreateVersion7(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||||
Status = LibraryScanJobStatus.Completed;
|
Status = LibraryScanJobStatus.Completed;
|
||||||
// When this job has no linked children, it is the last job in the directed acyclic job graph, and the scan is completed.
|
// When this job has no linked children, it is the last job in the directed acyclic job graph, and the scan is completed.
|
||||||
if (Children.Count == 0)
|
if (Children.Count == 0)
|
||||||
await domainEventPublisher.PublishAsync(new LibraryScanFinishedDomainEvent(Guid.NewGuid(), compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
await domainEventPublisher.PublishAsync(new LibraryScanFinishedDomainEvent(Guid.CreateVersion7(), compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
// Call each linked child with the obtained payload.
|
// Call each linked child with the obtained payload.
|
||||||
foreach (IMediaLibraryScanJob child in Children)
|
foreach (IMediaLibraryScanJob child in Children)
|
||||||
|
|||||||
+2
-2
@@ -76,7 +76,7 @@ internal sealed class MediaLibraryScanDiffJob : MediaLibraryScanJob, IMediaLibra
|
|||||||
throw new InvalidOperationException(publishJobProgressResult.FirstError.Description);
|
throw new InvalidOperationException(publishJobProgressResult.FirstError.Description);
|
||||||
|
|
||||||
// This job finished, increment the number of processed jobs progress.
|
// This job finished, increment the number of processed jobs progress.
|
||||||
await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.CreateVersion7(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||||
Status = LibraryScanJobStatus.Completed;
|
Status = LibraryScanJobStatus.Completed;
|
||||||
|
|
||||||
// Call each linked child with the obtained payload.
|
// Call each linked child with the obtained payload.
|
||||||
@@ -112,7 +112,7 @@ internal sealed class MediaLibraryScanDiffJob : MediaLibraryScanJob, IMediaLibra
|
|||||||
return scanJobProgressResult.Errors;
|
return scanJobProgressResult.Errors;
|
||||||
|
|
||||||
await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent(
|
await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent(
|
||||||
Guid.NewGuid(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
Guid.CreateVersion7(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -132,7 +132,7 @@ internal sealed class MediaLibraryScanHashJob : MediaLibraryScanJob, IMediaLibra
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This job finished, increment the number of processed jobs progress.
|
// This job finished, increment the number of processed jobs progress.
|
||||||
await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.CreateVersion7(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||||
Status = LibraryScanJobStatus.Completed;
|
Status = LibraryScanJobStatus.Completed;
|
||||||
|
|
||||||
// Call each linked child with the obtained payload.
|
// Call each linked child with the obtained payload.
|
||||||
@@ -168,7 +168,7 @@ internal sealed class MediaLibraryScanHashJob : MediaLibraryScanJob, IMediaLibra
|
|||||||
return scanJobProgressResult.Errors;
|
return scanJobProgressResult.Errors;
|
||||||
|
|
||||||
await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent(
|
await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent(
|
||||||
Guid.NewGuid(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
Guid.CreateVersion7(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -76,11 +76,11 @@ internal sealed class MediaLibraryScanMetadataEnrichmentJob : MediaLibraryScanJo
|
|||||||
await metadataEnricher.EnrichAsync(LibraryId, ScanId, UserId, cancellationToken).ConfigureAwait(false);
|
await metadataEnricher.EnrichAsync(LibraryId, ScanId, UserId, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
// Increment the number of completed jobs progress.
|
// Increment the number of completed jobs progress.
|
||||||
await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.CreateVersion7(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||||
Status = LibraryScanJobStatus.Completed;
|
Status = LibraryScanJobStatus.Completed;
|
||||||
// When this job has no linked children, it is the last job in the directed acyclic job graph, and the scan is completed.
|
// When this job has no linked children, it is the last job in the directed acyclic job graph, and the scan is completed.
|
||||||
if (Children.Count == 0)
|
if (Children.Count == 0)
|
||||||
await domainEventPublisher.PublishAsync(new LibraryScanFinishedDomainEvent(Guid.NewGuid(), compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
await domainEventPublisher.PublishAsync(new LibraryScanFinishedDomainEvent(Guid.CreateVersion7(), compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
// Call each linked child with the obtained payload.
|
// Call each linked child with the obtained payload.
|
||||||
foreach (IMediaLibraryScanJob child in Children)
|
foreach (IMediaLibraryScanJob child in Children)
|
||||||
|
|||||||
+4
-4
@@ -147,7 +147,7 @@ internal sealed class MediaLibraryScanProviderConfigurationInvalidationJob : Med
|
|||||||
library.ArtworkProvidersConfigurationFingerprint = artworkFingerprint;
|
library.ArtworkProvidersConfigurationFingerprint = artworkFingerprint;
|
||||||
library.PathTemplateFingerprint = pathTemplateFingerprint;
|
library.PathTemplateFingerprint = pathTemplateFingerprint;
|
||||||
library.UpdatedOnUtc = DateTime.UtcNow;
|
library.UpdatedOnUtc = DateTime.UtcNow;
|
||||||
library.UpdatedBy = Guid.NewGuid();
|
library.UpdatedBy = Guid.CreateVersion7();
|
||||||
|
|
||||||
Result<Success> saveChangesResult = await unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
Result<Success> saveChangesResult = await unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||||
if (saveChangesResult.IsFailure)
|
if (saveChangesResult.IsFailure)
|
||||||
@@ -159,11 +159,11 @@ internal sealed class MediaLibraryScanProviderConfigurationInvalidationJob : Med
|
|||||||
throw new InvalidOperationException(publishJobProgressResult.FirstError.Description);
|
throw new InvalidOperationException(publishJobProgressResult.FirstError.Description);
|
||||||
|
|
||||||
// Increment the number of completed jobs progress.
|
// Increment the number of completed jobs progress.
|
||||||
await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.CreateVersion7(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||||
Status = LibraryScanJobStatus.Completed;
|
Status = LibraryScanJobStatus.Completed;
|
||||||
// When this job has no linked children, it is the last job in the directed acyclic job graph, and the scan is completed.
|
// When this job has no linked children, it is the last job in the directed acyclic job graph, and the scan is completed.
|
||||||
if (Children.Count == 0)
|
if (Children.Count == 0)
|
||||||
await domainEventPublisher.PublishAsync(new LibraryScanFinishedDomainEvent(Guid.NewGuid(), compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
await domainEventPublisher.PublishAsync(new LibraryScanFinishedDomainEvent(Guid.CreateVersion7(), compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
// Call each linked child with the obtained payload.
|
// Call each linked child with the obtained payload.
|
||||||
foreach (IMediaLibraryScanJob child in Children)
|
foreach (IMediaLibraryScanJob child in Children)
|
||||||
@@ -198,7 +198,7 @@ internal sealed class MediaLibraryScanProviderConfigurationInvalidationJob : Med
|
|||||||
return scanJobProgressResult.Errors;
|
return scanJobProgressResult.Errors;
|
||||||
|
|
||||||
await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent(
|
await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent(
|
||||||
Guid.NewGuid(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
Guid.CreateVersion7(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -106,7 +106,7 @@ internal sealed class MediaLibraryScanResultsSaveJob : MediaLibraryScanJob, IMed
|
|||||||
foreach (string deletedPath in getDeletedPathsResult.Value)
|
foreach (string deletedPath in getDeletedPathsResult.Value)
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
await domainEventPublisher.PublishAsync(new LibraryMediaItemDeletedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, deletedPath, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
await domainEventPublisher.PublishAsync(new LibraryMediaItemDeletedDomainEvent(Guid.CreateVersion7(), LibraryId, compositeKey, deletedPath, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Materialize the media library items from the scan snapshot, so that they are browsable even without web metadata.
|
// Materialize the media library items from the scan snapshot, so that they are browsable even without web metadata.
|
||||||
@@ -133,11 +133,11 @@ internal sealed class MediaLibraryScanResultsSaveJob : MediaLibraryScanJob, IMed
|
|||||||
throw new InvalidOperationException(publishJobProgressResult.FirstError.Description);
|
throw new InvalidOperationException(publishJobProgressResult.FirstError.Description);
|
||||||
|
|
||||||
// Increment the number of completed jobs progress.
|
// Increment the number of completed jobs progress.
|
||||||
await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.CreateVersion7(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||||
Status = LibraryScanJobStatus.Completed;
|
Status = LibraryScanJobStatus.Completed;
|
||||||
// When this job has no linked children, it is the last job in the directed acyclic job graph, and the scan is completed.
|
// When this job has no linked children, it is the last job in the directed acyclic job graph, and the scan is completed.
|
||||||
if (Children.Count == 0)
|
if (Children.Count == 0)
|
||||||
await domainEventPublisher.PublishAsync(new LibraryScanFinishedDomainEvent(Guid.NewGuid(), compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
await domainEventPublisher.PublishAsync(new LibraryScanFinishedDomainEvent(Guid.CreateVersion7(), compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
// Call each linked child with the obtained payload.
|
// Call each linked child with the obtained payload.
|
||||||
foreach (IMediaLibraryScanJob child in Children)
|
foreach (IMediaLibraryScanJob child in Children)
|
||||||
@@ -171,7 +171,7 @@ internal sealed class MediaLibraryScanResultsSaveJob : MediaLibraryScanJob, IMed
|
|||||||
if (scanJobProgressResult.IsFailure)
|
if (scanJobProgressResult.IsFailure)
|
||||||
return scanJobProgressResult.Errors;
|
return scanJobProgressResult.Errors;
|
||||||
|
|
||||||
await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent(Guid.CreateVersion7(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -32,7 +32,7 @@ internal static class ScanFailurePublisher
|
|||||||
{
|
{
|
||||||
await using AsyncServiceScope asyncServiceScope = serviceScopeFactory.CreateAsyncScope();
|
await using AsyncServiceScope asyncServiceScope = serviceScopeFactory.CreateAsyncScope();
|
||||||
IDomainEventPublisher domainEventPublisher = asyncServiceScope.ServiceProvider.GetService<IDomainEventPublisher>()!;
|
IDomainEventPublisher domainEventPublisher = asyncServiceScope.ServiceProvider.GetService<IDomainEventPublisher>()!;
|
||||||
await domainEventPublisher.PublishAsync(new LibraryScanFailedDomainEvent(Guid.NewGuid(), libraryId, compositeKey, DateTime.UtcNow, Optional<string>.FromNullable(exception.Message)), cancellationToken).ConfigureAwait(false);
|
await domainEventPublisher.PublishAsync(new LibraryScanFailedDomainEvent(Guid.CreateVersion7(), libraryId, compositeKey, DateTime.UtcNow, Optional<string>.FromNullable(exception.Message)), cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|||||||
+4
-4
@@ -170,7 +170,7 @@ internal sealed class BooksFileSystemDiscoveryJob : MediaLibraryScanJob, IBooksF
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This job finished, increment the number of processed jobs progress.
|
// This job finished, increment the number of processed jobs progress.
|
||||||
await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.CreateVersion7(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||||
Status = LibraryScanJobStatus.Completed;
|
Status = LibraryScanJobStatus.Completed;
|
||||||
|
|
||||||
// Call each linked child with the obtained payload.
|
// Call each linked child with the obtained payload.
|
||||||
@@ -237,7 +237,7 @@ internal sealed class BooksFileSystemDiscoveryJob : MediaLibraryScanJob, IBooksF
|
|||||||
|
|
||||||
fingerprintBatch.Add(new DirectoryScanFingerprintEntity()
|
fingerprintBatch.Add(new DirectoryScanFingerprintEntity()
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
LibraryId = LibraryId.Value,
|
LibraryId = LibraryId.Value,
|
||||||
Path = currentDirectory.FullName,
|
Path = currentDirectory.FullName,
|
||||||
LastWriteTimeUtc = currentLastWriteTimeUtc
|
LastWriteTimeUtc = currentLastWriteTimeUtc
|
||||||
@@ -389,7 +389,7 @@ internal sealed class BooksFileSystemDiscoveryJob : MediaLibraryScanJob, IBooksF
|
|||||||
{
|
{
|
||||||
return new LibraryScanStagingResultsEntity()
|
return new LibraryScanStagingResultsEntity()
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
LibraryScanId = ScanId.Value,
|
LibraryScanId = ScanId.Value,
|
||||||
Path = file.FullName,
|
Path = file.FullName,
|
||||||
Size = file.Length,
|
Size = file.Length,
|
||||||
@@ -417,7 +417,7 @@ internal sealed class BooksFileSystemDiscoveryJob : MediaLibraryScanJob, IBooksF
|
|||||||
return scanJobProgressResult.Errors;
|
return scanJobProgressResult.Errors;
|
||||||
|
|
||||||
await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent(
|
await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent(
|
||||||
Guid.NewGuid(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
Guid.CreateVersion7(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -210,7 +210,7 @@ internal sealed class BooksMediaLibraryScanArtworkEnricher : IMediaLibraryScanAr
|
|||||||
{
|
{
|
||||||
coverArtwork.Status = ArtworkStatus.Failed;
|
coverArtwork.Status = ArtworkStatus.Failed;
|
||||||
coverArtwork.UpdatedOnUtc = DateTime.UtcNow;
|
coverArtwork.UpdatedOnUtc = DateTime.UtcNow;
|
||||||
coverArtwork.UpdatedBy = Guid.NewGuid();
|
coverArtwork.UpdatedBy = Guid.CreateVersion7();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -240,7 +240,7 @@ internal sealed class BooksMediaLibraryScanArtworkEnricher : IMediaLibraryScanAr
|
|||||||
{
|
{
|
||||||
existingCoverArtwork.Status = ArtworkStatus.Failed;
|
existingCoverArtwork.Status = ArtworkStatus.Failed;
|
||||||
existingCoverArtwork.UpdatedOnUtc = DateTime.UtcNow;
|
existingCoverArtwork.UpdatedOnUtc = DateTime.UtcNow;
|
||||||
existingCoverArtwork.UpdatedBy = Guid.NewGuid();
|
existingCoverArtwork.UpdatedBy = Guid.CreateVersion7();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -262,7 +262,7 @@ internal sealed class BooksMediaLibraryScanArtworkEnricher : IMediaLibraryScanAr
|
|||||||
existingCoverArtwork.Provider = resolvedArtwork.ProviderName;
|
existingCoverArtwork.Provider = resolvedArtwork.ProviderName;
|
||||||
existingCoverArtwork.LastUpdateUtc = DateTime.UtcNow;
|
existingCoverArtwork.LastUpdateUtc = DateTime.UtcNow;
|
||||||
existingCoverArtwork.UpdatedOnUtc = DateTime.UtcNow;
|
existingCoverArtwork.UpdatedOnUtc = DateTime.UtcNow;
|
||||||
existingCoverArtwork.UpdatedBy = Guid.NewGuid();
|
existingCoverArtwork.UpdatedBy = Guid.CreateVersion7();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -272,7 +272,7 @@ internal sealed class BooksMediaLibraryScanArtworkEnricher : IMediaLibraryScanAr
|
|||||||
existingCoverArtwork.Provider = resolvedArtwork.ProviderName;
|
existingCoverArtwork.Provider = resolvedArtwork.ProviderName;
|
||||||
existingCoverArtwork.LastUpdateUtc = DateTime.UtcNow;
|
existingCoverArtwork.LastUpdateUtc = DateTime.UtcNow;
|
||||||
existingCoverArtwork.UpdatedOnUtc = DateTime.UtcNow;
|
existingCoverArtwork.UpdatedOnUtc = DateTime.UtcNow;
|
||||||
existingCoverArtwork.UpdatedBy = Guid.NewGuid();
|
existingCoverArtwork.UpdatedBy = Guid.CreateVersion7();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,7 +332,7 @@ internal sealed class BooksMediaLibraryScanArtworkEnricher : IMediaLibraryScanAr
|
|||||||
{
|
{
|
||||||
return new BookArtworkEntity
|
return new BookArtworkEntity
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
BookId = bookId,
|
BookId = bookId,
|
||||||
ArtworkType = ArtworkType.Cover,
|
ArtworkType = ArtworkType.Cover,
|
||||||
Ordinal = 0,
|
Ordinal = 0,
|
||||||
@@ -364,7 +364,7 @@ internal sealed class BooksMediaLibraryScanArtworkEnricher : IMediaLibraryScanAr
|
|||||||
return scanJobProgressResult.Errors;
|
return scanJobProgressResult.Errors;
|
||||||
|
|
||||||
await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent(
|
await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent(
|
||||||
Guid.NewGuid(), libraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
Guid.CreateVersion7(), libraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -171,7 +171,7 @@ internal sealed class BooksMediaLibraryScanItemMaterializer : IMediaLibraryScanI
|
|||||||
|
|
||||||
return new BookEntity
|
return new BookEntity
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
LibraryId = library.Id.Value,
|
LibraryId = library.Id.Value,
|
||||||
Path = path,
|
Path = path,
|
||||||
Title = title,
|
Title = title,
|
||||||
|
|||||||
+3
-3
@@ -221,7 +221,7 @@ internal sealed class BooksMediaLibraryScanMetadataEnricher : IMediaLibraryScanM
|
|||||||
// No metadata provider returned usable metadata, so the book is marked as failed to enrich, keeping its previous metadata.
|
// No metadata provider returned usable metadata, so the book is marked as failed to enrich, keeping its previous metadata.
|
||||||
bookEntity.MetadataStatus = MetadataStatus.Failed;
|
bookEntity.MetadataStatus = MetadataStatus.Failed;
|
||||||
bookEntity.UpdatedOnUtc = DateTime.UtcNow;
|
bookEntity.UpdatedOnUtc = DateTime.UtcNow;
|
||||||
bookEntity.UpdatedBy = Guid.NewGuid();
|
bookEntity.UpdatedBy = Guid.CreateVersion7();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,7 +244,7 @@ internal sealed class BooksMediaLibraryScanMetadataEnricher : IMediaLibraryScanM
|
|||||||
continue;
|
continue;
|
||||||
linkedContributors.Add(new BookContributorEntity
|
linkedContributors.Add(new BookContributorEntity
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
BookId = bookEntity.Id,
|
BookId = bookEntity.Id,
|
||||||
MediaContributorId = contributorEntity.Id,
|
MediaContributorId = contributorEntity.Id,
|
||||||
Role = role,
|
Role = role,
|
||||||
@@ -395,7 +395,7 @@ internal sealed class BooksMediaLibraryScanMetadataEnricher : IMediaLibraryScanM
|
|||||||
return scanJobProgressResult.Errors;
|
return scanJobProgressResult.Errors;
|
||||||
|
|
||||||
await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent(
|
await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent(
|
||||||
Guid.NewGuid(), libraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
Guid.CreateVersion7(), libraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -146,7 +146,7 @@ internal sealed class MediaLibraryScanProcessorJob : BackgroundService
|
|||||||
|
|
||||||
// The file system discovery job is the only top level job of the scan job graph, and every job awaits its children, so awaiting it
|
// The file system discovery job is the only top level job of the scan job graph, and every job awaits its children, so awaiting it
|
||||||
// completes the entire scan. The next queued scan is only dequeued once this call returns.
|
// completes the entire scan. The next queued scan is only dequeued once this call returns.
|
||||||
await rootJob.ExecuteAsync(Guid.NewGuid(), new { }, linkedSource.Token).ConfigureAwait(false);
|
await rootJob.ExecuteAsync(Guid.CreateVersion7(), new { }, linkedSource.Token).ConfigureAwait(false);
|
||||||
|
|
||||||
_logger.LogInformation("Completed the media library scan '{ScanId}' of the media library '{LibraryId}'.", compositeId.ScanId.Value, libraryScan.LibraryId.Value);
|
_logger.LogInformation("Completed the media library scan '{ScanId}' of the media library '{LibraryId}'.", compositeId.ScanId.Value, libraryScan.LibraryId.Value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -291,7 +291,7 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv
|
|||||||
// columns are left at their defaults because the persistence layer stamps them when the row is saved.
|
// columns are left at their defaults because the persistence layer stamps them when the row is saved.
|
||||||
LibraryBookReaderConfigurationEntity configuration = new()
|
LibraryBookReaderConfigurationEntity configuration = new()
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
LibraryId = libraryId,
|
LibraryId = libraryId,
|
||||||
PluginId = pluginId,
|
PluginId = pluginId,
|
||||||
IsEnabled = false,
|
IsEnabled = false,
|
||||||
@@ -333,7 +333,7 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv
|
|||||||
// columns are left at their defaults because the persistence layer stamps them when the row is saved.
|
// columns are left at their defaults because the persistence layer stamps them when the row is saved.
|
||||||
LibraryBookReaderConfigurationEntity configuration = new()
|
LibraryBookReaderConfigurationEntity configuration = new()
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
LibraryId = libraryId,
|
LibraryId = libraryId,
|
||||||
PluginId = pluginId,
|
PluginId = pluginId,
|
||||||
IsEnabled = false,
|
IsEnabled = false,
|
||||||
@@ -384,7 +384,7 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv
|
|||||||
// the audit columns are left at their defaults because the persistence layer stamps them when the row is saved.
|
// the audit columns are left at their defaults because the persistence layer stamps them when the row is saved.
|
||||||
LibraryMetadataProviderConfigurationEntity configuration = new()
|
LibraryMetadataProviderConfigurationEntity configuration = new()
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
LibraryId = libraryId,
|
LibraryId = libraryId,
|
||||||
PluginId = pluginId,
|
PluginId = pluginId,
|
||||||
IsEnabled = false,
|
IsEnabled = false,
|
||||||
@@ -437,7 +437,7 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv
|
|||||||
// audit columns are left at their defaults because the persistence layer stamps them when the row is saved.
|
// audit columns are left at their defaults because the persistence layer stamps them when the row is saved.
|
||||||
LibraryArtworkProviderConfigurationEntity configuration = new()
|
LibraryArtworkProviderConfigurationEntity configuration = new()
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
LibraryId = libraryId,
|
LibraryId = libraryId,
|
||||||
PluginId = pluginId,
|
PluginId = pluginId,
|
||||||
IsEnabled = false,
|
IsEnabled = false,
|
||||||
@@ -479,7 +479,7 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv
|
|||||||
// the audit columns are left at their defaults because the persistence layer stamps them when the row is saved.
|
// the audit columns are left at their defaults because the persistence layer stamps them when the row is saved.
|
||||||
LibraryMetadataProviderConfigurationEntity configuration = new()
|
LibraryMetadataProviderConfigurationEntity configuration = new()
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
LibraryId = libraryId,
|
LibraryId = libraryId,
|
||||||
PluginId = pluginId,
|
PluginId = pluginId,
|
||||||
IsEnabled = false,
|
IsEnabled = false,
|
||||||
@@ -521,7 +521,7 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv
|
|||||||
// audit columns are left at their defaults because the persistence layer stamps them when the row is saved.
|
// audit columns are left at their defaults because the persistence layer stamps them when the row is saved.
|
||||||
LibraryArtworkProviderConfigurationEntity configuration = new()
|
LibraryArtworkProviderConfigurationEntity configuration = new()
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
LibraryId = libraryId,
|
LibraryId = libraryId,
|
||||||
PluginId = pluginId,
|
PluginId = pluginId,
|
||||||
IsEnabled = false,
|
IsEnabled = false,
|
||||||
@@ -578,7 +578,7 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv
|
|||||||
bool isEnabled = enabledStatesByPluginId.GetValueOrDefault(pluginId) ?? storedConfiguration?.IsEnabled ?? false;
|
bool isEnabled = enabledStatesByPluginId.GetValueOrDefault(pluginId) ?? storedConfiguration?.IsEnabled ?? false;
|
||||||
LibraryMetadataProviderConfigurationEntity configuration = storedConfiguration ?? new LibraryMetadataProviderConfigurationEntity
|
LibraryMetadataProviderConfigurationEntity configuration = storedConfiguration ?? new LibraryMetadataProviderConfigurationEntity
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
LibraryId = libraryId,
|
LibraryId = libraryId,
|
||||||
PluginId = pluginId,
|
PluginId = pluginId,
|
||||||
IsEnabled = isEnabled,
|
IsEnabled = isEnabled,
|
||||||
@@ -636,7 +636,7 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv
|
|||||||
bool isEnabled = enabledStatesByPluginId.GetValueOrDefault(pluginId) ?? storedConfiguration?.IsEnabled ?? false;
|
bool isEnabled = enabledStatesByPluginId.GetValueOrDefault(pluginId) ?? storedConfiguration?.IsEnabled ?? false;
|
||||||
LibraryArtworkProviderConfigurationEntity configuration = storedConfiguration ?? new LibraryArtworkProviderConfigurationEntity
|
LibraryArtworkProviderConfigurationEntity configuration = storedConfiguration ?? new LibraryArtworkProviderConfigurationEntity
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
LibraryId = libraryId,
|
LibraryId = libraryId,
|
||||||
PluginId = pluginId,
|
PluginId = pluginId,
|
||||||
IsEnabled = isEnabled,
|
IsEnabled = isEnabled,
|
||||||
@@ -693,7 +693,7 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv
|
|||||||
bool isEnabled = enabledStatesByPluginId.GetValueOrDefault(pluginId) ?? storedConfiguration?.IsEnabled ?? false;
|
bool isEnabled = enabledStatesByPluginId.GetValueOrDefault(pluginId) ?? storedConfiguration?.IsEnabled ?? false;
|
||||||
LibraryBookReaderConfigurationEntity configuration = storedConfiguration ?? new LibraryBookReaderConfigurationEntity
|
LibraryBookReaderConfigurationEntity configuration = storedConfiguration ?? new LibraryBookReaderConfigurationEntity
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
LibraryId = libraryId,
|
LibraryId = libraryId,
|
||||||
PluginId = pluginId,
|
PluginId = pluginId,
|
||||||
IsEnabled = isEnabled,
|
IsEnabled = isEnabled,
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ public sealed class ScheduledJobSchedulerJob : BackgroundService, IScheduledJobS
|
|||||||
Guid ownerUserId = scheduledJobs[0].OwnerUserId;
|
Guid ownerUserId = scheduledJobs[0].OwnerUserId;
|
||||||
ScheduledJobEntity technicalDataCleanupJob = new()
|
ScheduledJobEntity technicalDataCleanupJob = new()
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
Name = "Technical data cleanup at startup",
|
Name = "Technical data cleanup at startup",
|
||||||
TaskType = ScheduledTaskType.TechnicalDataCleanup,
|
TaskType = ScheduledTaskType.TechnicalDataCleanup,
|
||||||
ScheduleType = ScheduleType.OnceAtStartup,
|
ScheduleType = ScheduleType.OnceAtStartup,
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ internal static class ThemeSynchronizer
|
|||||||
|
|
||||||
ThemeEntity themeEntity = new()
|
ThemeEntity themeEntity = new()
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.CreateVersion7(),
|
||||||
ThemeId = manifestResult.Value.Id,
|
ThemeId = manifestResult.Value.Id,
|
||||||
Name = manifestResult.Value.Name,
|
Name = manifestResult.Value.Name,
|
||||||
Description = manifestResult.Value.Description,
|
Description = manifestResult.Value.Description,
|
||||||
|
|||||||
@@ -125,6 +125,7 @@
|
|||||||
<File Path="../docs/technical/architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0017.md" />
|
<File Path="../docs/technical/architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0017.md" />
|
||||||
<File Path="../docs/technical/architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0018.md" />
|
<File Path="../docs/technical/architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0018.md" />
|
||||||
<File Path="../docs/technical/architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0019.md" />
|
<File Path="../docs/technical/architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0019.md" />
|
||||||
|
<File Path="../docs/technical/architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0020.md" />
|
||||||
</Folder>
|
</Folder>
|
||||||
<Folder Name="/docs/technical/domain/">
|
<Folder Name="/docs/technical/domain/">
|
||||||
<File Path="../docs/technical/domain/Aggregates.AudioLibrary.md" />
|
<File Path="../docs/technical/domain/Aggregates.AudioLibrary.md" />
|
||||||
|
|||||||
+43
@@ -1,13 +1,18 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
|
||||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||||
|
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||||
|
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||||
|
using Lumina.DataAccess.Common.ValueGeneration;
|
||||||
using Lumina.DataAccess.Core.UoW;
|
using Lumina.DataAccess.Core.UoW;
|
||||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||||
using Microsoft.Data.Sqlite;
|
using Microsoft.Data.Sqlite;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Metadata;
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -116,6 +121,44 @@ public class LuminaDbContextTests : IDisposable
|
|||||||
Assert.Contains("Favorites", tableNames);
|
Assert.Contains("Favorites", tableNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void OnModelCreating_WhenApplied_ShouldUseTimeOrderedGeneratorsForPersistedGuidIdentifiers()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
List<IProperty> generatedGuidProperties = [.. _context.Model.GetEntityTypes()
|
||||||
|
.SelectMany(entityType => entityType.GetProperties())
|
||||||
|
.Where(property => property.ClrType == typeof(Guid) && property.ValueGenerated == ValueGenerated.OnAdd)];
|
||||||
|
|
||||||
|
// Act
|
||||||
|
Assert.All(generatedGuidProperties, property => Assert.NotNull(property.GetValueGeneratorFactory()));
|
||||||
|
List<Type> generatorTypes = [.. generatedGuidProperties.Select(property => property.GetValueGeneratorFactory()!(property, property.DeclaringType).GetType())];
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Contains(generatedGuidProperties, property => property.DeclaringType.ClrType == typeof(PermissionEntity) && property.Name == nameof(PermissionEntity.Id));
|
||||||
|
Assert.Contains(generatedGuidProperties, property => property.DeclaringType.ClrType == typeof(AudioRatingEntity) && property.Name == "Id");
|
||||||
|
Assert.All(generatorTypes, generatorType => Assert.Equal(typeof(GuidV7ValueGenerator), generatorType));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task SaveChangesAsync_WhenAPermissionHasNoId_ShouldAssignAVersion7Identifier()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
_context.Database.EnsureCreated();
|
||||||
|
PermissionEntity permission = new()
|
||||||
|
{
|
||||||
|
PermissionName = AuthorizationPermission.CanViewUsers,
|
||||||
|
CreatedBy = Guid.CreateVersion7(),
|
||||||
|
CreatedOnUtc = DateTime.UtcNow
|
||||||
|
};
|
||||||
|
_context.Permissions.Add(permission);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(7, permission.Id.Version);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task SaveChangesAsync_WhenAddingBook_ShouldPersistItToTheDatabase()
|
public async Task SaveChangesAsync_WhenAddingBook_ShouldPersistItToTheDatabase()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user