mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 07:11:10 +00:00
Adds the media library scan snapshot, staging and directory fingerprint data model
This commit is contained in:
1 parent
4fec67a1f8
commit
1dc3da3da1
37 files changed
+7315
-89
No files matched your search
@@ -0,0 +1,47 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.Common.Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Configures the entity mapping for the <see cref="DirectoryScanFingerprintEntity"/> entity.
|
||||
/// </summary>
|
||||
public class DirectoryScanFingerprintConfiguration : IEntityTypeConfiguration<DirectoryScanFingerprintEntity>
|
||||
{
|
||||
/// <summary>
|
||||
/// Configures the <see cref="DirectoryScanFingerprintEntity"/> entity.
|
||||
/// </summary>
|
||||
/// <param name="builder">The builder to be used to configure the entity.</param>
|
||||
public void Configure(EntityTypeBuilder<DirectoryScanFingerprintEntity> builder)
|
||||
{
|
||||
builder.ToTable("DirectoryScanFingerprints");
|
||||
// composite key, so that each directory scan fingerprint is uniquely identified within its library by its path
|
||||
builder.HasKey(directoryScanFingerprint => new { directoryScanFingerprint.LibraryId, directoryScanFingerprint.Path });
|
||||
|
||||
// one library with many directory scan fingerprints
|
||||
builder.HasOne<LibraryEntity>()
|
||||
.WithMany()
|
||||
.HasForeignKey(directoryScanFingerprint => directoryScanFingerprint.LibraryId)
|
||||
.IsRequired()
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.Property(directoryScanFingerprint => directoryScanFingerprint.Id)
|
||||
.ValueGeneratedNever()
|
||||
.HasColumnOrder(0);
|
||||
|
||||
builder.Property(directoryScanFingerprint => directoryScanFingerprint.Path)
|
||||
.HasMaxLength(1024)
|
||||
.IsRequired()
|
||||
.HasColumnOrder(1);
|
||||
|
||||
builder.Property(directoryScanFingerprint => directoryScanFingerprint.LastWriteTimeUtc)
|
||||
.IsRequired()
|
||||
.HasColumnOrder(2);
|
||||
|
||||
// enables fast lookups of the directory scan fingerprints of a library
|
||||
builder.HasIndex(directoryScanFingerprint => directoryScanFingerprint.LibraryId);
|
||||
}
|
||||
}
|
||||
@@ -57,5 +57,11 @@ public class LibraryScanConfiguration : IEntityTypeConfiguration<LibraryScanEnti
|
||||
builder.Property(libraryScan => libraryScan.UpdatedBy)
|
||||
.HasDefaultValue(null)
|
||||
.HasColumnOrder(5);
|
||||
|
||||
// Indexes
|
||||
|
||||
// enables fast lookup of latest non-running scans per library
|
||||
builder.HasIndex(libraryScan => new { libraryScan.LibraryId, libraryScan.Status, libraryScan.CreatedOnUtc })
|
||||
.IsDescending(true, false, true); // CreatedOnUtc DESC
|
||||
}
|
||||
}
|
||||
@@ -18,12 +18,12 @@ public class LibraryScanResultConfiguration : IEntityTypeConfiguration<LibrarySc
|
||||
public void Configure(EntityTypeBuilder<LibraryScanResultEntity> builder)
|
||||
{
|
||||
builder.ToTable("LibraryScanResults");
|
||||
// composite key for efficient scan-specific lookups
|
||||
// composite key for efficient scan-specific lookups (paths are enforced as UNIQUE within the same scan)
|
||||
builder.HasKey(libraryScanResult => new { libraryScanResult.LibraryScanId, libraryScanResult.Path });
|
||||
|
||||
// one library scan with many library scan results
|
||||
builder.HasOne(libraryScanResult => libraryScanResult.LibraryScan)
|
||||
.WithMany()
|
||||
.WithMany(libraryScan => libraryScan.LibraryScanResults)
|
||||
.HasForeignKey(libraryScanResult => libraryScanResult.LibraryScanId)
|
||||
.IsRequired()
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
@@ -46,15 +46,19 @@ public class LibraryScanResultConfiguration : IEntityTypeConfiguration<LibrarySc
|
||||
.IsRequired()
|
||||
.HasColumnOrder(3);
|
||||
|
||||
builder.Property(libraryScanResult => libraryScanResult.LastModified)
|
||||
builder.Property(libraryScanResult => libraryScanResult.Ticks)
|
||||
.IsRequired()
|
||||
.HasColumnOrder(4);
|
||||
|
||||
// Indexes
|
||||
builder.HasIndex(libraryScanResult => new { libraryScanResult.ContentHash, libraryScanResult.FileSize, libraryScanResult.Path })
|
||||
.IsUnique();
|
||||
builder.Property(libraryScanResult => libraryScanResult.Status)
|
||||
.IsRequired()
|
||||
.HasConversion<string>()
|
||||
.HasMaxLength(10)
|
||||
.HasColumnOrder(5);
|
||||
|
||||
builder.HasIndex(libraryScanResult => libraryScanResult.Path)
|
||||
.IsUnique();
|
||||
// Indexes
|
||||
builder.HasIndex(libraryScanResult => new { libraryScanResult.ContentHash, libraryScanResult.FileSize, libraryScanResult.Path });
|
||||
|
||||
builder.HasIndex(libraryScanResult => libraryScanResult.Path);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.Common.Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Configures the entity mapping for the <see cref="LibraryScanSnapshotEntity"/> entity.
|
||||
/// </summary>
|
||||
public class LibraryScanSnapshotConfiguration : IEntityTypeConfiguration<LibraryScanSnapshotEntity>
|
||||
{
|
||||
/// <summary>
|
||||
/// Configures the <see cref="LibraryScanSnapshotEntity"/> entity.
|
||||
/// </summary>
|
||||
/// <param name="builder">The builder to be used to configure the entity.</param>
|
||||
public void Configure(EntityTypeBuilder<LibraryScanSnapshotEntity> builder)
|
||||
{
|
||||
builder.ToTable("LibraryScanSnapshots");
|
||||
// composite key, so that each media library scan snapshot item is uniquely identified within its library by its path
|
||||
builder.HasKey(libraryScanSnapshot => new { libraryScanSnapshot.LibraryId, libraryScanSnapshot.Path });
|
||||
|
||||
// one library with many media library scan snapshot items
|
||||
builder.HasOne(libraryScanSnapshot => libraryScanSnapshot.Library)
|
||||
.WithMany()
|
||||
.HasForeignKey(libraryScanSnapshot => libraryScanSnapshot.LibraryId)
|
||||
.IsRequired()
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.Property(libraryScanSnapshot => libraryScanSnapshot.Id)
|
||||
.ValueGeneratedNever()
|
||||
.HasColumnOrder(0);
|
||||
|
||||
builder.Property(libraryScanSnapshot => libraryScanSnapshot.Path)
|
||||
.HasMaxLength(1024)
|
||||
.IsRequired()
|
||||
.HasColumnOrder(1);
|
||||
|
||||
builder.Property(libraryScanSnapshot => libraryScanSnapshot.ContentHash)
|
||||
.IsRequired()
|
||||
.HasColumnOrder(2);
|
||||
|
||||
builder.Property(libraryScanSnapshot => libraryScanSnapshot.FileSize)
|
||||
.IsRequired()
|
||||
.HasColumnOrder(3);
|
||||
|
||||
builder.Property(libraryScanSnapshot => libraryScanSnapshot.Ticks)
|
||||
.IsRequired()
|
||||
.HasColumnOrder(4);
|
||||
|
||||
// audit
|
||||
builder.Property(libraryScanSnapshot => libraryScanSnapshot.CreatedOnUtc)
|
||||
.IsRequired()
|
||||
.HasColumnOrder(5);
|
||||
|
||||
builder.Property(libraryScanSnapshot => libraryScanSnapshot.CreatedBy)
|
||||
.IsRequired()
|
||||
.HasColumnOrder(6);
|
||||
|
||||
builder.Property(libraryScanSnapshot => libraryScanSnapshot.UpdatedOnUtc)
|
||||
.HasDefaultValue(null)
|
||||
.HasColumnOrder(7);
|
||||
|
||||
builder.Property(libraryScanSnapshot => libraryScanSnapshot.UpdatedBy)
|
||||
.HasDefaultValue(null)
|
||||
.HasColumnOrder(8);
|
||||
|
||||
// enables fast lookups of the media library scan snapshot items of a library
|
||||
builder.HasIndex(libraryScanSnapshot => libraryScanSnapshot.LibraryId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.Common.Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Configures the entity mapping for the <see cref="LibraryScanStagingResultsEntity"/> entity.
|
||||
/// </summary>
|
||||
public class LibraryScanStagingResultsConfiguration : IEntityTypeConfiguration<LibraryScanStagingResultsEntity>
|
||||
{
|
||||
/// <summary>
|
||||
/// Configures the <see cref="LibraryScanStagingResultsEntity"/> entity.
|
||||
/// </summary>
|
||||
/// <param name="builder">The builder to be used to configure the entity.</param>
|
||||
public void Configure(EntityTypeBuilder<LibraryScanStagingResultsEntity> builder)
|
||||
{
|
||||
builder.ToTable("LibraryScanStagingResults");
|
||||
// composite key, so that each media library scan staging result is uniquely identified within its scan by its path
|
||||
builder.HasKey(libraryScanStagingResult => new { libraryScanStagingResult.LibraryScanId, libraryScanStagingResult.Path });
|
||||
|
||||
// one media library scan with many media library scan staging results
|
||||
builder.HasOne<LibraryScanEntity>()
|
||||
.WithMany()
|
||||
.HasForeignKey(libraryScanStagingResult => libraryScanStagingResult.LibraryScanId)
|
||||
.IsRequired()
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.Property(libraryScanStagingResult => libraryScanStagingResult.Id)
|
||||
.ValueGeneratedNever()
|
||||
.HasColumnOrder(0);
|
||||
|
||||
builder.Property(libraryScanStagingResult => libraryScanStagingResult.Path)
|
||||
.HasMaxLength(1024)
|
||||
.IsRequired()
|
||||
.HasColumnOrder(1);
|
||||
|
||||
builder.Property(libraryScanStagingResult => libraryScanStagingResult.Size)
|
||||
.IsRequired()
|
||||
.HasColumnOrder(2);
|
||||
|
||||
builder.Property(libraryScanStagingResult => libraryScanStagingResult.Ticks)
|
||||
.IsRequired()
|
||||
.HasColumnOrder(3);
|
||||
|
||||
builder.Property(libraryScanStagingResult => libraryScanStagingResult.ContentHash)
|
||||
.IsRequired()
|
||||
.HasColumnOrder(4);
|
||||
|
||||
builder.Property(libraryScanStagingResult => libraryScanStagingResult.PreviousContentHash)
|
||||
.IsRequired()
|
||||
.HasColumnOrder(5);
|
||||
|
||||
builder.Property(libraryScanStagingResult => libraryScanStagingResult.NeedsRehash)
|
||||
.IsRequired()
|
||||
.HasColumnOrder(6);
|
||||
|
||||
builder.Property(libraryScanStagingResult => libraryScanStagingResult.IsNew)
|
||||
.IsRequired()
|
||||
.HasColumnOrder(7);
|
||||
|
||||
// enables fast lookups of the staging results of a scan that need their content hashed
|
||||
builder.HasIndex(libraryScanStagingResult => new { libraryScanStagingResult.LibraryScanId, libraryScanStagingResult.NeedsRehash });
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user