Auto-tune channels can now carry per-content-source rotation weights (weighted
round-robin, e.g. 3x Show A / 1x Show B) and query corrections (exclude /
add-untagged), supplied at bulk-create time via an optional
`sources: [{sourceId, weight, excluded}]` on each AutoTunedChannelRequest.
Design (Option A, reuse #70): when a source is customized the channel is backed
by a system-owned MultiCollection of per-source SmartCollections carrying the
weights, with PlaybackOrder.WeightedShuffle -- the exact path
WeightedShuffleCollectionEnumerator already consumes. All-default weights keep
the #69 single-SmartCollection fair-share shape.
- Discriminators: TV -> live show_title:"X" (episodes carry no parent-show id in
the index); movies -> stable id:{mediaItemId}.
- Materialization is axis-dependent: TV materializes every base show individually
(un-weighted shows keep per-show fair-share) + a live remainder at weight 1;
MovieGenre materializes only touched movies + one count-weighted remainder.
- Remainder = (base) AND NOT (materialized union excluded) -- a partition.
- New nullable OwnedByChannelId on SmartCollection + MultiCollection
(dual-provider migration); owned rows are hidden from the collection lists and
cascade-cleaned on channel delete.
Tests: AutoTuneAxisMap query/partition units; DB-backed weighted-path handler
tests (TV materialize-all, movie count-remainder, exclusion, no-customization
fallback); delete-cleanup. Docs: decisions.md, domain-model.md, api-conventions.md;
OpenAPI trio regenerated.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
69 lines
3.0 KiB
C#
69 lines
3.0 KiB
C#
using ErsatzTV.Core.Domain;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
|
|
namespace ErsatzTV.Infrastructure.Data.Configurations;
|
|
|
|
public class MultiCollectionConfiguration : IEntityTypeConfiguration<MultiCollection>
|
|
{
|
|
public void Configure(EntityTypeBuilder<MultiCollection> builder)
|
|
{
|
|
builder.ToTable("MultiCollection");
|
|
|
|
builder.Property(mc => mc.Version).IsConcurrencyToken();
|
|
|
|
builder.Property(mc => mc.Name)
|
|
.HasMaxLength(50)
|
|
.HasColumnType("varchar(50)");
|
|
|
|
builder.HasIndex(mc => mc.Name)
|
|
.IsUnique();
|
|
|
|
// Cleanup + list-hiding of the system multi collection an auto-tune weighted channel owns (#425).
|
|
// Nullable: null = a normal user multi collection.
|
|
builder.HasIndex(mc => mc.OwnedByChannelId);
|
|
|
|
builder.HasMany(m => m.Collections)
|
|
.WithMany(m => m.MultiCollections)
|
|
.UsingEntity<MultiCollectionItem>(
|
|
j => j.HasOne(mci => mci.Collection)
|
|
.WithMany(c => c.MultiCollectionItems)
|
|
.HasForeignKey(mci => mci.CollectionId)
|
|
.OnDelete(DeleteBehavior.Cascade),
|
|
j => j.HasOne(mci => mci.MultiCollection)
|
|
.WithMany(mc => mc.MultiCollectionItems)
|
|
.HasForeignKey(mci => mci.MultiCollectionId)
|
|
.OnDelete(DeleteBehavior.Cascade),
|
|
j =>
|
|
{
|
|
j.HasKey(mci => new { mci.MultiCollectionId, mci.CollectionId });
|
|
|
|
// default 1 = fair share (#70). Must be a DB default too, or existing rows migrate to 0 --
|
|
// a value that means nothing on a share-of-airtime scale. The enumerator clamps such a
|
|
// row to the floor, so it rotates rather than vanishing; the backfill should still be
|
|
// right at the source.
|
|
j.Property(mci => mci.Weight).HasDefaultValue(1);
|
|
});
|
|
|
|
builder.HasMany(m => m.SmartCollections)
|
|
.WithMany(m => m.MultiCollections)
|
|
.UsingEntity<MultiCollectionSmartItem>(
|
|
j => j.HasOne(mci => mci.SmartCollection)
|
|
.WithMany(c => c.MultiCollectionSmartItems)
|
|
.HasForeignKey(mci => mci.SmartCollectionId)
|
|
.OnDelete(DeleteBehavior.Cascade),
|
|
j => j.HasOne(mci => mci.MultiCollection)
|
|
.WithMany(mc => mc.MultiCollectionSmartItems)
|
|
.HasForeignKey(mci => mci.MultiCollectionId)
|
|
.OnDelete(DeleteBehavior.Cascade),
|
|
j =>
|
|
{
|
|
j.HasKey(mci => new { mci.MultiCollectionId, mci.SmartCollectionId });
|
|
|
|
// mirrors MultiCollectionItem above -- omitting it would silently un-weight
|
|
// every smart-collection member of a multi collection
|
|
j.Property(mci => mci.Weight).HasDefaultValue(1);
|
|
});
|
|
}
|
|
}
|