Change editor rule
This commit is contained in:
@@ -2,42 +2,43 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
using Musify.Domain.Abstractions;
|
||||
|
||||
namespace Musify.Infrastructure.Persistence;
|
||||
|
||||
public sealed class AuditableEntityInterceptor : SaveChangesInterceptor
|
||||
namespace Musify.Infrastructure.Persistence
|
||||
{
|
||||
public override InterceptionResult<int> SavingChanges(DbContextEventData eventData, InterceptionResult<int> result)
|
||||
public sealed class AuditableEntityInterceptor : SaveChangesInterceptor
|
||||
{
|
||||
ApplyTimestamps(eventData.Context);
|
||||
return base.SavingChanges(eventData, result);
|
||||
}
|
||||
|
||||
public override ValueTask<InterceptionResult<int>> SavingChangesAsync(
|
||||
DbContextEventData eventData, InterceptionResult<int> result, CancellationToken cancellationToken = default)
|
||||
{
|
||||
ApplyTimestamps(eventData.Context);
|
||||
return base.SavingChangesAsync(eventData, result, cancellationToken);
|
||||
}
|
||||
|
||||
private static void ApplyTimestamps(DbContext? context)
|
||||
{
|
||||
if (context == null)
|
||||
return;
|
||||
|
||||
context.ChangeTracker.DetectChanges();
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
|
||||
foreach (var entry in context.ChangeTracker.Entries<IAuditable>())
|
||||
public override InterceptionResult<int> SavingChanges(DbContextEventData eventData, InterceptionResult<int> result)
|
||||
{
|
||||
if (entry.State == EntityState.Added)
|
||||
ApplyTimestamps(eventData.Context);
|
||||
return base.SavingChanges(eventData, result);
|
||||
}
|
||||
|
||||
public override ValueTask<InterceptionResult<int>> SavingChangesAsync(
|
||||
DbContextEventData eventData, InterceptionResult<int> result, CancellationToken cancellationToken = default)
|
||||
{
|
||||
ApplyTimestamps(eventData.Context);
|
||||
return base.SavingChangesAsync(eventData, result, cancellationToken);
|
||||
}
|
||||
|
||||
private static void ApplyTimestamps(DbContext? context)
|
||||
{
|
||||
if (context == null)
|
||||
return;
|
||||
|
||||
context.ChangeTracker.DetectChanges();
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
|
||||
foreach (var entry in context.ChangeTracker.Entries<IAuditable>())
|
||||
{
|
||||
entry.Entity.CreatedAt = now;
|
||||
entry.Entity.UpdatedAt = now;
|
||||
}
|
||||
else if (entry.State == EntityState.Modified)
|
||||
{
|
||||
entry.Property(nameof(IAuditable.UpdatedAt)).CurrentValue = now;
|
||||
if (entry.State == EntityState.Added)
|
||||
{
|
||||
entry.Entity.CreatedAt = now;
|
||||
entry.Entity.UpdatedAt = now;
|
||||
}
|
||||
else if (entry.State == EntityState.Modified)
|
||||
{
|
||||
entry.Property(nameof(IAuditable.UpdatedAt)).CurrentValue = now;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,81 +8,82 @@ using Musify.Domain.ValueObjects;
|
||||
using Musify.Infrastructure.Configuration;
|
||||
using Npgsql;
|
||||
|
||||
namespace Musify.Infrastructure.Persistence;
|
||||
|
||||
public class Database(DatabaseConfiguration configuration)
|
||||
: DbContext, Musify.Application.Contracts.IDatabase
|
||||
namespace Musify.Infrastructure.Persistence
|
||||
{
|
||||
private static readonly AuditableEntityInterceptor AuditInterceptor = new();
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
public class Database(DatabaseConfiguration configuration)
|
||||
: DbContext, Musify.Application.Contracts.IDatabase
|
||||
{
|
||||
optionsBuilder
|
||||
.UseNpgsql(configuration.ConnectionString, o => o.MapEnum<Genre>("genre"))
|
||||
.AddInterceptors(AuditInterceptor);
|
||||
}
|
||||
private static readonly AuditableEntityInterceptor AuditInterceptor = new();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
modelBuilder.AddInboxStateEntity();
|
||||
modelBuilder.AddOutboxMessageEntity();
|
||||
modelBuilder.AddOutboxStateEntity();
|
||||
|
||||
ModelConfiguration.Apply(modelBuilder);
|
||||
}
|
||||
|
||||
public DbSet<User> Users => Set<User>();
|
||||
|
||||
public DbSet<Track> Tracks => Set<Track>();
|
||||
|
||||
public DbSet<PlayList> PlayLists => Set<PlayList>();
|
||||
|
||||
public DbSet<Album> Albums => Set<Album>();
|
||||
|
||||
public DbSet<AlbumHasTrack> AlbumHasTracks => Set<AlbumHasTrack>();
|
||||
|
||||
public DbSet<PlayListHasTrack> PlayListHasTracks => Set<PlayListHasTrack>();
|
||||
|
||||
public DbSet<Mix> Mixes => Set<Mix>();
|
||||
|
||||
public DbSet<MixItem> MixItems => Set<MixItem>();
|
||||
|
||||
public DbSet<UploadIntent> UploadIntents => Set<UploadIntent>();
|
||||
|
||||
public DbSet<ListeningHistory> ListeningHistories => Set<ListeningHistory>();
|
||||
|
||||
public DbSet<TrackLike> TrackLikes => Set<TrackLike>();
|
||||
|
||||
public DbSet<TrackTag> TrackTags => Set<TrackTag>();
|
||||
|
||||
public DbSet<UserFollow> UserFollows => Set<UserFollow>();
|
||||
|
||||
public async Task<IDatabaseTransaction> BeginTransactionAsync(System.Data.IsolationLevel isolationLevel, CancellationToken cancellationToken)
|
||||
{
|
||||
var transaction = await Database.BeginTransactionAsync(isolationLevel, cancellationToken);
|
||||
return new DatabaseTransaction(transaction);
|
||||
}
|
||||
|
||||
public async Task<ErrorOr<Success>> TrySaveChangesAsync(Error onUniqueViolation, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
await SaveChangesAsync(cancellationToken);
|
||||
return Result.Success;
|
||||
optionsBuilder
|
||||
.UseNpgsql(configuration.ConnectionString, o => o.MapEnum<Genre>("genre"))
|
||||
.AddInterceptors(AuditInterceptor);
|
||||
}
|
||||
catch (DbUpdateException exception) when (exception.InnerException is PostgresException { SqlState: PostgresErrorCodes.UniqueViolation })
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
return onUniqueViolation;
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
modelBuilder.AddInboxStateEntity();
|
||||
modelBuilder.AddOutboxMessageEntity();
|
||||
modelBuilder.AddOutboxStateEntity();
|
||||
|
||||
ModelConfiguration.Apply(modelBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class DatabaseTransaction(IDbContextTransaction inner) : IDatabaseTransaction
|
||||
{
|
||||
public Task CommitAsync(CancellationToken cancellationToken) =>
|
||||
inner.CommitAsync(cancellationToken);
|
||||
public DbSet<User> Users => Set<User>();
|
||||
|
||||
public ValueTask DisposeAsync() => inner.DisposeAsync();
|
||||
public DbSet<Track> Tracks => Set<Track>();
|
||||
|
||||
public DbSet<PlayList> PlayLists => Set<PlayList>();
|
||||
|
||||
public DbSet<Album> Albums => Set<Album>();
|
||||
|
||||
public DbSet<AlbumHasTrack> AlbumHasTracks => Set<AlbumHasTrack>();
|
||||
|
||||
public DbSet<PlayListHasTrack> PlayListHasTracks => Set<PlayListHasTrack>();
|
||||
|
||||
public DbSet<Mix> Mixes => Set<Mix>();
|
||||
|
||||
public DbSet<MixItem> MixItems => Set<MixItem>();
|
||||
|
||||
public DbSet<UploadIntent> UploadIntents => Set<UploadIntent>();
|
||||
|
||||
public DbSet<ListeningHistory> ListeningHistories => Set<ListeningHistory>();
|
||||
|
||||
public DbSet<TrackLike> TrackLikes => Set<TrackLike>();
|
||||
|
||||
public DbSet<TrackTag> TrackTags => Set<TrackTag>();
|
||||
|
||||
public DbSet<UserFollow> UserFollows => Set<UserFollow>();
|
||||
|
||||
public async Task<IDatabaseTransaction> BeginTransactionAsync(System.Data.IsolationLevel isolationLevel, CancellationToken cancellationToken)
|
||||
{
|
||||
var transaction = await Database.BeginTransactionAsync(isolationLevel, cancellationToken);
|
||||
return new DatabaseTransaction(transaction);
|
||||
}
|
||||
|
||||
public async Task<ErrorOr<Success>> TrySaveChangesAsync(Error onUniqueViolation, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
await SaveChangesAsync(cancellationToken);
|
||||
return Result.Success;
|
||||
}
|
||||
catch (DbUpdateException exception) when (exception.InnerException is PostgresException { SqlState: PostgresErrorCodes.UniqueViolation })
|
||||
{
|
||||
return onUniqueViolation;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class DatabaseTransaction(IDbContextTransaction inner) : IDatabaseTransaction
|
||||
{
|
||||
public Task CommitAsync(CancellationToken cancellationToken) =>
|
||||
inner.CommitAsync(cancellationToken);
|
||||
|
||||
public ValueTask DisposeAsync() => inner.DisposeAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,18 +4,19 @@ using Musify.Application.Configuration;
|
||||
using Musify.Application.Contracts;
|
||||
using Musify.Infrastructure.Configuration;
|
||||
|
||||
namespace Musify.Infrastructure.Persistence;
|
||||
|
||||
public static class DatabaseDependencyInjection
|
||||
namespace Musify.Infrastructure.Persistence
|
||||
{
|
||||
public static IServiceCollection AddDatabase(this IServiceCollection services, IConfiguration configuration)
|
||||
public static class DatabaseDependencyInjection
|
||||
{
|
||||
services.AddValidatedOptions<DatabaseConfiguration>(configuration);
|
||||
public static IServiceCollection AddDatabase(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.AddValidatedOptions<DatabaseConfiguration>(configuration);
|
||||
|
||||
services.AddDbContext<Database>();
|
||||
services.AddDbContext<Database>();
|
||||
|
||||
services.AddScoped<IDatabase>(serviceProvider => serviceProvider.GetRequiredService<Database>());
|
||||
services.AddScoped<IDatabase>(serviceProvider => serviceProvider.GetRequiredService<Database>());
|
||||
|
||||
return services;
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,24 +2,25 @@ using Microsoft.EntityFrameworkCore.Design;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Musify.Infrastructure.Configuration;
|
||||
|
||||
namespace Musify.Infrastructure.Persistence;
|
||||
|
||||
public class DatabaseDesignTimeFactory : IDesignTimeDbContextFactory<Database>
|
||||
namespace Musify.Infrastructure.Persistence
|
||||
{
|
||||
public Database CreateDbContext(string[] args)
|
||||
public class DatabaseDesignTimeFactory : IDesignTimeDbContextFactory<Database>
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("DesignSettings.json", optional: true)
|
||||
.AddUserSecrets<DatabaseDesignTimeFactory>()
|
||||
.AddEnvironmentVariables()
|
||||
.Build();
|
||||
public Database CreateDbContext(string[] args)
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("DesignSettings.json", optional: true)
|
||||
.AddUserSecrets<DatabaseDesignTimeFactory>()
|
||||
.AddEnvironmentVariables()
|
||||
.Build();
|
||||
|
||||
var databaseConfiguration = configuration
|
||||
.GetRequiredSection(DatabaseConfiguration.SectionName)
|
||||
.Get<DatabaseConfiguration>()
|
||||
?? throw new InvalidOperationException($"{DatabaseConfiguration.SectionName} configuration section not found.");
|
||||
var databaseConfiguration = configuration
|
||||
.GetRequiredSection(DatabaseConfiguration.SectionName)
|
||||
.Get<DatabaseConfiguration>()
|
||||
?? throw new InvalidOperationException($"{DatabaseConfiguration.SectionName} configuration section not found.");
|
||||
|
||||
return new Database(databaseConfiguration);
|
||||
return new Database(databaseConfiguration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,152 +3,153 @@ using Musify.Domain.Entities;
|
||||
using Musify.Domain.ValueObjects;
|
||||
using Musify.Infrastructure.MassTransit.Sagas;
|
||||
|
||||
namespace Musify.Infrastructure.Persistence;
|
||||
|
||||
/// <summary>
|
||||
/// Entity model shared by <see cref="Database"/> and the in-memory test database, so both always agree.
|
||||
/// </summary>
|
||||
public static class ModelConfiguration
|
||||
namespace Musify.Infrastructure.Persistence
|
||||
{
|
||||
public static void Apply(ModelBuilder modelBuilder)
|
||||
/// <summary>
|
||||
/// Entity model shared by <see cref="Database"/> and the in-memory test database, so both always agree.
|
||||
/// </summary>
|
||||
public static class ModelConfiguration
|
||||
{
|
||||
var trackProcessing = modelBuilder.Entity<TrackProcessingState>();
|
||||
trackProcessing.HasKey(state => state.CorrelationId);
|
||||
trackProcessing.Property(state => state.CorrelationId).ValueGeneratedNever();
|
||||
trackProcessing.Property(state => state.CurrentState).HasMaxLength(64);
|
||||
public static void Apply(ModelBuilder modelBuilder)
|
||||
{
|
||||
var trackProcessing = modelBuilder.Entity<TrackProcessingState>();
|
||||
trackProcessing.HasKey(state => state.CorrelationId);
|
||||
trackProcessing.Property(state => state.CorrelationId).ValueGeneratedNever();
|
||||
trackProcessing.Property(state => state.CurrentState).HasMaxLength(64);
|
||||
|
||||
modelBuilder.Entity<Track>()
|
||||
.OwnsOne(track => track.Pictures, pictures =>
|
||||
{
|
||||
pictures.Property(p => p.OriginalName).HasColumnName("OriginalPictureName").HasMaxLength(64);
|
||||
pictures.Property(p => p.SmallName).HasColumnName("SmallPictureName").HasMaxLength(64);
|
||||
pictures.Property(p => p.MediumName).HasColumnName("MediumPictureName").HasMaxLength(64);
|
||||
pictures.Property(p => p.LargeName).HasColumnName("LargePictureName").HasMaxLength(64);
|
||||
pictures.Property(p => p.ProcessingStatus).HasColumnName("PicturesProcessingStatus");
|
||||
});
|
||||
modelBuilder.Entity<Track>().Navigation(track => track.Pictures).IsRequired();
|
||||
modelBuilder.Entity<Track>()
|
||||
.OwnsOne(track => track.Pictures, pictures =>
|
||||
{
|
||||
pictures.Property(p => p.OriginalName).HasColumnName("OriginalPictureName").HasMaxLength(64);
|
||||
pictures.Property(p => p.SmallName).HasColumnName("SmallPictureName").HasMaxLength(64);
|
||||
pictures.Property(p => p.MediumName).HasColumnName("MediumPictureName").HasMaxLength(64);
|
||||
pictures.Property(p => p.LargeName).HasColumnName("LargePictureName").HasMaxLength(64);
|
||||
pictures.Property(p => p.ProcessingStatus).HasColumnName("PicturesProcessingStatus");
|
||||
});
|
||||
modelBuilder.Entity<Track>().Navigation(track => track.Pictures).IsRequired();
|
||||
|
||||
modelBuilder.Entity<Track>()
|
||||
.OwnsOne(track => track.Audio, audio =>
|
||||
{
|
||||
audio.Property(a => a.OriginalName).HasColumnName("OriginalAudioName").HasMaxLength(64);
|
||||
audio.Property(a => a.FolderName).HasColumnName("AudioFolderName").HasMaxLength(64);
|
||||
audio.Property(a => a.TranscodeStatus).HasColumnName("AudioTranscodeProcessingStatus");
|
||||
});
|
||||
modelBuilder.Entity<Track>().Navigation(track => track.Audio).IsRequired();
|
||||
modelBuilder.Entity<Track>()
|
||||
.OwnsOne(track => track.Audio, audio =>
|
||||
{
|
||||
audio.Property(a => a.OriginalName).HasColumnName("OriginalAudioName").HasMaxLength(64);
|
||||
audio.Property(a => a.FolderName).HasColumnName("AudioFolderName").HasMaxLength(64);
|
||||
audio.Property(a => a.TranscodeStatus).HasColumnName("AudioTranscodeProcessingStatus");
|
||||
});
|
||||
modelBuilder.Entity<Track>().Navigation(track => track.Audio).IsRequired();
|
||||
|
||||
modelBuilder.Entity<Track>()
|
||||
.HasOne(track => track.Owner)
|
||||
.WithMany()
|
||||
.HasForeignKey(track => track.OwnerUserId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
modelBuilder.Entity<Track>()
|
||||
.HasOne(track => track.Owner)
|
||||
.WithMany()
|
||||
.HasForeignKey(track => track.OwnerUserId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
modelBuilder.Entity<PlayList>()
|
||||
.Property(playList => playList.Visibility)
|
||||
.HasDefaultValue(PlayListVisibility.Private);
|
||||
modelBuilder.Entity<PlayList>()
|
||||
.Property(playList => playList.Visibility)
|
||||
.HasDefaultValue(PlayListVisibility.Private);
|
||||
|
||||
modelBuilder.Entity<PlayList>()
|
||||
.OwnsOne(playList => playList.Pictures, pictures =>
|
||||
{
|
||||
pictures.Property(p => p.OriginalName).HasColumnName("OriginalPictureName").HasMaxLength(64).IsRequired(false);
|
||||
pictures.Property(p => p.SmallName).HasColumnName("SmallPictureName").HasMaxLength(64).IsRequired(false);
|
||||
pictures.Property(p => p.MediumName).HasColumnName("MediumPictureName").HasMaxLength(64).IsRequired(false);
|
||||
pictures.Property(p => p.LargeName).HasColumnName("LargePictureName").HasMaxLength(64).IsRequired(false);
|
||||
});
|
||||
modelBuilder.Entity<PlayList>().Navigation(playList => playList.Pictures).IsRequired(false);
|
||||
modelBuilder.Entity<PlayList>()
|
||||
.OwnsOne(playList => playList.Pictures, pictures =>
|
||||
{
|
||||
pictures.Property(p => p.OriginalName).HasColumnName("OriginalPictureName").HasMaxLength(64).IsRequired(false);
|
||||
pictures.Property(p => p.SmallName).HasColumnName("SmallPictureName").HasMaxLength(64).IsRequired(false);
|
||||
pictures.Property(p => p.MediumName).HasColumnName("MediumPictureName").HasMaxLength(64).IsRequired(false);
|
||||
pictures.Property(p => p.LargeName).HasColumnName("LargePictureName").HasMaxLength(64).IsRequired(false);
|
||||
});
|
||||
modelBuilder.Entity<PlayList>().Navigation(playList => playList.Pictures).IsRequired(false);
|
||||
|
||||
modelBuilder.Entity<Album>()
|
||||
.OwnsOne(album => album.Pictures, pictures =>
|
||||
{
|
||||
pictures.Property(p => p.OriginalName).HasColumnName("OriginalPictureName").HasMaxLength(64);
|
||||
pictures.Property(p => p.SmallName).HasColumnName("SmallPictureName").HasMaxLength(64).IsRequired(false);
|
||||
pictures.Property(p => p.MediumName).HasColumnName("MediumPictureName").HasMaxLength(64).IsRequired(false);
|
||||
pictures.Property(p => p.LargeName).HasColumnName("LargePictureName").HasMaxLength(64).IsRequired(false);
|
||||
});
|
||||
modelBuilder.Entity<Album>().Navigation(album => album.Pictures).IsRequired(false);
|
||||
modelBuilder.Entity<Album>()
|
||||
.OwnsOne(album => album.Pictures, pictures =>
|
||||
{
|
||||
pictures.Property(p => p.OriginalName).HasColumnName("OriginalPictureName").HasMaxLength(64);
|
||||
pictures.Property(p => p.SmallName).HasColumnName("SmallPictureName").HasMaxLength(64).IsRequired(false);
|
||||
pictures.Property(p => p.MediumName).HasColumnName("MediumPictureName").HasMaxLength(64).IsRequired(false);
|
||||
pictures.Property(p => p.LargeName).HasColumnName("LargePictureName").HasMaxLength(64).IsRequired(false);
|
||||
});
|
||||
modelBuilder.Entity<Album>().Navigation(album => album.Pictures).IsRequired(false);
|
||||
|
||||
modelBuilder.Entity<Album>()
|
||||
.HasOne(album => album.Owner)
|
||||
.WithMany()
|
||||
.HasForeignKey(album => album.OwnerUserId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
modelBuilder.Entity<Album>()
|
||||
.HasOne(album => album.Owner)
|
||||
.WithMany()
|
||||
.HasForeignKey(album => album.OwnerUserId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
modelBuilder.Entity<AlbumHasTrack>()
|
||||
.HasOne(albumTrack => albumTrack.Album)
|
||||
.WithMany(album => album.AlbumTracks)
|
||||
.HasForeignKey(albumTrack => albumTrack.AlbumId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
modelBuilder.Entity<AlbumHasTrack>()
|
||||
.HasOne(albumTrack => albumTrack.Album)
|
||||
.WithMany(album => album.AlbumTracks)
|
||||
.HasForeignKey(albumTrack => albumTrack.AlbumId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
modelBuilder.Entity<AlbumHasTrack>()
|
||||
.HasOne(albumTrack => albumTrack.Track)
|
||||
.WithMany(track => track.AlbumTracks)
|
||||
.HasForeignKey(albumTrack => albumTrack.TrackId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
modelBuilder.Entity<AlbumHasTrack>()
|
||||
.HasOne(albumTrack => albumTrack.Track)
|
||||
.WithMany(track => track.AlbumTracks)
|
||||
.HasForeignKey(albumTrack => albumTrack.TrackId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
modelBuilder.Entity<AlbumHasTrack>()
|
||||
.HasIndex(albumTrack => new { albumTrack.AlbumId, albumTrack.TrackId })
|
||||
.IsUnique();
|
||||
modelBuilder.Entity<AlbumHasTrack>()
|
||||
.HasIndex(albumTrack => new { albumTrack.AlbumId, albumTrack.TrackId })
|
||||
.IsUnique();
|
||||
|
||||
modelBuilder.Entity<PlayListHasTrack>()
|
||||
.HasIndex(playListTrack => new { playListTrack.PlayListId, playListTrack.TrackId })
|
||||
.IsUnique();
|
||||
modelBuilder.Entity<PlayListHasTrack>()
|
||||
.HasIndex(playListTrack => new { playListTrack.PlayListId, playListTrack.TrackId })
|
||||
.IsUnique();
|
||||
|
||||
modelBuilder.Entity<Mix>()
|
||||
.HasIndex(mix => new { mix.UserId, mix.Position });
|
||||
modelBuilder.Entity<Mix>()
|
||||
.HasIndex(mix => new { mix.UserId, mix.Position });
|
||||
|
||||
modelBuilder.Entity<MixItem>()
|
||||
.HasOne(item => item.Mix)
|
||||
.WithMany(mix => mix.Items)
|
||||
.HasForeignKey(item => item.MixId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
modelBuilder.Entity<MixItem>()
|
||||
.HasOne(item => item.Mix)
|
||||
.WithMany(mix => mix.Items)
|
||||
.HasForeignKey(item => item.MixId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
modelBuilder.Entity<MixItem>()
|
||||
.HasOne(item => item.Track)
|
||||
.WithMany()
|
||||
.HasForeignKey(item => item.TrackId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
modelBuilder.Entity<MixItem>()
|
||||
.HasOne(item => item.Track)
|
||||
.WithMany()
|
||||
.HasForeignKey(item => item.TrackId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
modelBuilder.Entity<MixItem>()
|
||||
.HasIndex(item => new { item.MixId, item.Position });
|
||||
modelBuilder.Entity<MixItem>()
|
||||
.HasIndex(item => new { item.MixId, item.Position });
|
||||
|
||||
modelBuilder.Entity<TrackLike>()
|
||||
.HasIndex(like => new { like.UserId, like.TrackId })
|
||||
.IsUnique();
|
||||
modelBuilder.Entity<TrackLike>()
|
||||
.HasIndex(like => new { like.UserId, like.TrackId })
|
||||
.IsUnique();
|
||||
|
||||
modelBuilder.Entity<TrackTag>()
|
||||
.HasOne(trackTag => trackTag.Track)
|
||||
.WithMany(track => track.Tags)
|
||||
.HasForeignKey(trackTag => trackTag.TrackId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
modelBuilder.Entity<TrackTag>()
|
||||
.HasOne(trackTag => trackTag.Track)
|
||||
.WithMany(track => track.Tags)
|
||||
.HasForeignKey(trackTag => trackTag.TrackId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
modelBuilder.Entity<TrackTag>()
|
||||
.HasIndex(trackTag => new { trackTag.TrackId, trackTag.Tag })
|
||||
.IsUnique();
|
||||
modelBuilder.Entity<TrackTag>()
|
||||
.HasIndex(trackTag => new { trackTag.TrackId, trackTag.Tag })
|
||||
.IsUnique();
|
||||
|
||||
modelBuilder.Entity<UserFollow>()
|
||||
.HasOne(follow => follow.Follower)
|
||||
.WithMany()
|
||||
.HasForeignKey(follow => follow.FollowerId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
modelBuilder.Entity<UserFollow>()
|
||||
.HasOne(follow => follow.Follower)
|
||||
.WithMany()
|
||||
.HasForeignKey(follow => follow.FollowerId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
modelBuilder.Entity<UserFollow>()
|
||||
.HasOne(follow => follow.Followed)
|
||||
.WithMany()
|
||||
.HasForeignKey(follow => follow.FollowedId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
modelBuilder.Entity<UserFollow>()
|
||||
.HasOne(follow => follow.Followed)
|
||||
.WithMany()
|
||||
.HasForeignKey(follow => follow.FollowedId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
modelBuilder.Entity<UserFollow>()
|
||||
.HasIndex(follow => new { follow.FollowerId, follow.FollowedId })
|
||||
.IsUnique();
|
||||
modelBuilder.Entity<UserFollow>()
|
||||
.HasIndex(follow => new { follow.FollowerId, follow.FollowedId })
|
||||
.IsUnique();
|
||||
|
||||
var playListProcessing = modelBuilder.Entity<PlayListProcessingState>();
|
||||
playListProcessing.HasKey(state => state.CorrelationId);
|
||||
playListProcessing.Property(state => state.CorrelationId).ValueGeneratedNever();
|
||||
playListProcessing.Property(state => state.CurrentState).HasMaxLength(64);
|
||||
var playListProcessing = modelBuilder.Entity<PlayListProcessingState>();
|
||||
playListProcessing.HasKey(state => state.CorrelationId);
|
||||
playListProcessing.Property(state => state.CorrelationId).ValueGeneratedNever();
|
||||
playListProcessing.Property(state => state.CurrentState).HasMaxLength(64);
|
||||
|
||||
var albumProcessing = modelBuilder.Entity<AlbumProcessingState>();
|
||||
albumProcessing.HasKey(state => state.CorrelationId);
|
||||
albumProcessing.Property(state => state.CorrelationId).ValueGeneratedNever();
|
||||
albumProcessing.Property(state => state.CurrentState).HasMaxLength(64);
|
||||
var albumProcessing = modelBuilder.Entity<AlbumProcessingState>();
|
||||
albumProcessing.HasKey(state => state.CorrelationId);
|
||||
albumProcessing.Property(state => state.CorrelationId).ValueGeneratedNever();
|
||||
albumProcessing.Property(state => state.CurrentState).HasMaxLength(64);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user