using Microsoft.EntityFrameworkCore; using Socialize.Api.Modules.ContentItems.Data; using Socialize.Api.Modules.Workspaces.Data; namespace Socialize.Api.Modules.Assets.Data; internal static class AssetModelConfiguration { public static ModelBuilder ConfigureAssetsModule(this ModelBuilder modelBuilder) { modelBuilder.Entity(asset => { asset.ToTable("Assets"); asset.HasKey(x => x.Id); asset.Property(x => x.AssetType).HasMaxLength(64).IsRequired(); asset.Property(x => x.SourceType).HasMaxLength(64).IsRequired(); asset.Property(x => x.DisplayName).HasMaxLength(256).IsRequired(); asset.Property(x => x.GoogleDriveFileId).HasMaxLength(256); asset.Property(x => x.GoogleDriveLink).HasMaxLength(2048); asset.Property(x => x.PreviewUrl).HasMaxLength(2048); asset.Property(x => x.CreatedAt) .ValueGeneratedOnAdd() .HasDefaultValueSql("CURRENT_TIMESTAMP"); asset.HasIndex(x => x.WorkspaceId); asset.HasIndex(x => x.ContentItemId); asset.HasOne() .WithMany() .HasForeignKey(x => x.WorkspaceId) .OnDelete(DeleteBehavior.Restrict); asset.HasOne() .WithMany() .HasForeignKey(x => x.ContentItemId) .OnDelete(DeleteBehavior.Restrict); }); modelBuilder.Entity(revision => { revision.ToTable("AssetRevisions"); revision.HasKey(x => x.Id); revision.Property(x => x.SourceReference).HasMaxLength(2048).IsRequired(); revision.Property(x => x.PreviewUrl).HasMaxLength(2048); revision.Property(x => x.Notes).HasMaxLength(1024); revision.Property(x => x.CreatedAt) .ValueGeneratedOnAdd() .HasDefaultValueSql("CURRENT_TIMESTAMP"); revision.HasIndex(x => x.AssetId); revision.HasIndex(x => new { x.AssetId, x.RevisionNumber }).IsUnique(); revision.HasOne() .WithMany() .HasForeignKey(x => x.AssetId) .OnDelete(DeleteBehavior.Cascade); }); return modelBuilder; } }